From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3B8172F7CE8 for ; Fri, 4 Jul 2025 12:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633939; cv=none; b=bfM/NXvrnpOnk29FtwHnbSs5yLsCoPp4lLPeYNYKdXMHLipABU16otMLC4DEq0leUrSIsA3weO0QjHBASy5wq/R6kfrpZ7/iG13x9dDZmqUHUpZNnqZcHsJ/+jBO3QXonK9PuTdUjE/MjkAJ50/5oKiHoAyEgfKXQs4DybWbvb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633939; c=relaxed/simple; bh=QMWIrIsZsHd4/QJq/tOFfSWRWVwuYowwy6j47eKWiWQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LZ+yBaowfwNiRm3JrKN8BCuwW2laOEQYxgAgikv5ugRoaXo9CKtHB0F2tpMxBYEquGwV7RysmupQqa0YHyK4yjeGRpYm5D2Yz++sPSyV9cn+xuTmUlso9gfn9cWKw/lQpYOULWVtknYaEF+MLIJJhVmo1jB8Xlg6fGr0ox6tZcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=X7eYKpx/; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="X7eYKpx/" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-3a52874d593so778385f8f.0 for ; Fri, 04 Jul 2025 05:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633935; x=1752238735; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Gz0K9x6WVUUEMtJl7r+FzEpq3GnlzRz5RtFA+qGgsHk=; b=X7eYKpx/RsZRj+yaOBk4XPYZHt+IeT2mLsugnUOMR0h2JUzDablP4xOuh7H/PnLaEn Ah3saTjIIpx8/hF0qAfKu7lHnQfdue6ECx7p/Sf+qWFY/M3Cr1JGTpxTd3qAT2qfBTMm ZJ5L9mblVIBMgLon47yUYtN7wLWfOfG6EEsigOF/V68GwM9JBpS58JQo3jTcExoNi3kW fuurGWMSeJSjzfA3h7L8XJzjIvbR06NkgwUjfU9J16AXflvlEL3fF1LdXqZqOo1CeVhy Dr0E7iai8bVVLjKi1knP8xh6sR6xqmofgfZXZkbsoEpiukaVcHQCxICo1D8475byX3x7 Nalw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633935; x=1752238735; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gz0K9x6WVUUEMtJl7r+FzEpq3GnlzRz5RtFA+qGgsHk=; b=KhjmkUHMJLR4Lf2xmfMrn+n2lbgtcCSChq0aQMvDV3L2+rMp+QnaI+/9mti7uUJAww 6V7uc8816RAgekPe8+QVk/OQtdvZt0KK1jT1sXBmjt0k7IybPd4U/oE8jg8AdcnWJQTF FjzG89opkEwNSHrbr8bBZB9ModBXOLckD7MIB/UgnnIocgj6UBMZNqvEEwe0VtIt0h7O EeHjNFdO2GqPhK4Y+3o07IbaBRVh6tD25bY7ySOTaixN1UP5PAt70yf1YI5yTyiPlC22 +1vMyWGA5F2Gm0lVeeAUAfYlNd2bbiOSxpuLoHQ0zAB7/HQtV9VoF4nL3OOJxJwLGAs4 upkg== X-Forwarded-Encrypted: i=1; AJvYcCU+S+u0qRI80yQ7hE67SMDVXO8pHA66N8aCWgsRo6Au8DnCqRuj27y6G18oHZATYBxnMrAUNUJGG7QGPc4=@vger.kernel.org X-Gm-Message-State: AOJu0YwV6tkj56Gi76zAEz8hflQthNLWbN6eaaE8o9TN9eCAFmc5GW/3 MEkiL6Szc5Hy3gDxASEj+pyjOpU8vXGuZ8etuAOZqT2KtdHnbORf1VR9OqEyLcxqIgM= X-Gm-Gg: ASbGncuAfStcAKDAgQIy4qO+2f/41E/haFV50LKMBdqmyWeAlHUoxrGg6IDQr7voZ+5 NQ9qb4SOz8xTvA6Eqr+5CdCIfIp9GT5+XbDlLkzS5WajLleNortCqddC5+lqnnTI6J6Hwhhhq/y +/2mpV7VcvHNX2gOFzMVqLwGnNJUl93t2u/OJbR/7wWeYo1SnG00hp8NOg1Fm+u6IODoEDGexEa UK25rsr8mKy4kkZc/n7VFf4aphZYEaqTZpANegHtpVEa36i5CEphZI5V5ZwpUlaBCtStDLskioX TGbNU1eZjrUgGf3gZCI2YDGLdhZ+TjZjPBTcjl4pdJfnlbkRTXNSdeY= X-Google-Smtp-Source: AGHT+IHg1n/qrH2J6dTNw93F2kEzgdI64kMJD2ZmQFJ01deEa0sk7Src48VwOQ06MLVAifI/HZiaQA== X-Received: by 2002:a05:6000:480b:b0:3a8:38b3:6e32 with SMTP id ffacd0b85a97d-3b4964f4e41mr1862900f8f.8.1751633935292; Fri, 04 Jul 2025 05:58:55 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:58:54 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:48 +0200 Subject: [PATCH v4 01/10] gpio: sysfs: use gpiod_is_equal() to compare GPIO descriptors Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-1-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=937; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ikmfqSg91RkpdEfKPtgwiZRnKuHEt1zFC0lBiF3REpM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9AKFdJP2TwJNtEzy85VwJjHxi4N/QvM4zY8h tjJ9c9Fdz+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCgAKCRARpy6gFHHX cmq4EACwoTIkVXg0R4gogmKgBodhH6XWnN9aB44SDWTZ6mdOuG/yDn4+yIKiKVmtMYvm0mHsZas C0legWWSJm6/iBdXBuIzyynXfRUUjFz5tx3YJVdZQyWWFROQTzHs0U0uKTMNcafNtn3qTMSsAYt xhowSzgde4udxKb8/3laymvak5DU+eGGmwPtLhgASo9CvHyOCJ2+zx6wYKjFQ3BRoyWp00Wn4JH TS6QE3NnxV8Q8PcF7hQBVmpinOnlyFr4DVp/Z0riv2VWP0Xoh7GMZQ8Oh58To0fp7N+MDt3J6PE wQAh5W/WEgVcElrbj/l+wh3Hv7m2pPQvSP9RmkpG2/Bb1dXN16dkVaNDqNQYnoC0NRTXb5P9zu8 TuE27L0E2gDXwRTIzYXyaZw11enzahGT72ikLRegkeu4COzvNChOG4aLoHoYR106siwIqg1kP7F EsUu2RoxauXwNd6au/QZ9xohrtM+AYAaWLTm2VZ6KMtrlS739ryz06g6ghilWi1pF5c0KHlYmAu HugnS5zf5A4ZGDH5pXs6/ac5zUo11zTsrwunSfUAgP6MUSplWusuaIgAoC7L5GVWWYcSHve6611 eSdITxRuYQd6HIeRRdiN9F5Ftai21XaaE8G1uAE/vAtRDVsjqOfGEzuPiyFsCjm9jM4n18KfHBy Tu6h7KAlD/umzBA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We have a dedicated comparator for GPIO descriptors that performs additional checks and hides the implementation detail of whether the same GPIO can be associated with two separate struct gpio_desc objects. Use it in sysfs code Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index c4c21e25c682b939e4a0517393308343feb6585a..c4e85f2827697d0239ff6296caf= 49d243cf10fe8 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -657,7 +657,7 @@ static int match_export(struct device *dev, const void = *desc) { struct gpiod_data *data =3D dev_get_drvdata(dev); =20 - return data->desc =3D=3D desc; + return gpiod_is_equal(data->desc, desc); } =20 /** --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42A1E2F7CFC for ; Fri, 4 Jul 2025 12:58:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633940; cv=none; b=mO4RkWjSAK0FCpffNjyizn/8nnx4rrczu34M48PwEd9IOoCOuR0Qbv7xJfwUtf9x4/0mOPMKveLHYkmG5xZ3g9TB34XdKtkgxav0iUXvnK67C3+Hs986mnYNpDcgmROEb1ga0LFQQ6Y8HaCxvx9yw0Nvt+ZTX96zGTJYv8ok0h8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633940; c=relaxed/simple; bh=HhG83jFmoV5xdCHkj21aD/0tubc0+blTrTs2HK40gu8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q0CA9l7ooJB5+IXGUgtyJs7s85RavIZMyHxEbIQFyIcT++bP7UJnEz/WadVrGPvir5tJzvu1R2o9nulMAyqPGqYs/iVp89nZHHB2IM1bdVq5giTegp51tatthrTBR21LYAXvBDWGwqdtBhMIAYeVVPm0XpikbH3PBlqcrdNWn7c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=yZMcLLVl; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="yZMcLLVl" Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-451d6ade159so7987485e9.1 for ; Fri, 04 Jul 2025 05:58:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633936; x=1752238736; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5bPbuY7LrWyKcfoiO0z5WW0ENh7MgP8sldaKCSQKpoc=; b=yZMcLLVlo+eZGUAHn70X4OHKM2pqMKztGXtJ0zxaquuojx44hu/xbSmkjZk6V45uUC wzq9OFFDHAKrRx0+nOG7fuL6HP/1wXnsaCoJBOQpyRGJnUuzpcx8HWGzt30GUKUQroJN +4hsQmNoiV6X0mnV8EiFG1nuKkaP+afCQkHoVW+bPzoVeyYllk/InRaZv/eFJIcXvZJ4 IBkuFy0tU2PK449+G1o+6GGResKv5cOA3FXJyeuSfpilczX0vs4RMQwq8BTMq1pV+zI2 tf0PEOG1UrjGx5Wr9rQCCjvebrNgoTsOosuhOegnPOBspnp/x7bTF2vgf2HWW11CqqxM uNaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633936; x=1752238736; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5bPbuY7LrWyKcfoiO0z5WW0ENh7MgP8sldaKCSQKpoc=; b=vTcp9rpj2QBDfsa1vnwVr6JLFmrEaaxXRbmlBEYFs/q8ofkRqvQYA7QhNAUIbfogBk zE9xXv0IYj8pUB3TOKNjhyAzgMCrVaXbLsHve4LUxbw+lmtna4YrhFO+TeNfGDx+xHVq YnLs6mckpYxQvZ3PLwRLZZP4aAKJnuM8DQ20KFaPMIO5cseaMOluWD8sFj1PJSZr4Z7k Jyxy37Iv8bzCxnJzdemJAXXclu3Fe8P7ID/QEGRHeX1F0wtsRgIVtgxhFQ/rmry0gn50 u+gjkTpj1CT4KAOjRogpIY2qVk0o9ymVhmy7HxO7TkG1u3RLOzATQ/NWWFRw/+bqFpXR ioCg== X-Forwarded-Encrypted: i=1; AJvYcCWxQVE2NxCbKjXTp8lhQHU7WLKvbcNdXnJ3sxlySTOrM5/jwZ2PcltZRxQkMUrHxfN+/aT03M17bVfhEYE=@vger.kernel.org X-Gm-Message-State: AOJu0Ywr7m/3mkbHg7bmSyMHxTE6s4cnSr3OIGzyxQVFuRiARXnD6jQh umsr7cbzBVt105c1dr1pE3MO9x2wR/2rRUiNAqp+LperIrrEE9eR0wJ4TYr5EIFdnmI= X-Gm-Gg: ASbGncsML1a7RgZsUYmrNsMUVhPVKAMgnkaelvDGB/RQ2dV4Agukc9udiK9qlenHot3 KvF4egwyx7ix/oxcYxyZVWOIxwcQcl33nuHqeLEt+sj5WNjmGdRWUdtQwHXGaII2nbVGEoLb3DA MOQsWDwoaaNrZdQd8ZYONnYqEAfSIiRG/ST90OI/KvKGvHlbx9IdqG6/fpx/F6keTtDJUu4VMFG YobeWNLn5nMYBmLnz457JTEwh9b7VILnJ70AKK9uN2/QBLGUTW6CZOfGw6ZiqZ2igJXiI5jlwih Kme3vctskfZMFsUtp9zf/wgIA+HQhLZ7xKkwXVnzzZspdjwWIPOHENg= X-Google-Smtp-Source: AGHT+IGCnX4hh4gtPYCGUQD4xyeDmsCfqHwBbBm0KTACazkJNfJ26QejQ49ZXkNB6N0XFeJwri9tew== X-Received: by 2002:a05:600c:1c19:b0:43c:f8fc:f697 with SMTP id 5b1f17b1804b1-454b4e74ba9mr22014455e9.9.1751633936521; Fri, 04 Jul 2025 05:58:56 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:58:56 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:49 +0200 Subject: [PATCH v4 02/10] gpio: sysfs: add a parallel class device for each GPIO chip using device IDs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-2-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9925; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=FnQGtT4MFyQtsq5dSlUq/XlWDskcX3/x8jCYFrX9rOI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9AKj+lsEZ0SiZLHmFSXOrqLLXs/G4iRw8ZyX eLiyGhHmLuJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCgAKCRARpy6gFHHX cpBZEACRT0QpOUMn/TDhc2qh35/q2HXwJpXgLszxkfrMX7uFdyBZnqKC5l7NKWIvofvdpyZDA6s QdMenn8iXUg2u3PGun6XFu1HqnP+BCPSQ2YhWjhSpB9SvtkpESpvb2IWFK2W2Q+PvqWoMmfzD89 qeiVZLIBUHQShKWUE2TLFU7fgLD4Ey/7H9Imdw9lr5U/81J2iYEi7HI+aSbjVJBziGvhMNPw5En 6oSow2vbBAXZyCgIO4FtaSyIe4O2pKi6moEK42sy/c1/nhnE8vrLmsuPekYWT41t+IMbwRA2MMC yF14B/H7Gozj5o2o5j3IbrzryHtcu122UI13Jz7SS4CjTeFqi1tcH7xndLEg0pJ30NwlIYuJywM mtgAED0RxzlANSSTsVBumhJTCugFQOfnSiJ6B1AYCxKNuvcjIgtO8yU6f8CIG91Tjjz0M31waKX Plpw5265MWMvNLdvphumdCxUQwPwY/t06ESlLNEaGUO60nKP9Dk0LzGoblkw5NYU96zWR27/3TB pfUebOEARM+r9mzRbfzeyeBQDRRt5CRDF2tdLzO+zFGHLptC1vKvHA5/eCsa62I1utMzBxmKFEi Ub6sz5pb4113pxEgusQNjaWvv9QXZn0JRAihE5DHc5xE6ksdu34dOgrEp//bH3YqULwQUKQsSLH 00XyqR5+q9GN+lw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In order to enable moving away from the global GPIO numberspace-based exporting of lines over sysfs: add a parallel, per-chip entry under /sys/class/gpio/ for every registered GPIO chip, denoted by device ID in the file name and not its base GPIO number. Compared to the existing chip group: it does not contain the "base" attribute as the goal of this change is to not refer to GPIOs by their global number from user-space anymore. It also contains its own, per-chip export/unexport attribute pair which allow to export lines by their hardware offset within the chip. Caveat #1: the new device cannot be a link to (or be linked to by) the existing "gpiochip" entry as we cannot create links in /sys/class/xyz/. Caveat #2: the new entry cannot be named "gpiochipX" as it could conflict with devices whose base is statically defined to a low number. Let's go with "chipX" instead. While at it: the chip label is unique so update the untrue statement when extending the docs. Acked-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- Documentation/ABI/obsolete/sysfs-gpio | 7 +- drivers/gpio/gpiolib-sysfs.c | 192 +++++++++++++++++++++++++-----= ---- 2 files changed, 150 insertions(+), 49 deletions(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obso= lete/sysfs-gpio index 480316fee6d80fb7a0ed61706559838591ec0932..ff694708a3bef787afa42dedf94= faf209c44dbf0 100644 --- a/Documentation/ABI/obsolete/sysfs-gpio +++ b/Documentation/ABI/obsolete/sysfs-gpio @@ -25,8 +25,13 @@ Description: /active_low ... r/w as: 0, 1 /gpiochipN ... for each gpiochip; #N is its first GPIO /base ... (r/o) same as N - /label ... (r/o) descriptive, not necessarily unique + /label ... (r/o) descriptive chip name /ngpio ... (r/o) number of GPIOs; numbered N to N + (ngpio - 1) + /chipX ... for each gpiochip; #X is the gpio device ID + /export ... asks the kernel to export a GPIO at HW offset X to usersp= ace + /unexport ... to return a GPIO at HW offset X to the kernel + /label ... (r/o) descriptive chip name + /ngpio ... (r/o) number of GPIOs exposed by the chip =20 This ABI is obsoleted by Documentation/ABI/testing/gpio-cdev and will be removed after 2020. diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index c4e85f2827697d0239ff6296caf49d243cf10fe8..990db0405cc86c42bad61295dc8= 23f970199534e 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -45,6 +45,7 @@ struct gpiod_data { =20 struct gpiodev_data { struct gpio_device *gdev; + struct device *cdev_id; /* Class device by GPIO device ID */ struct device *cdev_base; /* Class device by GPIO base */ }; =20 @@ -399,6 +400,14 @@ static const struct attribute_group *gpio_groups[] =3D= { * /base ... matching gpio_chip.base (N) * /label ... matching gpio_chip.label * /ngpio ... matching gpio_chip.ngpio + * + * AND + * + * /sys/class/gpio/chipX/ + * /export ... export GPIO at given offset + * /unexport ... unexport GPIO at given offset + * /label ... matching gpio_chip.label + * /ngpio ... matching gpio_chip.ngpio */ =20 static ssize_t base_show(struct device *dev, struct device_attribute *attr, @@ -428,6 +437,111 @@ static ssize_t ngpio_show(struct device *dev, struct = device_attribute *attr, } static DEVICE_ATTR_RO(ngpio); =20 +static int export_gpio_desc(struct gpio_desc *desc) +{ + int offset, ret; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + offset =3D gpio_chip_hwgpio(desc); + if (!gpiochip_line_is_valid(guard.gc, offset)) { + pr_debug_ratelimited("%s: GPIO %d masked\n", __func__, + gpio_chip_hwgpio(desc)); + return -EINVAL; + } + + /* + * No extra locking here; FLAG_SYSFS just signifies that the + * request and export were done by on behalf of userspace, so + * they may be undone on its behalf too. + */ + + ret =3D gpiod_request_user(desc, "sysfs"); + if (ret) + return ret; + + ret =3D gpiod_set_transitory(desc, false); + if (ret) { + gpiod_free(desc); + return ret; + } + + ret =3D gpiod_export(desc, true); + if (ret < 0) { + gpiod_free(desc); + } else { + set_bit(FLAG_SYSFS, &desc->flags); + gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); + } + + return ret; +} + +static int unexport_gpio_desc(struct gpio_desc *desc) +{ + /* + * No extra locking here; FLAG_SYSFS just signifies that the + * request and export were done by on behalf of userspace, so + * they may be undone on its behalf too. + */ + if (!test_and_clear_bit(FLAG_SYSFS, &desc->flags)) + return -EINVAL; + + gpiod_unexport(desc); + gpiod_free(desc); + + return 0; +} + +static ssize_t do_chip_export_store(struct device *dev, + struct device_attribute *attr, + const char *buf, ssize_t size, + int (*handler)(struct gpio_desc *desc)) +{ + struct gpiodev_data *data =3D dev_get_drvdata(dev); + struct gpio_device *gdev =3D data->gdev; + struct gpio_desc *desc; + unsigned int gpio; + int ret; + + ret =3D kstrtouint(buf, 0, &gpio); + if (ret) + return ret; + + desc =3D gpio_device_get_desc(gdev, gpio); + if (IS_ERR(desc)) + return PTR_ERR(desc); + + ret =3D handler(desc); + if (ret) + return ret; + + return size; +} + +static ssize_t chip_export_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + return do_chip_export_store(dev, attr, buf, size, export_gpio_desc); +} + +static struct device_attribute dev_attr_export =3D __ATTR(export, 0200, NU= LL, + chip_export_store); + +static ssize_t chip_unexport_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + return do_chip_export_store(dev, attr, buf, size, unexport_gpio_desc); +} + +static struct device_attribute dev_attr_unexport =3D __ATTR(unexport, 0200, + NULL, + chip_unexport_store); + static struct attribute *gpiochip_attrs[] =3D { &dev_attr_base.attr, &dev_attr_label.attr, @@ -436,6 +550,15 @@ static struct attribute *gpiochip_attrs[] =3D { }; ATTRIBUTE_GROUPS(gpiochip); =20 +static struct attribute *gpiochip_ext_attrs[] =3D { + &dev_attr_label.attr, + &dev_attr_ngpio.attr, + &dev_attr_export.attr, + &dev_attr_unexport.attr, + NULL +}; +ATTRIBUTE_GROUPS(gpiochip_ext); + /* * /sys/class/gpio/export ... write-only * integer N ... number of GPIO to export (full access) @@ -447,7 +570,7 @@ static ssize_t export_store(const struct class *class, const char *buf, size_t len) { struct gpio_desc *desc; - int status, offset; + int status; long gpio; =20 status =3D kstrtol(buf, 0, &gpio); @@ -461,40 +584,7 @@ static ssize_t export_store(const struct class *class, return -EINVAL; } =20 - CLASS(gpio_chip_guard, guard)(desc); - if (!guard.gc) - return -ENODEV; - - offset =3D gpio_chip_hwgpio(desc); - if (!gpiochip_line_is_valid(guard.gc, offset)) { - pr_debug_ratelimited("%s: GPIO %ld masked\n", __func__, gpio); - return -EINVAL; - } - - /* No extra locking here; FLAG_SYSFS just signifies that the - * request and export were done by on behalf of userspace, so - * they may be undone on its behalf too. - */ - - status =3D gpiod_request_user(desc, "sysfs"); - if (status) - goto done; - - status =3D gpiod_set_transitory(desc, false); - if (status) { - gpiod_free(desc); - goto done; - } - - status =3D gpiod_export(desc, true); - if (status < 0) { - gpiod_free(desc); - } else { - set_bit(FLAG_SYSFS, &desc->flags); - gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_REQUESTED); - } - -done: + status =3D export_gpio_desc(desc); if (status) pr_debug("%s: status %d\n", __func__, status); return status ? : len; @@ -511,7 +601,7 @@ static ssize_t unexport_store(const struct class *class, =20 status =3D kstrtol(buf, 0, &gpio); if (status < 0) - goto done; + return status; =20 desc =3D gpio_to_desc(gpio); /* reject bogus commands (gpiod_unexport() ignores them) */ @@ -520,18 +610,7 @@ static ssize_t unexport_store(const struct class *clas= s, return -EINVAL; } =20 - status =3D -EINVAL; - - /* No extra locking here; FLAG_SYSFS just signifies that the - * request and export were done by on behalf of userspace, so - * they may be undone on its behalf too. - */ - if (test_and_clear_bit(FLAG_SYSFS, &desc->flags)) { - gpiod_unexport(desc); - gpiod_free(desc); - status =3D 0; - } -done: + status =3D unexport_gpio_desc(desc); if (status) pr_debug("%s: status %d\n", __func__, status); return status ? : len; @@ -561,6 +640,11 @@ static int match_gdev(struct device *dev, const void *= desc) static struct gpiodev_data * gdev_get_data(struct gpio_device *gdev) __must_hold(&sysfs_lock) { + /* + * Find the first device in GPIO class that matches. Whether that's + * the one indexed by GPIO base or device ID doesn't matter, it has + * the same address set as driver data. + */ struct device *cdev __free(put_device) =3D class_find_device(&gpio_class, NULL, gdev, match_gdev); @@ -787,6 +871,17 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) return err; } =20 + data->cdev_id =3D device_create_with_groups(&gpio_class, parent, + MKDEV(0, 0), data, + gpiochip_ext_groups, + "chip%d", gdev->id); + if (IS_ERR(data->cdev_id)) { + device_unregister(data->cdev_base); + err =3D PTR_ERR(data->cdev_id); + kfree(data); + return err; + } + return 0; } =20 @@ -802,6 +897,7 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) return; =20 device_unregister(data->cdev_base); + device_unregister(data->cdev_id); kfree(data); } =20 --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C68DB2F7D1B for ; Fri, 4 Jul 2025 12:58:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633941; cv=none; b=B2gizgLNsx5RpA4Gtwwu/T0ad4QUADhpIedFqUSoynd02fFGFoyLZEfidmmdehp1F/lL38OnckUdnw0kPGJbTshRr1WBRcKQ5yQChM4Q8J6/GQjovFD0e0z7WUFecSzf9wQHamufEK2dqhaiss0k5dNXjD1NRtuhT9N6L8+VN9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633941; c=relaxed/simple; bh=HdYrd5wAQlj2cg109qOltUEP+8Z89jrbFJR2AWTzVRo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DxzP2++8QWIRxboEBu6AgK7Tx3tAdMzwc1rOjLg3ZIR3EPvA6mBAWXnJz3QXGyklrF5hmTngQe1xASKNJHIH0shC2BE5PxyhwtAl3hmtafPB2Acdnfcbo3eNYpeiXAVk4AtiF7ZCdSe1PeRPuX04p9NgAj13re+OGGrbVOjvJY8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=SOuN+D3J; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="SOuN+D3J" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4530921461aso6628675e9.0 for ; Fri, 04 Jul 2025 05:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633938; x=1752238738; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nM06UOupnjpVIz2DIB+rEDMhBUDdLc/LT6TEZgEANCA=; b=SOuN+D3JniosxR3mRWjkGupPlz4HsiKpt6xeACXaleQ7S2RZ4QM2r1+pIY4Z5KYisD JT9JFCYnwoqQWehyKKD2NtNQA2SF3IpLQXHl5IVWcarvGU/iTX8+mLuijGbopfSBdbsH Mi6roMD+AOJc06roZPWNu9Hnq9pAOq4TXq542WWeAjbK9+yPlX/dj05CRhI0tMSWJBSR hCpi6Mf5kpttXOAmDkksrJzcSX/Lpx6Mbze843UeVPX8aMzq9oTFG+l63SmsIc0TSZ7a CRt4WpKqVtqYLqdu8cmCj/7ivtiBNkB8jJ8yjjG97X0TQ9Pn+9mZ7q6URpKC4X4Sx0E8 FupQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633938; x=1752238738; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nM06UOupnjpVIz2DIB+rEDMhBUDdLc/LT6TEZgEANCA=; b=qanQNRKdwLA7mom5FlkOHn7jaeMkwCKvb/b0tQ4VJI+CB2HKnScGdubDaO4by5Ijr1 6WJ9Z+TYSSOZfgLNwfiNFPN8T0MAzzKyJjRbZyFc5+aiaEri9zHKI0B/cUQv8NRxoOyG rDvb9DddfFjPahC1EiUe4StSxiODvFfppDPM/MppOBd5bD0MX5v9KMFWeHn8s8fEnwU7 qRepmm6czEDt4fppcG924cjUaid+HPMQsiXMyCmv+xsfQzGgkSfBydH+tHcL+DQIh8Kd ay6bG2juWSlrUIFqNf+Bn3k2g4Dh4TuVRHFI9PxbclP6gHY9LCx7DO6lr2LdsVQ3ENAF cLWQ== X-Forwarded-Encrypted: i=1; AJvYcCULO0kZoYobQgDJZhBued0ZlljrL82nqKgURDrWhntfDvijq9p8BkUIj5WLby7543EiZUnvfgqJaFVp7es=@vger.kernel.org X-Gm-Message-State: AOJu0YwH4CilWy0dGVebGmMtW1sePCMwoET8AWpWKz2V2NBPRigTKCZh b3p66bIYSH1wMS8QjrfwV8C6Fio/v+SP1oJyJO0oglVmEAY2HOU7p1xNhfrEBBUt264= X-Gm-Gg: ASbGncuVkdhGVEvev4nK7KMT6gHKGN2WFKComDtTGpXPaZVbvHGAcgEvUbS6/YF5s4J 9qjyeADELYGNFY0WGa7sRtUtTfALv7Q3juzZPWLpZP+KeMAczG641z6e+j6yQRUy7YnRQJu4pc4 3EMQ5TjVmJwLzY5LjTSu+U6C0vKP173wOJtYcgt1/Ys1q/Nz3MZTv1hMXRsidZkVg/1/kZp9wv4 oOpkyjrugVrwwhqa9ZjxEu9Xd/7wkAu0vICPF7bIdQxEaKSrBQMtZcVdGDCcK3ZovEiCnr7PlvV QhYSHYvM2u03kjkh6TcA4xEIjfIQDOdRzJ6GHCO7/h4t/yTw0Pmlj8E= X-Google-Smtp-Source: AGHT+IFYyioA9K5vuPmOKby5kRjktdDyy2pH75rERivuNYa351BCsQwioCaEkDqrzIKmj35uSH1aQw== X-Received: by 2002:a05:600c:6295:b0:453:b44:eb71 with SMTP id 5b1f17b1804b1-454b3102952mr24742655e9.19.1751633938011; Fri, 04 Jul 2025 05:58:58 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:58:56 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:50 +0200 Subject: [PATCH v4 03/10] gpio: sysfs: only get the dirent reference for the value attr once Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-3-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2623; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=JxMuWlaSBErn8oTKxqgNq9xj/0gFj3dqHDBwJKynqek=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9AKi+r0yxZvERHr2Uf1I7PnjZZMDbcdwj/kF q/oUrY/17CJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCgAKCRARpy6gFHHX cvL/D/9YbeIZ9MN+Z3MqjVnSkqEqLrA/CrhslXGF3Zm40e5pb96lwzI1SOU3Vjjij3zds0xg1MC IXnxbVHO5auLHY1MMfng1IbfTWwdJeNHfKPOvyh63sRxtfvmeYUbTAqH7fmiM5bwIDt7K33BgOC dBCUIXrR35eocfxD5IVIiXLcL231jc5PHit3nziuvqdq0efGzBk0AvN9MULBshgFYqnwkldtPmR rp9iQ+B46hWgxp0TshkwfA8NJyu87kvbeXgrJPCtw+ee0imoc6A7jZBllZImTT/e44MN5XT9vcY 2U/9f0mZPyFgDsDVDoQ5WkT8uHZkhwJMPwm0NzcDy7MMxUtqEx/psFp11Yvz0OG5LXl85XIFSF3 bKJJe+2rbIDDgxuBwPqUS8yQi7ZAWR+lzUfCuCHAMTrU8E4ArRCI+VyEnq9ZVuPVVPj1b47XN0p Y6X4qtI98mYoBWk2ueuIV0aEuidyeXWgACQl4OqZD1sFHfEZ54uCKfRtxopaDAuMLQr11TxYdRV IQZjWDBhj1b9h8cL1A6MYjBWEArs6wSjQciGzKFCjdT9bdLY4gLStVHdW7d4JdncNTNXbexx53u WX+SBiXcwXkvSvfwmH1/QYmT//4hI2MUHbyunlhlWAubJJVaddTaB2+SIZgd2W+Eq9ADja90b3d 8t0zIhKMsEnlpGA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski There's no reason to retrieve the reference to the sysfs dirent every time we request an interrupt, we can as well only do it once when exporting the GPIO. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 990db0405cc86c42bad61295dc823f970199534e..39e9ca31f034e20abd08fb5e9b4= eecf24f127d5e 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -177,10 +177,6 @@ static int gpio_sysfs_request_irq(struct device *dev, = unsigned char flags) if (data->irq < 0) return -EIO; =20 - data->value_kn =3D sysfs_get_dirent(dev->kobj.sd, "value"); - if (!data->value_kn) - return -ENODEV; - irq_flags =3D IRQF_SHARED; if (flags & GPIO_IRQF_TRIGGER_FALLING) { irq_flags |=3D test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? @@ -203,7 +199,7 @@ static int gpio_sysfs_request_irq(struct device *dev, u= nsigned char flags) */ ret =3D gpiochip_lock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); if (ret < 0) - goto err_put_kn; + goto err_clr_bits; =20 ret =3D request_any_context_irq(data->irq, gpio_sysfs_irq, irq_flags, "gpiolib", data); @@ -216,10 +212,9 @@ static int gpio_sysfs_request_irq(struct device *dev, = unsigned char flags) =20 err_unlock: gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); -err_put_kn: +err_clr_bits: clear_bit(FLAG_EDGE_RISING, &desc->flags); clear_bit(FLAG_EDGE_FALLING, &desc->flags); - sysfs_put(data->value_kn); =20 return ret; } @@ -242,7 +237,6 @@ static void gpio_sysfs_free_irq(struct device *dev) gpiochip_unlock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); clear_bit(FLAG_EDGE_RISING, &desc->flags); clear_bit(FLAG_EDGE_FALLING, &desc->flags); - sysfs_put(data->value_kn); } =20 static const char *const trigger_names[] =3D { @@ -726,8 +720,16 @@ int gpiod_export(struct gpio_desc *desc, bool directio= n_may_change) goto err_free_data; } =20 + data->value_kn =3D sysfs_get_dirent(dev->kobj.sd, "value"); + if (!data->value_kn) { + status =3D -ENODEV; + goto err_unregister_device; + } + return 0; =20 +err_unregister_device: + device_unregister(dev); err_free_data: kfree(data); err_clear_bit: @@ -804,6 +806,7 @@ void gpiod_unexport(struct gpio_desc *desc) =20 data =3D dev_get_drvdata(dev); clear_bit(FLAG_EXPORT, &desc->flags); + sysfs_put(data->value_kn); device_unregister(dev); =20 /* --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C8A02F948A for ; Fri, 4 Jul 2025 12:59:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633942; cv=none; b=hK0JJIBH67cZx3OOdVJDrPqaIzyBAvnvu5CgUI5EOszxqull5D08wupHmLg5yzw6frk957wgm6FKM26WvxSUxITmzutfmfE5x44hBB8kvTsJ1ttXLxnU9GtI6bN7ohu7rTUcY4zGKeXxr2Xq3Xat1o5KU7GEgGmzo9m7FcLI38o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633942; c=relaxed/simple; bh=QvDRysI0zKBvfiq+uUhVzRccMt+3EXYSAt0+5f6/hQM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q7euXSOdosXpF8mFcJcbjjuONi/tvz8ke5eKn+z5xyFEcQAWzjVdrHto93cqlTD2LHVKzHCWPu0qKnKIeT/t8c3d91g6DBbQaD6m7FFD+8hn+ClJ+HicKZhXN8vC5tetNbKqab0AaATNZDSu+m0Moja+oFoiet74BQdLDWIRW7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=hqXbj257; arc=none smtp.client-ip=209.85.128.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="hqXbj257" Received: by mail-wm1-f42.google.com with SMTP id 5b1f17b1804b1-4538bc52a8dso6815305e9.2 for ; Fri, 04 Jul 2025 05:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633939; x=1752238739; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=chUTeulTUPdeqVOJNiNnsekTGU96gw2BccovvxawDKo=; b=hqXbj257IxLgpASSb+RAohYUPutr3Rrz56TuXUwcYt6FiZb18pBpDGbJC7MQRQRoo4 /JDesDauwNibsTyog8lgY6xF7Ktgjnn4Aj36Z0UlXdHLUb1HIhgEnqJogY6MObMG0L+t lS1hIwUt7KUVseXJWrFfqrkru0YQKmBLLBKVkyTNDWeg5HgWlqkZarC81fdndQ3O+aPN LSOT+uTCq2LkUV+zlFjadQaYLrWTlqDa65IrUGMv5N19ndyJW8UHFvh1ASEJJ0013d78 M9JHE4AZvUpe4WTJjmKuuZow6eas/xeV42ZtyAEncquPlNRW414gumAe1VhcLDUBVJCG wTpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633939; x=1752238739; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=chUTeulTUPdeqVOJNiNnsekTGU96gw2BccovvxawDKo=; b=E3C2j6wbRh08dFapXhXWR/QCrmcx/uhXCrpp/fbwc8WmnBxbqu7IDdIKsKMZiOiXRp GWYfZxVWpD1hV3Y/Kf2n9qXg6zFKWkhjkw+/PBY7QGJZXsjxb+ivxRTWQn8PaOhCpqjI aZ7qKBsPUcjEV62BiS/Hf/HxdoKjO/OZlw9z+Lar8vDgvh+BKvhNuQ7fGPbxp7graZVw JJxRrrnfaaDhn0EgvOeMvyjDvXk4ti5mSNUKmXWKu+D4WSY1ib3eA04nQXXFNh8sP+NK RY6l7wqVLa630EQfz5rZSJ/slYq3kJenzrD+Y2mgUcVMEgveMjhX1t+nC1B9UpKNzhii NfGQ== X-Forwarded-Encrypted: i=1; AJvYcCU92lhWIRkpWFfJ5F7UJ7Kl5JHyKzFLnNzRsCXjv7yxMOxDOW35hSGooTGv8mlGXtkNKTvSp6+hkS7vat4=@vger.kernel.org X-Gm-Message-State: AOJu0YyMHbXd6f0NgKgAKq29Fct1m++cuDbWTg00yp6okykOUg8RHs1X QxctlColG3ztDMHDedk8FyT3ik+9ddNPFVjplgYjtYoWTcyOEtO2mqwU45Aghp6KvH0= X-Gm-Gg: ASbGncueY9nt063TqUuTXhc+XFfVU2Nrx73b+XeDebHhcfQkHEKNgXOu3oV8auXBl97 ygYNzFec0a87yD8nuss0s9N/AJEX0YzLKLx96tniQLVauhRQWhbcpp0PDVKg11JthkxAnjCegv6 DL/JJ+qASo733fFuL3YnmZPhfUk6yY3jk1iiY3pQc4ywMS61iMRwu/tZvNKuOiibjFD3cz4wmnD ROOsbQmVDL/mGkIgHAE7TRGSKzIeha4kdmttlDY8VBOhZz2+4sIjIIRntephVxKIywZHkSXKP+8 s4GC7/6toDbM/QaEphYkYf8Be2dbONoFDXukd0AaCsYtmR98VEQPPxJOWCZsUGsWQw== X-Google-Smtp-Source: AGHT+IFZsxDFGsENnbAxd4uEJgHOkB70NNoxo3f2t8JXpzb3sCCH+idVcQZQ6iCzYFTSff30PFmkFw== X-Received: by 2002:a05:600c:3487:b0:43c:f3e4:d6f6 with SMTP id 5b1f17b1804b1-454b319326fmr27666635e9.31.1751633939453; Fri, 04 Jul 2025 05:58:59 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.58.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:58:58 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:51 +0200 Subject: [PATCH v4 04/10] gpio: sysfs: pass gpiod_data directly to internal GPIO sysfs functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-4-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3592; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=OQguaD3u1rCmwb79TkTjoMlipA/AyroTXpUaKeZMACU=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9ALKbygKkNInfE1rZp+MSje0r1Pe8dXXF7eI UkE/owHd6OJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCwAKCRARpy6gFHHX cmAMD/0dkkcQ1Lgyn5JoVK4UyoFt5HdrbSy7z9imWG4iqGGL9KQpQoJby4gZM4ctqiiccsMF1pj HcUt/XVF4l9coo5BQaKGxZxMrwi1i9LUmwBOuOuE2LKGu4VWLCGSyXwbdLQIhwG5mIBL+Art4C1 QJ4yeOKdMLQRQm8EvAPiN+q6UArAENfw+xCrNRKtoQGGvCatMck8KCVrUPq3YdWSq29ZmEY031F Tt+OQPyKkfTKIzXiW7iXCoZkjDW2uesY8qrsyfymoDUiVBOa5Et0Q/EJ4yfh6W392m0syt7eONk TLdiBCD3bm2Orx235jVn6Gomv5x7/thDpe/j6mltVIxLX5wqUQKq6WQd+9h1Bao/5+5S6kaH0uh YhzdyOBKfe9FRMjJ6NcvVTCDm1prwpq36HbWtN66kXjondhrixkX+xzYGX2l6Ak7dP/BzFEJcA+ yVmNc/y3qJEV9f56gsxtGaKy4xCJWZg9ysRFb1YpiNLt5jH7FPKLCDlwRz8TvKGlYd5T4qfNSz+ FTV9KNsphx7hqP4eLcwZeODv6bL6VaOYVTSAr6vd+z6jtGqA/aL/Hhfl9+RqhLd3fCI+wjPkKy7 lxYv+ffN65md1sXCERyYWQF3kR6BNmFqYlqwm5RvNPy/VxrbgQaOXwX/QoooI9XPcs6w/skY7KT vuAnat5VCsTCaqQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski We don't use any fields from struct device in gpio_sysfs_request_irq(), gpio_sysfs_free_irq() and gpio_sysfs_set_active_low(). We only use the dev argument to get the associated struct gpiod_data pointer with dev_get_drvdata(). To make the transition to not using dev_get_drvdata() across line callbacks for sysfs attributes easier, pass gpiod_data directly to these functions instead of having it wrapped in struct device. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 39e9ca31f034e20abd08fb5e9b4eecf24f127d5e..0cfa73e92b47fd089b973e96b50= 62694b7f8abd3 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -162,9 +162,8 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) } =20 /* Caller holds gpiod-data mutex. */ -static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags) +static int gpio_sysfs_request_irq(struct gpiod_data *data, unsigned char f= lags) { - struct gpiod_data *data =3D dev_get_drvdata(dev); struct gpio_desc *desc =3D data->desc; unsigned long irq_flags; int ret; @@ -223,9 +222,8 @@ static int gpio_sysfs_request_irq(struct device *dev, u= nsigned char flags) * Caller holds gpiod-data mutex (unless called after class-device * deregistration). */ -static void gpio_sysfs_free_irq(struct device *dev) +static void gpio_sysfs_free_irq(struct gpiod_data *data) { - struct gpiod_data *data =3D dev_get_drvdata(dev); struct gpio_desc *desc =3D data->desc; =20 CLASS(gpio_chip_guard, guard)(desc); @@ -278,12 +276,12 @@ static ssize_t edge_store(struct device *dev, struct = device_attribute *attr, return size; =20 if (data->irq_flags) - gpio_sysfs_free_irq(dev); + gpio_sysfs_free_irq(data); =20 if (!flags) return size; =20 - status =3D gpio_sysfs_request_irq(dev, flags); + status =3D gpio_sysfs_request_irq(data, flags); if (status) return status; =20 @@ -294,9 +292,8 @@ static ssize_t edge_store(struct device *dev, struct de= vice_attribute *attr, static DEVICE_ATTR_RW(edge); =20 /* Caller holds gpiod-data mutex. */ -static int gpio_sysfs_set_active_low(struct device *dev, int value) +static int gpio_sysfs_set_active_low(struct gpiod_data *data, int value) { - struct gpiod_data *data =3D dev_get_drvdata(dev); unsigned int flags =3D data->irq_flags; struct gpio_desc *desc =3D data->desc; int status =3D 0; @@ -309,8 +306,8 @@ static int gpio_sysfs_set_active_low(struct device *dev= , int value) /* reconfigure poll(2) support if enabled on one edge only */ if (flags =3D=3D GPIO_IRQF_TRIGGER_FALLING || flags =3D=3D GPIO_IRQF_TRIGGER_RISING) { - gpio_sysfs_free_irq(dev); - status =3D gpio_sysfs_request_irq(dev, flags); + gpio_sysfs_free_irq(data); + status =3D gpio_sysfs_request_irq(data, flags); } =20 gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); @@ -345,7 +342,7 @@ static ssize_t active_low_store(struct device *dev, =20 guard(mutex)(&data->mutex); =20 - return gpio_sysfs_set_active_low(dev, value) ?: size; + return gpio_sysfs_set_active_low(data, value) ?: size; } static DEVICE_ATTR_RW(active_low); =20 @@ -814,7 +811,7 @@ void gpiod_unexport(struct gpio_desc *desc) * edge_store. */ if (data->irq_flags) - gpio_sysfs_free_irq(dev); + gpio_sysfs_free_irq(data); } =20 put_device(dev); --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93C2E2FA637 for ; Fri, 4 Jul 2025 12:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633945; cv=none; b=MnlY7+np/ynhz3DpAyf4/vInXp/tg9/PRgPrvM7xZpJHryP1EV/wzaipshRz7m+2MeAQU0PvdO0ZGD697kUmOpgb/Vu+kYSGm4iyMIKIJGX99sCDqRGdQFRBB1EoKY+dGqvP+v/KyZ4a5KAggXeYWF3gZshCwnhHeWiB2KkQSMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633945; c=relaxed/simple; bh=YIyf520yc3OL6nrbv6RXMcd4vJ6epUbAY2ZFYCYhm9g=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gQXPS+Erw9cU1R3ynMXpu4VeGY/I53Fj1EZvIYXqL7Ub3NfnjYY6o2IRWg10MzoTFs5f2L2OymQl0QpNmU//M4MixEzyHaEQ0UTFMztVowJoEm2hU4AF2MlILbWRhSoydIPRqqCdzhE/yr2SiwhPKNUEl2qDXYi5FJkISNy8d64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=qVKCBgL+; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="qVKCBgL+" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-45348bff79fso9981005e9.2 for ; Fri, 04 Jul 2025 05:59:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633942; x=1752238742; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uBbCm54nWGP41Xnu/OzYvjIQKhcDFEESF+8gEh+/CCU=; b=qVKCBgL+hwKxl4Kr4Ez33aiFY9RAfkDJuow4aOSpLBLh//m+PdF2nnoTav6PswkPcp rO7reudU30GTrUQ6vzpNUopnW4AT2221Zapipuzr61OpnHiRicC3J1BI6Kth+YFr39yi hWZ//z7MSD2w8iZUu8ezHSZLz8YzhTl6e4naMlx01Z2UBmlYAeQ/raVjpcMfS8v8Lft2 iHeLpCYTidnwe6DOc2oe8gfy2FF/t81AGlhNs9Eua5tyAvWj4Uw7Oi/Ua96zILHLDCwK cUJzq1rXCtIZrWzCUoXLANX3Q6YMa5TmFpepj0ZXcTYT5SJuhNhaTuPR31ynEf/PuSnV W7tA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633942; x=1752238742; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uBbCm54nWGP41Xnu/OzYvjIQKhcDFEESF+8gEh+/CCU=; b=c7ebj74/FmniZk96aWsBpO/zC69uBLntSlkFLlDBGKu3Syf5b8EfQ9T9chl6AUCFVU 0DfQkesJKpAjI70dDbFX6Avlojf3CP/uzMezQn5BZA7aSca2hXLQf2UoSbGTAcs+L6aa 0YziKhnu8hUBjohcbnyXSFSCwvhieHXAdjXGRb53SDxsfbRRZwdSwYb3h7zLhqITdQ+h y4zszl29tGlPcpsyAzljE2QiX15C8iu+H02wUOqy9MSbotX+ends7lcWXk1Pp4eBXSSq kfP28SGumdKwr8L0dy8rqlIiR30eJBL5zG88tY+pJWmluL2zLx9NFRcf1H2E6GF16oTg xHQw== X-Forwarded-Encrypted: i=1; AJvYcCUT2HaMxmnWP4w3qsSec+ZVVE9WsN+3uFyAXadsv+LOMiVsJcXT5lB8Awk2MY5OhfOFpvbW49nlkHkUKhI=@vger.kernel.org X-Gm-Message-State: AOJu0YxttaWc8mp3HNhJi3neeTO+WpAJzXNDvTyYVMnWeEldwc2CSqrt x2T/fqaUsxNnx9Gl/2x5iszd17Lw7dTb/GF+YGpDnHPFZ8FcJIcqXWolSyoNlclh75MAFqbIFbo 7jDFyJOM= X-Gm-Gg: ASbGnctTk3odVN1YCZHJW96rW1yqOeeh2oDWYoo5evG0nuQWhRA6Vmit0vKAouOjgZf 26WyicZkNimxsD6j8mUnLmZVrZ9MM4/p+DUpGoAIej6yxf0Wo+EmKORqFiIcyqp8PcsG9cPEXKH 4FMtyr8ILTlcNlF3z6GUCFQuc+yqlwIHixhlWEfTn0fi6nt5p3HeE1Cyk7GETPsqLrp2nDoNUgA VxTNVmMS0x2V0ZlTy/TKalosfULcOGqakw+oB0ArQycnCnxx8poTQMC1nGg3Mnl0PoOp+QFkpGC nT+X1UuLPZlYx+4dEeasEFOEcRt6S4znyOqt0JvQEBH4y3sIbwMGlcnBN307Vntx0g== X-Google-Smtp-Source: AGHT+IGcBL5wyWMy6b4MR/KDtrIlyFD0sCwPdUXj+dZQvTg43CODdUPLPZuHEXZO0DSqXmbNQWmAcg== X-Received: by 2002:a05:600c:540f:b0:441:b076:fce8 with SMTP id 5b1f17b1804b1-454b4e85deemr23044245e9.14.1751633941705; Fri, 04 Jul 2025 05:59:01 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:00 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:52 +0200 Subject: [PATCH v4 05/10] gpio: sysfs: rename the data variable in gpiod_(un)export() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-5-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3480; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=dJVPDQuNRoeklWW2H8ZncDbRs/7tZWGjs63kgy+WzDA=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9ALBZ351aGMbGuaCcMzaY0jiNzLRhMAJU3n0 cig/Q6fg2SJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCwAKCRARpy6gFHHX cvy6EADN6IzH+Oz0QYqPlAnYqY3ARRz7lJnjAcdX4BwPWrW0cokk6Djb8fDI1dIjfUhO5TyolvF ExvGMv7Vw+ZcDLqi2h7P4axU7hpoKh1ybLcjJTwxKie4IoAubRvUOc3wsay3ZThXYnwrYS+PzT/ SpC3gf9HxH8/0ZAO4kUzD6BXQ1vgvLWGb6mYnYwvQ/1Rx2WCi5ghsQXaqeZhiSiWUu0PbCmV17B hl7J60qTwYAS68EVCrlvkmDIt3u91oyYrAZlQFQ9qxjaLASfZpmOn0OREPfmL/JC0UAHrIZnE5O XdNVjSXHxPIwDtBPvUsIWELGpueaPiB7bp5ZxG0a/Ly/NarPFim8aKLD0eR8/eA0oJblA/uDc3w n5H0Q3ZvgPtObcBrzA0tN/AWcbpoVbDmbNhgVY0dFUPYFQxlyydaRw/vv/03ZgCUaPWJ9RkeQfT RWwaTiTfpBrYndSSEgrqAKMvmmquOFrhyfQLOuStnoS8FbIfbkrkIdjFESE8iSxrbPczHapcZNe hCblRShVbBr1CuPHQ2aPcJCakwV/DD9uKfFliiefa9/Dht1HW3fvq2iy4+BmRNVt8QbOG3NZDmN 4a8mleI1e6iGvSnAvxJQcczmuH0W1Y1wOp0SpxGYOTr+HKBg+za+D73ZenC0Vuc8kuYPKvVy8un lHdgLa8d5JlkzZA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In preparation for future commits which will make use of descriptor AND GPIO-device data in the same functions rename the former from data to desc_data separately which will make future changes smaller and easier to read. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 0cfa73e92b47fd089b973e96b5062694b7f8abd3..fc9c19fde3f12c16a26aa09dcb6= f17960942c4bd 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -663,8 +663,8 @@ gdev_get_data(struct gpio_device *gdev) __must_hold(&sy= sfs_lock) */ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { + struct gpiod_data *desc_data; struct gpio_device *gdev; - struct gpiod_data *data; struct device *dev; int status; =20 @@ -696,29 +696,29 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) goto err_clear_bit; } =20 - data =3D kzalloc(sizeof(*data), GFP_KERNEL); - if (!data) { + desc_data =3D kzalloc(sizeof(*desc_data), GFP_KERNEL); + if (!desc_data) { status =3D -ENOMEM; goto err_clear_bit; } =20 - data->desc =3D desc; - mutex_init(&data->mutex); + desc_data->desc =3D desc; + mutex_init(&desc_data->mutex); if (guard.gc->direction_input && guard.gc->direction_output) - data->direction_can_change =3D direction_may_change; + desc_data->direction_can_change =3D direction_may_change; else - data->direction_can_change =3D false; + desc_data->direction_can_change =3D false; =20 dev =3D device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), data, gpio_groups, + MKDEV(0, 0), desc_data, gpio_groups, "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status =3D PTR_ERR(dev); goto err_free_data; } =20 - data->value_kn =3D sysfs_get_dirent(dev->kobj.sd, "value"); - if (!data->value_kn) { + desc_data->value_kn =3D sysfs_get_dirent(dev->kobj.sd, "value"); + if (!desc_data->value_kn) { status =3D -ENODEV; goto err_unregister_device; } @@ -728,7 +728,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) err_unregister_device: device_unregister(dev); err_free_data: - kfree(data); + kfree(desc_data); err_clear_bit: clear_bit(FLAG_EXPORT, &desc->flags); gpiod_dbg(desc, "%s: status %d\n", __func__, status); @@ -785,7 +785,7 @@ EXPORT_SYMBOL_GPL(gpiod_export_link); */ void gpiod_unexport(struct gpio_desc *desc) { - struct gpiod_data *data; + struct gpiod_data *desc_data; struct device *dev; =20 if (!desc) { @@ -801,22 +801,22 @@ void gpiod_unexport(struct gpio_desc *desc) if (!dev) return; =20 - data =3D dev_get_drvdata(dev); + desc_data =3D dev_get_drvdata(dev); clear_bit(FLAG_EXPORT, &desc->flags); - sysfs_put(data->value_kn); + sysfs_put(desc_data->value_kn); device_unregister(dev); =20 /* * Release irq after deregistration to prevent race with * edge_store. */ - if (data->irq_flags) - gpio_sysfs_free_irq(data); + if (desc_data->irq_flags) + gpio_sysfs_free_irq(desc_data); } =20 put_device(dev); - mutex_destroy(&data->mutex); - kfree(data); + mutex_destroy(&desc_data->mutex); + kfree(desc_data); } EXPORT_SYMBOL_GPL(gpiod_unexport); =20 --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C82F12FA65E for ; Fri, 4 Jul 2025 12:59:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633946; cv=none; b=sgSklnGx9aDfc8BD+kqG1fa0JWK3tqYTBgjfWXhc9dPoci76yY1MUdxA5hd+lU2xoRSLShCgPXbMDVtjslNYCEvSw1XFtuoJhjUWlOZYUjzEhB9wJ11gENJoeKFCAxVEAWD+yIQK7wurDM2IwzdL/M6YMt13yhMWKR1HxdyZvfY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633946; c=relaxed/simple; bh=cRLUt00itQyCNVDApOds8IW0t+If0N85EbImDHHhimc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=lWqSebmNNIMxeiBG54YpijXIO90cbdgzE/2bfYA/BbxoRyDA2X1o9P5VBoLnr2yV6dX0zSkOa7Y+VxlxWd4MalN9vX28y3b79zYvJl1S2kx86424Y/+eqSxJgCkRUd/34yydi9O+q1kbRmwJ4Z+Oehwld5idpzwiPBqB34kRXVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=lifRdjHz; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="lifRdjHz" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4538bc1cffdso7735895e9.0 for ; Fri, 04 Jul 2025 05:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633943; x=1752238743; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=LGmFGA8T0I8vbIJDw6IMfH4IDK3sle0n2iLWaYwSGLY=; b=lifRdjHzB5n76g8L+fA44Qs8QsLLpq4QR/hDkHeFqRtxkQEELBJN7Ig/7ifJ6YazSl Kw72y0UfgZOeDsKasToo+dyiedjlgXUdN2Ru01PZVZ+2ooAkN9YHwT4PBR/SIGmefNFb D7R4mS4/eVUS13pb8JlOS6bHVaBI+Lesms2ou0iG3ZZ+CKHgADlbU5T0W0a1ccMABrpk edlAAsKFojUWePtni3a+SETWAKkAk6JUbT5TqSiNzzgAw2C2YEy7arof4WTx/UyAODJ1 aML4kRrQo4NndeJCIFkVzfSr5dVJ6v+nEg2s4k2ccje8SQ+qrrJ+gQ6TGRZIQOsXWz9p 83eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633943; x=1752238743; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LGmFGA8T0I8vbIJDw6IMfH4IDK3sle0n2iLWaYwSGLY=; b=ITCTpYAEWvdLqQPZSY8RN5bUhq1F9wpJvDooTCv7p9OuSiJaatC8cRtmXERpHDKL0f kEbTa6xF2gJnJ86uoseDbkeoOAtFBVQFHFdrYYPiCR8JFqBdOmOAerkOIM4eS4HPfpwJ lQPLT3A++aKqoo/1Xmcoctuo7a3LI/p/rMD/ncBRc8lvB338gYfs1lPfijfuOX/07CLp wnjofKQloqY2ZLcwNYCghIjBSuVczFEk8yVYKBoWFvEZfQUrpfU5XGMNeYwBMgBt6X3R d0lgqQREWIrSFEva3GkV5pZrXvy84vjeubuANPna0IyeiSjeNONjfeh/ulZZH7I9dR1G cP/A== X-Forwarded-Encrypted: i=1; AJvYcCV6hSx0mdHCoKEg8qXlIzKnJ+uMUE4tSD5G/jOQ9fHTqxDTnXOetunzq8wNADtCbanFZyHhEnP5NDgWJeE=@vger.kernel.org X-Gm-Message-State: AOJu0YyLd8hCIZf5DSgKLOGNMqTqRtL5l00pgmjGu/JUkmyvieuHX+7h 5mRNohr01hW4kOHm9ybuSFv/Kbc5bSLM3rpCGImPvVHDNFFfAtZJPltrJI7Aoxyu8jE= X-Gm-Gg: ASbGncty5RMm5gjcq6rX6rNTn/lCaKLdcbTQFSEEaMBqq1BIV7W5ROsciTY7B8i2shB VOkNb/pxB7SipeKpYCDTy9l6XrEcV3BaIjv7vj69FxVcK7qTSKQ+EpRcLQw8pfPTBVZk4TeObFh 5Sheuzc/m4psJybi4NTrJjRohRi94xd5KWe+4oSUdf6gieKrDd+4znDlLd05V1uMNT7B7lUMNe9 q+D5XUukx08eP2awcuHT4dSRiaYenUEFfqjXrQhojSx8+lcE749BGBZuDfjGk8XcuLalsubRgJg gCPJ/GsI+uG54A4GUgNeXK0uGt6RhuF6PUTYvKINPS5hfpmRA8mVMUE= X-Google-Smtp-Source: AGHT+IGoAGnybMHcQ7i1hiirbYZeH2V6G3az+afM2C1mRoLzxdmit+tRGWqqf1cz3gOBya/nH+kaXg== X-Received: by 2002:a05:600c:4686:b0:442:f12f:bd9f with SMTP id 5b1f17b1804b1-454b4eb82f0mr21794685e9.27.1751633942956; Fri, 04 Jul 2025 05:59:02 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:02 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:53 +0200 Subject: [PATCH v4 06/10] gpio: sysfs: don't use driver data in sysfs callbacks for line attributes Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-6-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9835; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=X0f/dTpikuoddylbcLQ9jRYPBWNTjeVjP/0rrKM/JVg=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9ALQsPodd5UdGApCUSkPgb4MuCj1CEH4jglu 167kjtKa8GJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCwAKCRARpy6gFHHX csohD/9pvVhcpETRjSkonAJFVIZU31wWxEbi5pxPaMDePNXtTox3H1vidTm3MD9ED2PrEY3/Msy OS+XpygSkDFkDW5hPzNww2Mqoklm96tFgJ9ZQnq56ZBBKboWYEuZX/6OxqvfdhuO5gFMpGRrFQ8 lFI/9TqXN0TGmJHY+1zRUtStDU0CcjAPLtnYyBkd2WJZaA3WaXVOZQFEYm3qCnFjLU6e8b/fqA+ KmeWEFHL8b0voN6T7JDWml2obMOf7YEOqh5kZSYRAdLvN9NN9YL94XAcVoyO6ZP44ajtcNTifyt 4xkFRBK91NXZiNj6Obrj8Ma4xEMwywfysi8gIVPVv3JsOoggEB7o2J2kfJHFIZ+k8s6jYe4PALA YNNLI2HEgi1wcnQ8KneFleaYs2VXrd21olDDApT7CC86zY5bS4gdWshcb5CLZAIMYxM2hW8O4HU HoeZTSKtEQZr+1nFZa+FSa3IzWVJgA1xpoOiR+Hjpk8bTaPOUT7/sOCq4QPglO/Xmt7MZ032hqE XYMwettsZvq5n6dFAml5JCDonYV4OhqwIzPlLbxdCUHZay0oFUVIKL5+gC78jlKbvptOot0monI jcWKs6W14Ntso+WGSt9QS7wDyBSdNEOhOMeBCGsXIaoqGMxXiw0Kb6uy4mqVUW5VLn0eB0eOl63 IL7HN79a1uf1EKw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Currently each exported GPIO is represented in sysfs as a separate class device. This allows us to simply use dev_get_drvdata() to retrieve the pointer passed to device_create_with_groups() from sysfs ops callbacks. However, we're preparing to add a parallel set of per-line sysfs attributes that will live inside the associated gpiochip group. They are not registered as class devices and so have the parent device passed as argument to their callbacks (the GPIO chip class device). Put the attribute structs inside the GPIO descriptor data and dereference the relevant ones using container_of() in the callbacks. This way, we'll be able to reuse the same code for both the legacy and new GPIO attributes. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 123 +++++++++++++++++++++++++++++----------= ---- 1 file changed, 83 insertions(+), 40 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index fc9c19fde3f12c16a26aa09dcb6f17960942c4bd..e10d720ee0adb3b0f6e91eccbf6= 4c33e5700c616 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -32,6 +32,15 @@ struct kernfs_node; #define GPIO_IRQF_TRIGGER_BOTH (GPIO_IRQF_TRIGGER_FALLING | \ GPIO_IRQF_TRIGGER_RISING) =20 +enum { + GPIO_SYSFS_LINE_CLASS_ATTR_DIRECTION =3D 0, + GPIO_SYSFS_LINE_CLASS_ATTR_VALUE, + GPIO_SYSFS_LINE_CLASS_ATTR_EDGE, + GPIO_SYSFS_LINE_CLASS_ATTR_ACTIVE_LOW, + GPIO_SYSFS_LINE_CLASS_ATTR_SENTINEL, + GPIO_SYSFS_LINE_CLASS_ATTR_SIZE, +}; + struct gpiod_data { struct gpio_desc *desc; =20 @@ -41,6 +50,15 @@ struct gpiod_data { unsigned char irq_flags; =20 bool direction_can_change; + + struct device_attribute dir_attr; + struct device_attribute val_attr; + struct device_attribute edge_attr; + struct device_attribute active_low_attr; + + struct attribute *class_attrs[GPIO_SYSFS_LINE_CLASS_ATTR_SIZE]; + struct attribute_group class_attr_group; + const struct attribute_group *class_attr_groups[2]; }; =20 struct gpiodev_data { @@ -79,7 +97,8 @@ static DEFINE_MUTEX(sysfs_lock); static ssize_t direction_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + dir_attr); struct gpio_desc *desc =3D data->desc; int value; =20 @@ -95,7 +114,8 @@ static ssize_t direction_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + dir_attr); struct gpio_desc *desc =3D data->desc; ssize_t status; =20 @@ -112,12 +132,12 @@ static ssize_t direction_store(struct device *dev, =20 return status ? : size; } -static DEVICE_ATTR_RW(direction); =20 static ssize_t value_show(struct device *dev, struct device_attribute *att= r, char *buf) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + val_attr); struct gpio_desc *desc =3D data->desc; ssize_t status; =20 @@ -133,7 +153,8 @@ static ssize_t value_show(struct device *dev, struct de= vice_attribute *attr, static ssize_t value_store(struct device *dev, struct device_attribute *at= tr, const char *buf, size_t size) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + val_attr); struct gpio_desc *desc =3D data->desc; ssize_t status; long value; @@ -150,7 +171,6 @@ static ssize_t value_store(struct device *dev, struct d= evice_attribute *attr, =20 return size; } -static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_st= ore); =20 static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { @@ -247,7 +267,8 @@ static const char *const trigger_names[] =3D { static ssize_t edge_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + edge_attr); int flags; =20 scoped_guard(mutex, &data->mutex) @@ -262,7 +283,8 @@ static ssize_t edge_show(struct device *dev, struct dev= ice_attribute *attr, static ssize_t edge_store(struct device *dev, struct device_attribute *att= r, const char *buf, size_t size) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + edge_attr); ssize_t status =3D size; int flags; =20 @@ -289,7 +311,6 @@ static ssize_t edge_store(struct device *dev, struct de= vice_attribute *attr, =20 return size; } -static DEVICE_ATTR_RW(edge); =20 /* Caller holds gpiod-data mutex. */ static int gpio_sysfs_set_active_low(struct gpiod_data *data, int value) @@ -318,7 +339,8 @@ static int gpio_sysfs_set_active_low(struct gpiod_data = *data, int value) static ssize_t active_low_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + active_low_attr); struct gpio_desc *desc =3D data->desc; int value; =20 @@ -332,7 +354,8 @@ static ssize_t active_low_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct gpiod_data *data =3D dev_get_drvdata(dev); + struct gpiod_data *data =3D container_of(attr, struct gpiod_data, + active_low_attr); ssize_t status; long value; =20 @@ -344,48 +367,34 @@ static ssize_t active_low_store(struct device *dev, =20 return gpio_sysfs_set_active_low(data, value) ?: size; } -static DEVICE_ATTR_RW(active_low); =20 static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *att= r, int n) { - struct device *dev =3D kobj_to_dev(kobj); - struct gpiod_data *data =3D dev_get_drvdata(dev); - struct gpio_desc *desc =3D data->desc; + struct device_attribute *dev_attr =3D container_of(attr, + struct device_attribute, attr); umode_t mode =3D attr->mode; - bool show_direction =3D data->direction_can_change; + struct gpiod_data *data; =20 - if (attr =3D=3D &dev_attr_direction.attr) { - if (!show_direction) + if (strcmp(attr->name, "direction") =3D=3D 0) { + data =3D container_of(dev_attr, struct gpiod_data, dir_attr); + + if (!data->direction_can_change) mode =3D 0; - } else if (attr =3D=3D &dev_attr_edge.attr) { - if (gpiod_to_irq(desc) < 0) + } else if (strcmp(attr->name, "edge") =3D=3D 0) { + data =3D container_of(dev_attr, struct gpiod_data, edge_attr); + + if (gpiod_to_irq(data->desc) < 0) mode =3D 0; - if (!show_direction && test_bit(FLAG_IS_OUT, &desc->flags)) + + if (!data->direction_can_change && + test_bit(FLAG_IS_OUT, &data->desc->flags)) mode =3D 0; } =20 return mode; } =20 -static struct attribute *gpio_attrs[] =3D { - &dev_attr_direction.attr, - &dev_attr_edge.attr, - &dev_attr_value.attr, - &dev_attr_active_low.attr, - NULL, -}; - -static const struct attribute_group gpio_group =3D { - .attrs =3D gpio_attrs, - .is_visible =3D gpio_is_visible, -}; - -static const struct attribute_group *gpio_groups[] =3D { - &gpio_group, - NULL -}; - /* * /sys/class/gpio/gpiochipN/ * /base ... matching gpio_chip.base (N) @@ -645,6 +654,21 @@ gdev_get_data(struct gpio_device *gdev) __must_hold(&s= ysfs_lock) return dev_get_drvdata(cdev); }; =20 +static void gpiod_attr_init(struct device_attribute *dev_attr, const char = *name, + ssize_t (*show)(struct device *dev, + struct device_attribute *attr, + char *buf), + ssize_t (*store)(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count)) +{ + sysfs_attr_init(&dev_attr->attr); + dev_attr->attr.name =3D name; + dev_attr->attr.mode =3D 0644; + dev_attr->show =3D show; + dev_attr->store =3D store; +} + /** * gpiod_export - export a GPIO through sysfs * @desc: GPIO to make available, already requested @@ -665,6 +689,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) { struct gpiod_data *desc_data; struct gpio_device *gdev; + struct attribute **attrs; struct device *dev; int status; =20 @@ -709,8 +734,26 @@ int gpiod_export(struct gpio_desc *desc, bool directio= n_may_change) else desc_data->direction_can_change =3D false; =20 + gpiod_attr_init(&desc_data->dir_attr, "direction", + direction_show, direction_store); + gpiod_attr_init(&desc_data->val_attr, "value", value_show, value_store); + gpiod_attr_init(&desc_data->edge_attr, "edge", edge_show, edge_store); + gpiod_attr_init(&desc_data->active_low_attr, "active_low", + active_low_show, active_low_store); + + attrs =3D desc_data->class_attrs; + desc_data->class_attr_group.is_visible =3D gpio_is_visible; + attrs[GPIO_SYSFS_LINE_CLASS_ATTR_DIRECTION] =3D &desc_data->dir_attr.attr; + attrs[GPIO_SYSFS_LINE_CLASS_ATTR_VALUE] =3D &desc_data->val_attr.attr; + attrs[GPIO_SYSFS_LINE_CLASS_ATTR_EDGE] =3D &desc_data->edge_attr.attr; + attrs[GPIO_SYSFS_LINE_CLASS_ATTR_ACTIVE_LOW] =3D &desc_data->active_low_a= ttr.attr; + + desc_data->class_attr_group.attrs =3D desc_data->class_attrs; + desc_data->class_attr_groups[0] =3D &desc_data->class_attr_group; + dev =3D device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), desc_data, gpio_groups, + MKDEV(0, 0), desc_data, + desc_data->class_attr_groups, "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status =3D PTR_ERR(dev); --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 412BE2FBFFC for ; Fri, 4 Jul 2025 12:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633948; cv=none; b=i65Pk8ski0hJY4u1n98WtT+eLjbC2JAkCnwlt5fLyHk54zYPqQCndpJurKve6Uz/0TP6NBsfNeHSH0iv6ax0cksmGiV36HynMUWWp0g9wmpZOlnjMg92s+4L278OVMMhlwU0fqpDC3fUSBolCpgzK0cSwj9/iQlsC0w5cibPQrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633948; c=relaxed/simple; bh=HSQrtGe4/Z0TBW+gwH8FOlwHslQisfYTdDaYyI3dFb8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=dAEqF8f5NOR3pPKHfH8kwWVMg/4EMUIJPwN3v0Koz6Q+AoHO0FhpjpaHO4mmT6rsxzX8lyNhYJB45qm8IcDj3uSir0H4gkrLDxzpgekyhw2jco2Bb+j1yCqC+GjZXr66ei7QDVeFCk3sV99ijdf0etYESApvAWZUvxSgbdQ80Zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=AWyQhWov; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="AWyQhWov" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-453608ed113so10072605e9.0 for ; Fri, 04 Jul 2025 05:59:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633944; x=1752238744; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=BMEMEAqg83bufN2QGDWBOgNHkNfUTOyZRf8AHX0Mf9g=; b=AWyQhWovjeK4CkJQanLCf3+cTor+PiwLoyFEiGbBEREs+1IfNvT++A6O/N84IRnjyD p6Y4AvM1KOF2w0euIDlews2/1emcv80hjELuMW1PqOGSGaZep6NY7xCGGPdkMPu8qhY8 9XKmXLjc5OHdOxVAZWe7p9BYSTw2CilZdYUVDv/q3+cu6Xj5GWI1o0Q6qiARpj+5O+R0 gOwq9M+LIJ9Nongg1Uxmq3gcuiSgxEj5JFkskrbsRFZUgjY1n+xZ/WcE7cA9/5ADsqG9 dOyo2ri1+ki8w6KRi1Yml65l83zq9bnFEQ/MRnXJUv63ZiSNQiA2neBtDFZLsv7OL1Sv AmSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633944; x=1752238744; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BMEMEAqg83bufN2QGDWBOgNHkNfUTOyZRf8AHX0Mf9g=; b=OycI+ej24Ap/JUDB20eckT+gfn2+3Ih1/iIRAPSnsRgUg3jFOARGQMPpCRYvF9/Rop 7M2YgQ2PcvjHAftuxg1AErzvSEWsayYvtQ5neWOWlKF2vRzOj/zeds9Koly0kO6Qg+X0 w0XYATVmHogshqA7u3/BAFul1I/9odERGIrY7UbsMHBLmQ32P5pcn3JO+i5qkjSxBWib ajES6pqD0qvCVqOrYSxaAA/t8WEB2SYbd4cbUhGHJ1K7BtXflUFaMUgastPbRkFkvW07 xcvXOIn4vSKAUBaUHymNnG0p8dpdybn0OylwSUVbTS6wd8Y9ln8RXcA2Uhvcy5cGVxzh qMTw== X-Forwarded-Encrypted: i=1; AJvYcCUvk0Rp71s8uhejr/hCHdtgGUWaoSpaaJ7t4SgeALE+z4aU+gIxFeE/VLo3ith79x/0lRmkm4T8L+11DhQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwF088IGhMQlGqszY32fs/v5oZuY5vO23EnUmt8Nk71IiY/1DBL /vdYQHaxKLpQo8K250aQ1pHCn2sIZx0gQPttIKc1mh4dBY9Acp7i4oXS9952NN4yYVFryjaiWg3 oy3z3FOA= X-Gm-Gg: ASbGnctBiFd3cpD6tuEUfGkjtJXTFkeVVjeH6KmeiFrQmecCXKxgIPNK2s6zm70rnYQ EplsaoRG5IzStaj++e/lQhNOaSfdM6tL1IOXV2joqthSSZZpIFnfHZpvUedfbhRUd//91x2fOTh vR/V0qTh/A1kOvR0WyQcHBGDIdnCft0gj7Cw+mEk7SEci07MINZ5YAr+C6ZTPIu/oi6ev/jOYeV bKz7ntf8E+P2Ce4lZTWXcDLR64REoBeqIhy1a4+VhXz4lHIz7TChgg2y++te8iRRQn6+3lGvkIl 7vyDXbgI8sVAo0H2LVFGn0waNhALBEJCmRDA6c5vgAZ+q2+TdBW1ZKk= X-Google-Smtp-Source: AGHT+IHaSluiSjg6ZhGmsBkYXRIG9iwoBZVF5T5tgaWqiOqPiLzLikZKD5mhzB+Wy9gylFEewYJvkA== X-Received: by 2002:a5d:64c3:0:b0:3b2:e07f:757 with SMTP id ffacd0b85a97d-3b4964f5198mr2409455f8f.1.1751633944485; Fri, 04 Jul 2025 05:59:04 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:03 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:54 +0200 Subject: [PATCH v4 07/10] gpio: sysfs: don't look up exported lines as class devices Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-7-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4753; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=gFW3JmLsuFySaX3ICt4Hmzv3Y1dJIcjL8tzNr7Vj5fc=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9ALPECgZHxSOj7PIlfwj6d6B65AXnkb47jub lqMni47QJKJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCwAKCRARpy6gFHHX cp7HEADCzPIbVzpehNKQDCLf+jLNRs3MrkpbPHsavzLLFI2F9sxsXacNI1pkqRaCTY53Y3N4Kuz oFBUtdRrIFF0I2O75rsl+gjJTAAFXT0i0kLDCLRp1Wix8AZgCCqpESqJgVAVM2LuPTuWSPaxaqn c+4lgvdlDshS5kAl3KgKzQRsAyStCnX7U4H5Vhde8k0b0JWOhqGVpQ8XvZmBT8vzJC6vGsnXSKI fa3/rvBrn2Kt6QxGz28/Sb3mtECdw2ENuVjU83UZd8DuuG5ZnhjtW+WnFeJM/THodXvTCAHHs+q QBWnoA9ckrW41TJFOOT9q6W/FH63UVM5jzWziJG4EVY8nizqeR5DFSs04FuEkDCei6Me7MCYF8h 6pzHqWgiW/sK2tDZ5Z23jV7UunmnLQCNy4kWmndRVKx5DKZ0SutDvA7Lonuii4zzCpvwp5hkR3l nE54gO9ajX8sucK0OcO9i653k73fVt4HWMJrBF/hXgbeW4zGbNVXMM2BgV25LUW1axwwuLbmPb5 Ij8Hc+yriRCSQvxdylzYoPM1A7E2v/CAvcB10EoW7+bMJ3HXcFcBUCjLXEok4cUaD5GGNkqbTD4 Iy12o1KDhEfRhud68dUcq2f2Q5R6A24xREzMMnsp2G6KTido+ffIrE5U77xqIdlc/tzyeu/Xr3Q /Bj4BNdAkE11zCQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski In preparation for adding a parallel, per-chip attribute group for exported GPIO lines, stop using class device APIs to refer to it in the code. When unregistering the chip, don't call class_find_device() but instead store exported lines in a linked list inside the GPIO chip data object and look it up there. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 60 ++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index e10d720ee0adb3b0f6e91eccbf64c33e5700c616..ccc293a4cc5d512947039593170= 61af55fb0dab0 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -42,7 +42,10 @@ enum { }; =20 struct gpiod_data { + struct list_head list; + struct gpio_desc *desc; + struct device *dev; =20 struct mutex mutex; struct kernfs_node *value_kn; @@ -62,6 +65,7 @@ struct gpiod_data { }; =20 struct gpiodev_data { + struct list_head exported_lines; struct gpio_device *gdev; struct device *cdev_id; /* Class device by GPIO device ID */ struct device *cdev_base; /* Class device by GPIO base */ @@ -687,10 +691,10 @@ static void gpiod_attr_init(struct device_attribute *= dev_attr, const char *name, */ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { + struct gpiodev_data *gdev_data; struct gpiod_data *desc_data; struct gpio_device *gdev; struct attribute **attrs; - struct device *dev; int status; =20 /* can't export until sysfs is available ... */ @@ -751,25 +755,40 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) desc_data->class_attr_group.attrs =3D desc_data->class_attrs; desc_data->class_attr_groups[0] =3D &desc_data->class_attr_group; =20 - dev =3D device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), desc_data, - desc_data->class_attr_groups, - "gpio%u", desc_to_gpio(desc)); - if (IS_ERR(dev)) { - status =3D PTR_ERR(dev); + /* + * Note: we need to continue passing desc_data here as there's still + * at least one known user of gpiod_export_link() in the tree. This + * function still uses class_find_device() internally. + */ + desc_data->dev =3D device_create_with_groups(&gpio_class, &gdev->dev, + MKDEV(0, 0), desc_data, + desc_data->class_attr_groups, + "gpio%u", + desc_to_gpio(desc)); + if (IS_ERR(desc_data->dev)) { + status =3D PTR_ERR(desc_data->dev); goto err_free_data; } =20 - desc_data->value_kn =3D sysfs_get_dirent(dev->kobj.sd, "value"); + desc_data->value_kn =3D sysfs_get_dirent(desc_data->dev->kobj.sd, + "value"); if (!desc_data->value_kn) { status =3D -ENODEV; goto err_unregister_device; } =20 + gdev_data =3D gdev_get_data(gdev); + if (!gdev_data) { + status =3D -ENODEV; + goto err_unregister_device; + } + + list_add(&desc_data->list, &gdev_data->exported_lines); + return 0; =20 err_unregister_device: - device_unregister(dev); + device_unregister(desc_data->dev); err_free_data: kfree(desc_data); err_clear_bit: @@ -828,8 +847,9 @@ EXPORT_SYMBOL_GPL(gpiod_export_link); */ void gpiod_unexport(struct gpio_desc *desc) { - struct gpiod_data *desc_data; - struct device *dev; + struct gpiod_data *desc_data =3D NULL; + struct gpiodev_data *gdev_data; + struct gpio_device *gdev; =20 if (!desc) { pr_warn("%s: invalid GPIO\n", __func__); @@ -840,14 +860,22 @@ void gpiod_unexport(struct gpio_desc *desc) if (!test_bit(FLAG_EXPORT, &desc->flags)) return; =20 - dev =3D class_find_device(&gpio_class, NULL, desc, match_export); - if (!dev) + gdev =3D gpiod_to_gpio_device(desc); + gdev_data =3D gdev_get_data(gdev); + if (!gdev_data) return; =20 - desc_data =3D dev_get_drvdata(dev); + list_for_each_entry(desc_data, &gdev_data->exported_lines, list) + if (gpiod_is_equal(desc, desc_data->desc)) + break; + + if (!desc_data) + return; + + list_del(&desc_data->list); clear_bit(FLAG_EXPORT, &desc->flags); sysfs_put(desc_data->value_kn); - device_unregister(dev); + device_unregister(desc_data->dev); =20 /* * Release irq after deregistration to prevent race with @@ -857,7 +885,6 @@ void gpiod_unexport(struct gpio_desc *desc) gpio_sysfs_free_irq(desc_data); } =20 - put_device(dev); mutex_destroy(&desc_data->mutex); kfree(desc_data); } @@ -899,6 +926,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) return -ENOMEM; =20 data->gdev =3D gdev; + INIT_LIST_HEAD(&data->exported_lines); =20 guard(mutex)(&sysfs_lock); =20 --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63D0F2FC00F for ; Fri, 4 Jul 2025 12:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633949; cv=none; b=XtYA7cOumExXJ0rJjgBfBn2diEMgE3AjmqLaHPVV2HHmKXIaX1fgnVOwRmZ0r03dL7sodpydkSDThMYM6ARY6l0rYDGsWwIpuiVqkZOtkFfAx3OuLMHx7ps8nr+DpFGRB9L+op0cGgllPWPbdlq2ag7EfWWsyvMYGgZHz8ElO5o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633949; c=relaxed/simple; bh=MRAmlbg2el9RlT82IXfipSqk95B1KCNXrlmXQW0Xgmo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=po14U24TPF3+/xQ+tTFGfJpQFqv54IDTpiu44qUxLMPhwhvJBDnslrNU5QYpPGMEcTPg3jqK31/hEGpEOQ3hCUzPIEM9D9ZwnX/a+dOpesB81LyZRqM8Roj4ETkasY5cVZwND1qxvmyxb8ilIdrP1Nl3BUNz8r0qaP+jkpCUoaU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=GBMdmUer; arc=none smtp.client-ip=209.85.221.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="GBMdmUer" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a57c8e247cso699927f8f.1 for ; Fri, 04 Jul 2025 05:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633946; x=1752238746; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0mWdlg54oJudcLcZCbZIGM2v7WwK4QYuaO3Uvq5fqN4=; b=GBMdmUeru27gLfP01u/KnRnlevwTU6jvxOYIiq09CE8AmxnXH/OrExB2AjSfIxku3i jkKYeFzsnzdulSqXnJbnsmy0mcHCS2fDXTVPfBjV1DHeNshNVsXWJLSFuW92C05xa9H+ N+bImZ4Ybg+zrrrzQ3V+RLQRbguGFXEWscUnB9IaQ77n648e7TJbwVYQMIZ4H1YEEJq0 s/320UrEGQJv5MAG25uh3SRYk2m08EcJVCgjd1TV9iDGrLEueyV5z1rcQOj+l/4z9nuC K0oWXM3rdcW8kqjCyAd3Fz/VTvUAyAXh/OwX69oEGdmKjTOIqEfYXHEVWap1XJYvL9UU pFcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633946; x=1752238746; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0mWdlg54oJudcLcZCbZIGM2v7WwK4QYuaO3Uvq5fqN4=; b=va0l6YFVB6OAM7MrPR6hwS6hekBL957y9NMyo2DdtGW7qcVUBYy2GTMkr6aStTPJVZ QL3bd9xxUwje9dxsXT6jrDyngVIb6vqXCGcQ1KYXTlfDNWNAX44kF2KdPNp5piMp2kUS 9zJUrW/YaQ0GmCbct+YaNMJiYideVwzrH8HJG0wl5pV9WJiOwMQTUqrHLbZtOPFEFCwb LQ+kiW7dqX7E9HznOQDDN6/rjBmdfcb5SG8TQz2VuI7N4llTKixk/YtPnkgHbI9CUCRl EYPKxGT53uvhq2QckKJ0w62Xxw/VGidyhDeBFFOlX83kPDLAgafVPVNC8n4IlR8ZUZWt d3Xg== X-Forwarded-Encrypted: i=1; AJvYcCV2B7CPJIpJBq61MUGtHg+z5yIi5iRl/K9v+uSWV6/woO8fqXLvw2GILK4B/5BawQ1J898dUViz9mPwhag=@vger.kernel.org X-Gm-Message-State: AOJu0YywozP2foa4roo4hl18ZtjtucYQaP+2lBAzf2Yz9fvPW3nUdSNf pjY9UBLKTHNGnrpyN9jIj9YEw3CwCKTy4pTNZfBBohOrJIjb7mFpkLLsU9e+/M6MHKk= X-Gm-Gg: ASbGncvI5gt+f2pKQf3pF7CvYC+jbf9CwvVv+q15M4oaVR0+1ocROITzQDB8gXbxSS0 u1r0kqqh2RBvxZO51EprRWycw615CW8ne6FwbwBghxB8shz4BR2ASvXvuyZ8gu6ZHtTsKrmms0P HcNYbWGj6f/clauA97Mpb4foxFriOOTtwL8xC2/jpuz2icU+DT5lWKWPkJ/3/qCihgxDVwez/aA RD7o4o3XGk7wRJGeADbiesOyY6ma6ej8XDknWG+tDjSXNM09L8exW0nHIKo0gSMEo4jCU1bDQuk oiwDrKvsGpbka/B45uVJ4d8LB/7jwZEDHMToj69eXF2iKbm7/Rvr/H0= X-Google-Smtp-Source: AGHT+IHUN/J9ch4zZkcw26qV3iwG7fpp7cXYR7gk3IfEtkYyUXzrE2xtjGDXbgYjpYTt6DFJW6B8xA== X-Received: by 2002:a05:6000:2006:b0:3a5:2cb5:63fd with SMTP id ffacd0b85a97d-3b49700c452mr1896057f8f.10.1751633945736; Fri, 04 Jul 2025 05:59:05 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:05 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:55 +0200 Subject: [PATCH v4 08/10] gpio: sysfs: export the GPIO directory locally in the gpiochip directory Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-8-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4648; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=cYZbz96eXlnV3MjcgWxLoHkCLzWOQdWS5dSJMpwHOg8=; b=owEBbAKT/ZANAwAKARGnLqAUcddyAcsmYgBoZ9ALt9l9ireev9OrRcbTpBT1GQjAIm1/4RaPw udOH88TBkiJAjIEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQCwAKCRARpy6gFHHX cgvxD/dEQZku0pJR0CaOwt5rW6WAShbkSUtJIB/x2vcU+5upUjE2ADZzspk5Y+4CQtspOvMTIDD jmNoB3qOidul8p5fFvsvCi/ZZqYODZ8AJIIin3TfGLSJ1yPphG/9YF2pAPdaV7vxTLKmAufRDc5 u8Dv1BcK/5vec0NDFx8DnDtKoYgIFlDvM9tzpOXZuUN1zk6wgUrIH7Jk16Dc7tPlu0LTROGObpN bBNYT7Ki62zia7DsgdluaKXDlrgm37QPU6GYk5dCKvJvGj8razz987i3Ofg7SgkPLbALH/T/sBA wLwD4eKAUH9RC8J0/2RMrMZOUjPQ6ZXYhvwrpt/7fP7kjvrPj54DJTazLmDJpmvvx2JQt4CesQ2 jm/oU4uJv/f5cyphZHFaXuAw985kUEbAEQ3BW1aD0GjCGNSrbk/Uwcl/sG+EOalhFBrXiC5NCVg Btud9CzPFyIxR2ZrYCbtsI8FB4MriFnPIwc4ARBNCHgUPO/nHUAHFB4TdKCTlk55Q+eUecTeT5l TCclBQpI1fjNBr/AezHyLVumMx29N0TUPsLpvyQwovceSa7NO2XobM50M2ddcgvpBmafl7Cl8pX 23CR7B9xfzZNfzpJ/jPglyyqQqBsKe1ZIx8Wiy+E/FtKPgSgUU/3PCqS+iAhSJRezLnnRrmjxW3 A9qBdzQAb347N X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski As a way to allow the user-space to stop referring to GPIOs by their global numbers, introduce a parallel group of line attributes for exported GPIO that live inside the GPIO chip class device and are referred to by their HW offset within their parent chip. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- Documentation/ABI/obsolete/sysfs-gpio | 3 +++ drivers/gpio/gpiolib-sysfs.c | 51 +++++++++++++++++++++++++++++++= +++- 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obso= lete/sysfs-gpio index ff694708a3bef787afa42dedf94faf209c44dbf0..0d3f12c4dcbde4f93da33707cd3= 6e9acc0ee2fbf 100644 --- a/Documentation/ABI/obsolete/sysfs-gpio +++ b/Documentation/ABI/obsolete/sysfs-gpio @@ -27,6 +27,9 @@ Description: /base ... (r/o) same as N /label ... (r/o) descriptive chip name /ngpio ... (r/o) number of GPIOs; numbered N to N + (ngpio - 1) + /gpio + /value ... always readable, writes fail for input GPIOs + /direction ... r/w as: in, out (default low); write: high, low /chipX ... for each gpiochip; #X is the gpio device ID /export ... asks the kernel to export a GPIO at HW offset X to usersp= ace /unexport ... to return a GPIO at HW offset X to the kernel diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index ccc293a4cc5d51294703959317061af55fb0dab0..563e38456c33cd3a6e867448510= 5ef45ce8f5095 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -41,6 +41,13 @@ enum { GPIO_SYSFS_LINE_CLASS_ATTR_SIZE, }; =20 +enum { + GPIO_SYSFS_LINE_CHIP_ATTR_DIRECTION =3D 0, + GPIO_SYSFS_LINE_CHIP_ATTR_VALUE, + GPIO_SYSFS_LINE_CHIP_ATTR_SENTINEL, + GPIO_SYSFS_LINE_CHIP_ATTR_SIZE, +}; + struct gpiod_data { struct list_head list; =20 @@ -54,6 +61,7 @@ struct gpiod_data { =20 bool direction_can_change; =20 + struct kobject *parent; struct device_attribute dir_attr; struct device_attribute val_attr; struct device_attribute edge_attr; @@ -62,6 +70,10 @@ struct gpiod_data { struct attribute *class_attrs[GPIO_SYSFS_LINE_CLASS_ATTR_SIZE]; struct attribute_group class_attr_group; const struct attribute_group *class_attr_groups[2]; + + struct attribute *chip_attrs[GPIO_SYSFS_LINE_CHIP_ATTR_SIZE]; + struct attribute_group chip_attr_group; + const struct attribute_group *chip_attr_groups[2]; }; =20 struct gpiodev_data { @@ -691,6 +703,7 @@ static void gpiod_attr_init(struct device_attribute *de= v_attr, const char *name, */ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { + char *path __free(kfree) =3D NULL; struct gpiodev_data *gdev_data; struct gpiod_data *desc_data; struct gpio_device *gdev; @@ -780,13 +793,46 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) gdev_data =3D gdev_get_data(gdev); if (!gdev_data) { status =3D -ENODEV; - goto err_unregister_device; + goto err_put_dirent; + } + + desc_data->chip_attr_group.name =3D kasprintf(GFP_KERNEL, "gpio%u", + gpio_chip_hwgpio(desc)); + if (!desc_data->chip_attr_group.name) { + status =3D -ENOMEM; + goto err_put_dirent; + } + + attrs =3D desc_data->chip_attrs; + desc_data->chip_attr_group.is_visible =3D gpio_is_visible; + attrs[GPIO_SYSFS_LINE_CHIP_ATTR_DIRECTION] =3D &desc_data->dir_attr.attr; + attrs[GPIO_SYSFS_LINE_CHIP_ATTR_VALUE] =3D &desc_data->val_attr.attr; + + desc_data->chip_attr_group.attrs =3D attrs; + desc_data->chip_attr_groups[0] =3D &desc_data->chip_attr_group; + + desc_data->parent =3D &gdev_data->cdev_id->kobj; + status =3D sysfs_create_groups(desc_data->parent, + desc_data->chip_attr_groups); + if (status) + goto err_free_name; + + path =3D kasprintf(GFP_KERNEL, "gpio%u/value", gpio_chip_hwgpio(desc)); + if (!path) { + status =3D -ENOMEM; + goto err_remove_groups; } =20 list_add(&desc_data->list, &gdev_data->exported_lines); =20 return 0; =20 +err_remove_groups: + sysfs_remove_groups(desc_data->parent, desc_data->chip_attr_groups); +err_free_name: + kfree(desc_data->chip_attr_group.name); +err_put_dirent: + sysfs_put(desc_data->value_kn); err_unregister_device: device_unregister(desc_data->dev); err_free_data: @@ -883,6 +929,9 @@ void gpiod_unexport(struct gpio_desc *desc) */ if (desc_data->irq_flags) gpio_sysfs_free_irq(desc_data); + + sysfs_remove_groups(desc_data->parent, + desc_data->chip_attr_groups); } =20 mutex_destroy(&desc_data->mutex); --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F15A32FC3AF for ; Fri, 4 Jul 2025 12:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633950; cv=none; b=byc1Fk+7dknhUmKdEgaElFt1aCe/ba8jn49o2C5u0mvdYATMHvhl4rV7xRhMKi1D2haL37Y1GCL6SEY2GKB8AaAvIhfK90hoLYmbanv+E1/FH3hjTntEUqc/cOXFA+hgSSYZINGlQMpYWapOL8u7O8GXUfNUyt8dRfRaLStC7eE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633950; c=relaxed/simple; bh=SEQUE+wqnlsIeL+Vd0wTvWbzWH4y7y8v+wOvxDnzMmk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fw8MyPqYMXWgbScex26Nv8MnFELISI1u3kNpA5hzGyNDPAfur9zOksJC3fgHzzX8jmZuRDi1NcbDqlkQo2uJbBPbGIN1TXrYDBJmSuEuzJ0XR2RPRIpv2jt3Xyd0n6D1MV/UBHFpNrvaigMRJjEvCXnFGXmwjGk8Trizl2wcCBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=svLzJEZk; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="svLzJEZk" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-451d41e1ad1so6530185e9.1 for ; Fri, 04 Jul 2025 05:59:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633947; x=1752238747; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=6UOR2MPGqOiOmlbGxM7YXcw7cNM+OL5WteAFiwMTMKU=; b=svLzJEZkNQlSX/ccQ9lYyw+p78VFItVHNDrnxwP/kFrQys55lLbLfFh792WPmIXwXN DpyKD+VPbf5yYmHQXQyx6iK8ZjwQIUAulAsepFeV+/wVXaXodkfOEVgcEdeDLpePWGP2 FJU/8es19+3RpNvpOfTNQKpYGTL2vm+CzYEyVxDL/zzDV13tDodmY4WTKGCXUPMc7qDT BuLpJLA32QrwFsYKudPn3XTKNo1BJmqWT2wRBowEbSf0JZClraCuDMqpTpoaZileqqbv fxC/aDIzZ4p71YL5bfN6Twwv5RqbfrVwe4gHU4nsXuH+JTD7F+ogIocPfUyo+H9QrOUU 1u4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633947; x=1752238747; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6UOR2MPGqOiOmlbGxM7YXcw7cNM+OL5WteAFiwMTMKU=; b=PpZn7H8N8VxfXGoLR8QBFosFKe1euGM/qf7u3ZLFjxVGOblSWDU0UK+XyPLZU0Pld8 UALU+XfzTM5Fzs/P8jtvIqvrTWfY9Ahn1ZMQhCu3C2gQKbCuBJZs9yFGVjcPy8cLdbGP +LEqtykRl+7N40IYYDsh13+u1lbFOsM4gHnn8nW/EAM76n+xlGf4j5OjF0SWqHocd1SS 6AQ+R2VVWLKFjgbm3U17k5mX93wYYfO93epcvol99fBT713/aEwJiE6uC23wvOir4Bt6 9JVr/xdKwAIcxnjBS7uQGdS7lNn8twiIP+eNpwjXxapeDoSs9uRxodOCiBxh6Oezjho9 OTuQ== X-Forwarded-Encrypted: i=1; AJvYcCXVz/xpe1pNsF6TnFPogqJ5/nTM3KUIg28ct5S7Kzku/67Zu2kvDhuJwzDIIsCMAwCT5V7+LumO7ZKVJAc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9nLdUpQVVvn+jkpAcuQdADZqYxerD70FUy/GBDVq58iLD9T/r MbLqZtorj8Jd5Yh+hz7MNyADSA51aBNsnGqR4Ut/ABek3mgE7U/hJaDVPDLK+Yfj7cLY0sDbP50 k5t68pvY= X-Gm-Gg: ASbGncvMDenhFFvNqF6B4G3Dw1kuCkgfIarFjaleVZ7WLbbjqGTTGwtMLLRz0hkcTrO tphrM6INeIuMzl2kqhpB0NpBtYtUZI/+dR0GS/RqSWxvXIpSIEXh6eUruycDEBnl+1KG7+IZnLB yZ8bmAZmyxa36+FzGcTBh2Pahj4sFKU8Z55suO5cfMeUgpfWZm2GhAb396/y+kTZymbTVGnmjAc Bpx8onq4Y3Quv0iiiyDiv6dk/r60MiaYqQuK/JIGAmr3021QdoQQ7d4WYvriB04JGB1+SRZ2UwF 8ohmsCzGE7JN8ZqI+xL30r3QcklCrwpUe63NGcbYyBiyISblBxf7PsY= X-Google-Smtp-Source: AGHT+IHnksMyu8rvbVUDzpdeDkUVxrcX9/U69Pif100+iGeU2MGYmBeXjJy7gEarXskd975HFr0gFA== X-Received: by 2002:a05:600c:4f07:b0:43b:cc42:c54f with SMTP id 5b1f17b1804b1-454b835631bmr7435805e9.14.1751633947059; Fri, 04 Jul 2025 05:59:07 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.59.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:06 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:56 +0200 Subject: [PATCH v4 09/10] gpio: sysfs: allow disabling the legacy parts of the GPIO sysfs interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-9-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=9996; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=NprZaQcSbklXSYi5LBjzK05jcMN3zcONcmqjGfbIn0Q=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9AMQrcy/xXWwOFlmrFL1RwxS0/RzWVkEhsx4 i7sE3A33DyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQDAAKCRARpy6gFHHX cpREEADTTaWivKZMznFeC8Odftis9aDiF/hPq1Mlge1xvsvGB1w4bie1l0Jp1DFq/JzPOWjiYV4 9GqDGdkeC89xTOLq82prEh0tQFj26xBJ5fldUn+azcpIeDRkQ8oN1+yAIEsEwoUoPM/LsnkV5gj 10/w7C8MOIqWlfqH/flXDvv87hsV9kHiMNPRP1vU/nAFFn2UQnji+UNZmxm+HjF0YL9kR3WHxMr OJTMZ5mHVubfOMCVHftxkNj2PeSf/73JeY3KUvpgiSkviG59Dx8nATwCf5o4HHu1+4eqsbrh7+G m25tjDOTz32MeazcnZj+V/gTRR/sldDqM55ePv+iRS49C8ulVpPFmyyz431QJQlPTbHMefvpC9h fXxTgPX4K06ZunZm0/a4feFUDCZsI4OoXb5dMKaxQpbRYS2K86oFHttCd4LJGP1h4CCn7G6bK0N +Ml/pHD9iYyuCcLwpVXp4KGrImzoyFJW44jd1Nxxo9K976GswY17/7fHMwfugc+RsXYi4Nw7bZq s70Ew+UwPbjYgi4XiMLyVoM8Ic6MIDFRT6UreEtzpaP3rPnfG/nRd0eCQXjWeTaRP+3fLFE6kwc WRbHL0MQlQpyFHMyMvfPAorgSzhMWbxD6SVH1MI78TWXT6g3XFJRE018Sr3+hOBkOR2u06k5muD 9GqZkq7Nnupd4xg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Add a Kconfig switch allowing to disable the legacy parts of the GPIO sysfs interface. This means that even though we keep the /sys/class/gpio/ directory, it no longer contains the global export/unexport attribute pair (instead, the user should use the per-chip export/unpexport) nor the gpiochip$BASE entries. This option default to y if GPIO sysfs is enabled but we'll default it to n at some point in the future. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/Kconfig | 8 ++++++++ drivers/gpio/gpiolib-sysfs.c | 42 ++++++++++++++++++++++++++++++++++++++++= ++ 2 files changed, 50 insertions(+) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 44f922e10db2f8dcbdacf79ccd27b0fd9cd93564..d040fdd95ee4b19851057fbedbb= 023f277149c9c 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -69,6 +69,14 @@ config GPIO_SYSFS use the character device /dev/gpiochipN with the appropriate ioctl() operations instead. =20 +config GPIO_SYSFS_LEGACY + bool "Enable legacy functionalities of the sysfs interface" + depends on GPIO_SYSFS + default y if GPIO_SYSFS + help + Say Y here if you want to enable the legacy, global GPIO + numberspace-based functionalities of the sysfs interface. + config GPIO_CDEV bool "Character device (/dev/gpiochipN) support" if EXPERT default y diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 563e38456c33cd3a6e8674485105ef45ce8f5095..f31adc56bef1e215a257eab37ca= 3319c55ef36a6 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -24,6 +24,8 @@ #include "gpiolib.h" #include "gpiolib-sysfs.h" =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) + struct kernfs_node; =20 #define GPIO_IRQF_TRIGGER_NONE 0 @@ -41,6 +43,8 @@ enum { GPIO_SYSFS_LINE_CLASS_ATTR_SIZE, }; =20 +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ + enum { GPIO_SYSFS_LINE_CHIP_ATTR_DIRECTION =3D 0, GPIO_SYSFS_LINE_CHIP_ATTR_VALUE, @@ -55,21 +59,26 @@ struct gpiod_data { struct device *dev; =20 struct mutex mutex; +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct kernfs_node *value_kn; int irq; unsigned char irq_flags; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 bool direction_can_change; =20 struct kobject *parent; struct device_attribute dir_attr; struct device_attribute val_attr; + +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct device_attribute edge_attr; struct device_attribute active_low_attr; =20 struct attribute *class_attrs[GPIO_SYSFS_LINE_CLASS_ATTR_SIZE]; struct attribute_group class_attr_group; const struct attribute_group *class_attr_groups[2]; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 struct attribute *chip_attrs[GPIO_SYSFS_LINE_CHIP_ATTR_SIZE]; struct attribute_group chip_attr_group; @@ -80,7 +89,9 @@ struct gpiodev_data { struct list_head exported_lines; struct gpio_device *gdev; struct device *cdev_id; /* Class device by GPIO device ID */ +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct device *cdev_base; /* Class device by GPIO base */ +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ }; =20 /* @@ -188,6 +199,7 @@ static ssize_t value_store(struct device *dev, struct d= evice_attribute *attr, return size; } =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { struct gpiod_data *data =3D priv; @@ -383,6 +395,7 @@ static ssize_t active_low_store(struct device *dev, =20 return gpio_sysfs_set_active_low(data, value) ?: size; } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *att= r, int n) @@ -397,6 +410,7 @@ static umode_t gpio_is_visible(struct kobject *kobj, st= ruct attribute *attr, =20 if (!data->direction_can_change) mode =3D 0; +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) } else if (strcmp(attr->name, "edge") =3D=3D 0) { data =3D container_of(dev_attr, struct gpiod_data, edge_attr); =20 @@ -406,6 +420,7 @@ static umode_t gpio_is_visible(struct kobject *kobj, st= ruct attribute *attr, if (!data->direction_can_change && test_bit(FLAG_IS_OUT, &data->desc->flags)) mode =3D 0; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ } =20 return mode; @@ -426,6 +441,7 @@ static umode_t gpio_is_visible(struct kobject *kobj, st= ruct attribute *attr, * /ngpio ... matching gpio_chip.ngpio */ =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static ssize_t base_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -434,6 +450,7 @@ static ssize_t base_show(struct device *dev, struct dev= ice_attribute *attr, return sysfs_emit(buf, "%u\n", data->gdev->base); } static DEVICE_ATTR_RO(base); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 static ssize_t label_show(struct device *dev, struct device_attribute *att= r, char *buf) @@ -558,6 +575,7 @@ static struct device_attribute dev_attr_unexport =3D __= ATTR(unexport, 0200, NULL, chip_unexport_store); =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static struct attribute *gpiochip_attrs[] =3D { &dev_attr_base.attr, &dev_attr_label.attr, @@ -565,6 +583,7 @@ static struct attribute *gpiochip_attrs[] =3D { NULL, }; ATTRIBUTE_GROUPS(gpiochip); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 static struct attribute *gpiochip_ext_attrs[] =3D { &dev_attr_label.attr, @@ -575,6 +594,7 @@ static struct attribute *gpiochip_ext_attrs[] =3D { }; ATTRIBUTE_GROUPS(gpiochip_ext); =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) /* * /sys/class/gpio/export ... write-only * integer N ... number of GPIO to export (full access) @@ -639,10 +659,13 @@ static struct attribute *gpio_class_attrs[] =3D { NULL, }; ATTRIBUTE_GROUPS(gpio_class); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 static const struct class gpio_class =3D { .name =3D "gpio", +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) .class_groups =3D gpio_class_groups, +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ }; =20 static int match_gdev(struct device *dev, const void *desc) @@ -754,6 +777,8 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) gpiod_attr_init(&desc_data->dir_attr, "direction", direction_show, direction_store); gpiod_attr_init(&desc_data->val_attr, "value", value_show, value_store); + +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) gpiod_attr_init(&desc_data->edge_attr, "edge", edge_show, edge_store); gpiod_attr_init(&desc_data->active_low_attr, "active_low", active_low_show, active_low_store); @@ -789,6 +814,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) status =3D -ENODEV; goto err_unregister_device; } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 gdev_data =3D gdev_get_data(gdev); if (!gdev_data) { @@ -832,10 +858,12 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) err_free_name: kfree(desc_data->chip_attr_group.name); err_put_dirent: +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) sysfs_put(desc_data->value_kn); err_unregister_device: device_unregister(desc_data->dev); err_free_data: +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ kfree(desc_data); err_clear_bit: clear_bit(FLAG_EXPORT, &desc->flags); @@ -844,12 +872,14 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) } EXPORT_SYMBOL_GPL(gpiod_export); =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static int match_export(struct device *dev, const void *desc) { struct gpiod_data *data =3D dev_get_drvdata(dev); =20 return gpiod_is_equal(data->desc, desc); } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 /** * gpiod_export_link - create a sysfs link to an exported GPIO node @@ -866,6 +896,7 @@ static int match_export(struct device *dev, const void = *desc) int gpiod_export_link(struct device *dev, const char *name, struct gpio_desc *desc) { +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct device *cdev; int ret; =20 @@ -882,6 +913,9 @@ int gpiod_export_link(struct device *dev, const char *n= ame, put_device(cdev); =20 return ret; +#else + return -EOPNOTSUPP; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ } EXPORT_SYMBOL_GPL(gpiod_export_link); =20 @@ -920,6 +954,7 @@ void gpiod_unexport(struct gpio_desc *desc) =20 list_del(&desc_data->list); clear_bit(FLAG_EXPORT, &desc->flags); +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) sysfs_put(desc_data->value_kn); device_unregister(desc_data->dev); =20 @@ -929,6 +964,7 @@ void gpiod_unexport(struct gpio_desc *desc) */ if (desc_data->irq_flags) gpio_sysfs_free_irq(desc_data); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 sysfs_remove_groups(desc_data->parent, desc_data->chip_attr_groups); @@ -979,6 +1015,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) =20 guard(mutex)(&sysfs_lock); =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) /* use chip->base for the ID; it's already known to be unique */ data->cdev_base =3D device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), data, @@ -990,13 +1027,16 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) kfree(data); return err; } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ =20 data->cdev_id =3D device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), data, gpiochip_ext_groups, "chip%d", gdev->id); if (IS_ERR(data->cdev_id)) { +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) device_unregister(data->cdev_base); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ err =3D PTR_ERR(data->cdev_id); kfree(data); return err; @@ -1016,7 +1056,9 @@ void gpiochip_sysfs_unregister(struct gpio_device *gd= ev) if (!data) return; =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) device_unregister(data->cdev_base); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ device_unregister(data->cdev_id); kfree(data); } --=20 2.48.1 From nobody Mon Dec 15 21:27:04 2025 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D3A6D2FC3CB for ; Fri, 4 Jul 2025 12:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633951; cv=none; b=opATA32e949nMdSdn7mXrejZVH59bCWeecCQEow/iDd0PGiQYfwevUDI4FpLrtaUsKhGOC7i6AlqaUGFUXRY7aNvR7jWglQuY8gkw2NNbGx6BqmjVPbv/k9LB2Lp9Jtot8if0hvv1LwJ3TGHV1VW84rx0aqT6etU2/KIZYcCLAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751633951; c=relaxed/simple; bh=x4xWfBZSqqfz/V5ti2RqViVSuu/gEOo2Z1Y+BDm0ySQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ofJwGEmeNoseVYcEHMYvIRNc8W1O57l9TvpOh0ClWMfk6RkOAiKPh4480TEhVEH2uZCKvlbEi2mnULfAyCCk2S//wrhsQAuFWxscS3UW+Jkp+YmdYtsLlIH9dn204zk0q0gL3hzSFJ5DmRDd1VxKKuVAUCe/cVIAWoI8tFMJbc4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=Iexd9i7P; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Iexd9i7P" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-451dbe494d6so10131035e9.1 for ; Fri, 04 Jul 2025 05:59:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751633948; x=1752238748; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=O1S5vg6OWEI5vYVJXplRjZaK0cXCptPKall+ODc6zBI=; b=Iexd9i7P5Hb2gfg7ldPWwiTIDC96dTfslmqZHY+BjdpkDw7q9kqJpEf4D/r+iKA3k0 s0p6/KBj04MwNjFLkyeJMxzv8QlbL9U+bl+p9Ov8fwVG33sA+DtEHO3VuNePf/xSynzW NbJtH/lAjbihWb1k3pL3wckP5tgQ8MrK0Nq/Lpnfms08ccni3iDMPvQXer8+dbXbOAU7 0jY/JcH+mnO3wtS4Iv2PEvKJdcOT+DNsnWIpctPLn8pyi72lUgV6X0zNoD37kCrfvnCD dMz/XpIwXmjkRBof/zUXb0GE0HBYic6zgoVpoxkONA2f3FyJdZPvdJd0lPcFrPSMvSoT 1gsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751633948; x=1752238748; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=O1S5vg6OWEI5vYVJXplRjZaK0cXCptPKall+ODc6zBI=; b=gewcSKe7aL9k6rcfIaNUqhhyeVZLF3g4zxBXyRJNpWrTnE7qsezbAzEmhYKiUNu6XT rws8PMr2IXPserl0psKrl2HHqSsYNnyGX/d01457sdZZHjkNT1RAecqK1FXTGwwOYcvD 5SrDtYwWpNNYW/oWgPAZcNVrQGnY+nm8kTn7orTdelnMxjm5wNk5OU1ddyzw1XMqup/a GFDdRcZv1iHRcNg4oHD1h0Nz31E1HY+4lPRcWPdceQ+0ORDz2nNy7v6U61JIHS6v0gcD 9yvf8CB5UWZh9BY/z9r51L1OmzSYk2bMODirWa3m67055nhSQlOxqx9ok5T1PQhEnaZm foYg== X-Forwarded-Encrypted: i=1; AJvYcCWK/tbvk8lR1qny7eGrGuZH+nltEulsHL1s+MUSlAFRG22SBQNBfU7ihVPZ7cBIEs7jLo60yNlu+lhnfZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YxbRLMNSGDcsg+fKTlo6CvQz/F+Dm12W360r3c+SE2gPx6fjYm3 4yCO0u9oLa6bQnwH7gfv5zDyJG4RpGprCak10rwdtrcGRKQ/RhUlbYmjk1xD7jzfwB8= X-Gm-Gg: ASbGncuUJIZU0gSWdM1cvzrYdky7yNfE5bde8/jAF334ah4CV+searVgiOHACHNXWao Y1uDXH/ZIqAJO2ay797aZgbR9lsASS55t8L2Lu8GC952xHySfdK09eX7+D116JyE7jgTG2UDZoP dA8AK8xef9Ty1R0gU8QfZ1sql4oQSygl2sfj8TnLBey2hnonfLU5o63S+3BK4PSi4/Qdx3ydSRF kip4mEfc79sA1bjeBtLCVB4FbOkRUJiwnBPggnhYl6/N89sDro3BpP1ihXKln1YQLU8zq7PQWf/ t/fdbPwLKL5IoT5LqGJfr3diM2FqrkUw2Ouoh3VxwE5qyz1PLcujupBZ0g08jTdHcA== X-Google-Smtp-Source: AGHT+IHw2SDNQnrLSf6mtAGpuLA0PvMaMpcKRIrXgIkWxcTLslTfhWTRqmBlsbaFprLv6XxZ8AR2Pg== X-Received: by 2002:a05:600c:a4b:b0:453:1e14:6387 with SMTP id 5b1f17b1804b1-454b4ec46d0mr17230335e9.32.1751633948210; Fri, 04 Jul 2025 05:59:08 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:876:27c7:55ac:40ab]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454a9bcebf7sm56129665e9.21.2025.07.04.05.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 05:59:07 -0700 (PDT) From: Bartosz Golaszewski Date: Fri, 04 Jul 2025 14:58:57 +0200 Subject: [PATCH v4 10/10] gpio: TODO: remove the task for the sysfs rework Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250704-gpio-sysfs-chip-export-v4-10-9289d8758243@linaro.org> References: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> In-Reply-To: <20250704-gpio-sysfs-chip-export-v4-0-9289d8758243@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , Andy Shevchenko , Bartosz Golaszewski Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1713; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=hbJzVlaN/lD1PsifIIzsmeGvG4x8/iKN55oce2s//80=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoZ9AMhgzqbaNK9jpMW2hC8Ldf9/XWXB52+g6VM M0T4sNvzo6JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGfQDAAKCRARpy6gFHHX cibOEACqCTqMfX2NBWUAWz7eZ57c2kHYnRvO8kcE6Hx+ww6XJfK0pHuTb8OOCdW7h76LjLsyRSQ a6/C7aorGp9Mo6ICdnmAw2Er2MDdIrHObkjIF0BxtWCxBfXPtJ0CL1vL1robY5oJeg0YYEZAu4J Qa5tmE9PLd8mi2PYIKtqjCz/+dYPwia23OdWihxcHbTjTsmtXOYmhv0AkB9K2W46G6WTm03WrbR ElFjhOoOWt0w9BYZ4CngqoZ6yhyzxdKfiNaFbfeGIhT/6D01MdeiFhqavByMUIyENMWkdqTe8Xc kuDPE2qwHakbs54aB2ODFSLcDCbWJx8iKJtGNMrqUYwxI6QpF/DLW92oEl/FtNMVyNY7CaFggQl gDh6Trb2JfNGA9L2uLLuFzft1cYfRJeH6f9f5iPesJf+NBcUjOI/VEgkSd1uNfli8Sw/q+XKLxZ +4JAxmj+livwF4BHj60w2UNu00fojX3vWI/A7FYHIRn1JAWc/SnJ8qZD2ZQvh7w2Sp9CmQSzNl+ 80Vft5t1fXODZbbk6OnvlmhKJ3iAu6Vz3pO2WD4ZWoGj1lGaciKD8qbrqpaxwR7Tl2oS6wXlJ51 YbOAF4/7T8BvjeL2Io67GqMlUpxNe0pkRGuJF/9FwOQcN5r+j7nnncZbfaVOkb5KJxgs9S38CpW QFJ+2fbt40R1icw== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Remove the completed task tracking the rework of the sysfs interface and add a new task to track the removal of the legacy bits and pieces. Reviewed-by: Linus Walleij Signed-off-by: Bartosz Golaszewski --- drivers/gpio/TODO | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/drivers/gpio/TODO b/drivers/gpio/TODO index ef53892cb44d7c01d100f10f1b805c0aca561b46..7a09a4f58551b51c55938c278a4= 7a04e86ef4106 100644 --- a/drivers/gpio/TODO +++ b/drivers/gpio/TODO @@ -188,16 +188,12 @@ remove the old ones and finally rename the new ones b= ack to the old names. =20 --------------------------------------------------------------------------= ----- =20 -Extend the sysfs ABI to allow exporting lines by their HW offsets +Remove legacy sysfs features =20 -The need to support the sysfs GPIO class is one of the main obstacles to -removing the global GPIO numberspace from the kernel. In order to wean use= rs -off using global numbers from user-space, extend the existing interface wi= th -new per-gpiochip export/unexport attributes that allow to refer to GPIOs u= sing -their hardware offsets within the chip. - -Encourage users to switch to using them and eventually remove the existing -global export/unexport attribues. +We have two parallel per-chip class devices and per-exported-line attribute +groups in sysfs. One is using the obsolete global GPIO numberspace and the +second relies on hardware offsets of pins within the chip. Remove the form= er +once user-space has switched to using the latter. =20 --------------------------------------------------------------------------= ----- =20 --=20 2.48.1