From nobody Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 3F42128A1DE for ; Mon, 30 Jun 2025 12:37:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287044; cv=none; b=Q9UgeZAxishHidHX9XHLXiPOhkYI68gjQxJNc+fDf8Uy4LJJeqW8HxaANICjik0LyiMDi/VJDRBL6aA8FsnExQgTKn6WCEjmOIuCUWfHDracMzIUmioJQvvwJy5HDqJrn3qIWK2tlqxRGWb8+TxFwdD6fGKJnVzFbIdhdu9Xuvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287044; c=relaxed/simple; bh=BAX21BLXdgCjprb8m62SSWkuVvEMGYe3PXLwT9tphzk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eKfP9nWWq90RizI+hi1BGi2rEZRBwL0SoJYqFcG4yQ1WQ2JAF7LkIMSMZvBkxg/glJPZTI8BNGFeVYP5wKqIuPw3XhZN0lGalRn/DbF+5ro62tNVR4dJhI3T72awwdx9nEmYz95SywL+azpX3Z3dKCT4T49V/AhmKfdqMn6/mOw= 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=rJHFP3ad; arc=none smtp.client-ip=209.85.221.53 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="rJHFP3ad" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3a4f72cba73so3445124f8f.1 for ; Mon, 30 Jun 2025 05:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287041; x=1751891841; 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=lJkvj/FldXX6eN7UCXfXzKw4ph+FloS099EL9kd4YCQ=; b=rJHFP3adK8CYAfh6oblPVOKQKRDYdx/FaLD5yKiL8U4qzZSLCtZ9RdfmqpEsPhxv5E lF2T+CSBVj00zL2j7hT3Y3jAyujEf730euBlGyhjQKPyawbvvovN2xVlRBVrG+uTpjqR Cz40p11nFwjcBhHAFZE439swDvAgdcwBxXrSG4HsCsghlSxSd8+tIk6Z0025FWK/7TuQ tRkFno4RsLpAQ1pnZvpMagPQqYA0qfy/XW5F5AqzXrIkx8CQBguI71KF39Tq1Y0c2JyV rvvKXtWhj7/LUY4QppiRwJz4GEB3vz/HG6NlcmnwuiZR+c2pQlyF1eGuj+cmxTxP/0cA /g/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287041; x=1751891841; 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=lJkvj/FldXX6eN7UCXfXzKw4ph+FloS099EL9kd4YCQ=; b=qpCPFjXArQm7LY4wL7v48DRwIenK/UGY06Nvid1c7NykYr3MCnIu+a117vt23vpcSX L6TezSeC3qTpP5G6IRR4MaKc+tieZl8juw0NtCCMDfPokS5xMt3p2UDdhD945ZwrC6yD JGQL/SD4QLt2c2uarlTEyfygOTFy7HGdvPnNOo5r2w1Oh7e0NsZtqzhAbDK0Ayj0YhNh AgMzw1gR1mA+DE39w1KpuCBPv9l1CMQokmvvrBgL7uKF7gkd8UPNNHavgd5IRiVNQpdS 7xdmG6d9UY1EP/YzypImgvAwzmEHS6TTYMgT9WICn+ryQi56HCC+qhb4lCBg5RiZc5it yhZA== X-Forwarded-Encrypted: i=1; AJvYcCWCpMyze7UXrQxMTGAAm1VMUr0ANDW80emMz0QReqfq3u+tCpekl+su5uVpROcwrdgQ+suXGFFITDHzOwo=@vger.kernel.org X-Gm-Message-State: AOJu0YxPYPbCLNJRufgULGaEaGT2HFpKRL7zNObq8DbLSVpTc8dfL8sH 9qgJ4wXC0X6SljuO1FK1i5qrUFOlp2PA2s1Gd0xxALJQnK5VcSCuRJ86CdHZKAX0FtU= X-Gm-Gg: ASbGncv5Eq5Zs7Lxo+vmwoRYV1uuyjUe0QKX3orda3uZPoMeekzOCZDVAR10mQesG8T +VMMXNXwu/cIlkzfAt4d2pxdB9l/qcJ53o5iV1kaoMwLM/DwAc5wRvGlelu6/JOxDvP2D5y50Iq DIJnZNvRyxyOegcesEQgcD3g0Bz4pJDcXTcjE+9FWGGmhcdxaVCWuDmuMNq8SR4UC/dGjZl/im1 3K5/DkXvREAYIz6Ge6JjeKxIDLU5/CB/gFBMicOAsNga4r56fc9fqkiuYd8bbVfRNFI7DjdGCyS dCHg5Abeqj3IIzS1iGyGOYqtX1nUaklIfEux9riglzr4IiHM1IfDfvca X-Google-Smtp-Source: AGHT+IE0F/cqsrvm9WJqsaaoQDoMcHDkIHS46Ew1THqWepGmGlMw+IKBlJmlMtsY7BWR4Midl3nwgA== X-Received: by 2002:a05:6000:40da:b0:3a3:6478:e08 with SMTP id ffacd0b85a97d-3a98c78caf9mr10963556f8f.23.1751287041451; Mon, 30 Jun 2025 05:37:21 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:20 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:08 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-1-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=882; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=5K929j8J+QocufDoF5VRHIwbhKAOdKHaj6roDc6rDQY=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT8JbRZZtjWQbfdmzbkzEz7oqXHnDfpckLtW +9ehyoYIfWJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/AAKCRARpy6gFHHX cmaRD/sFqS2WGuoadny+5iCJLjmF3+iQEvsig2RE284dyKEYayNGEC6a/cGRNcsOFKMlnYHnPO+ Kx4OQBAHJhg2Sjd9DhrB/2zaB+WtXXY6kqnUiYd3vunWq8PNvIHCq/9TgToIyoVf5H4MzSAbQkE hav3Ehw1C7Ls+BSUdpj7NxsdYJayKa1JB9nLCFx8P5+Pu12yvMX3LjO35boX2pfHM0oze2FDys0 BVgjZckiAls4FAr6NVe+b7MmhGCxxA7bM/WdjuLyeNIFig1EI3tIhgtdNSxMsG07AdXf7+IIIXi 8H/fybPfPzl8iVBqXDmV92a3H6KXivbH7r+PeZVjXpGbbbB1aaXunCofcrYiKydPN0EQ98tkLrW Kc0TCt/Idt+h9vkYrAEOMhPt3Aoc8SNt9qmVxVd9am/hS3t+LcV4ch5haTD+lHOzT0dSeGKxZup 5+ePn8EqvMXATC51J5TExTSCW+xKbxBHbo2jBcnwwm+ip9vy9RGvI5sY7/33ZDWh5GMhYphyqss LEp6ThWXhXkiGEozhIjcgrRAUPuonqu8bMXeDfAdJestYcWRfFVuf7b6iejchvx8iquybyBUFP9 EAIVHYvvzfwcpRRgn+ft9CzGgjXsgwPXWAeA+r2X+hTvFdIq+iAd+sbo5Gz0Qn5QFVuSqGPsWR5 YANtlYS6/4y6Zlw== 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 Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- 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 Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.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 5F2BC28A40F for ; Mon, 30 Jun 2025 12:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287046; cv=none; b=JgL/m1MKS82KRcpbNRDoTF6I415RdMRI84lmdSBTNuQBqZxq0xcBbQF/gTSqLF771yl1xSGiNk2HiRMomTYRsvtFyCqskpuxuiCzKpGTX3+m4UcLiiYB/kvixljDa1DUDzHQlG6rKiY1wj5vVCFO5gQYZLpr5kJfaJKPuTVhEoU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287046; c=relaxed/simple; bh=HhG83jFmoV5xdCHkj21aD/0tubc0+blTrTs2HK40gu8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tT5AluYrdDJUqHgXL5NXyLdxkr6RK/GmpqN8m72/S1bO8eYdU80UxBs64B5Ccmzd6Zk56eD/cfH3JgMeKRfe0FnLNmduZa7vT1UscRgqK4ocyyXNxW7U9jHrSIZo/INV+rFOlBKw7cG75NWDCETQAlGTdf5nwIxE8tUOFm1gsnA= 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=GyhDHZt2; arc=none smtp.client-ip=209.85.221.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="GyhDHZt2" Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-3a507e88b0aso1584404f8f.1 for ; Mon, 30 Jun 2025 05:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287043; x=1751891843; 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=GyhDHZt210bfoyRlL3VrQweANBZYwzb2LEZApPJ9Jyahz8ZM/pWFLQnuZN8Dmj6rNR OjIH2H8/yxeGGOQb9bfB25q2mGIsVg9VzGJYfUY/n6f2Mrbi/WVnxtfNTyuhp+vqarH/ L3eTUwBmCWeQVW9zFH2T34wAPb1jnQ216HngOVVMgj/ndfxExbMzu9QI1W/h6W6MalLl 7QuKsYvwMf0GhDVFWplfySvptWpZA9fpbgF/Bi0AM+FHIZ7zejq5i+rUokuiB8B6nPLo RX9+3kGfE5rSbS+DTpnSdL0bvJy2w4ZMeW0tpA6mgTkQty5mIaELh4uLpfPhzoODyHLq S9nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287043; x=1751891843; 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=CdkMb6ahwE4XJlhiQrBx+G2Nhd003KdPIpRyZ9sAmBg/et4adjLNQvT4ZRiyKd3VCk R6sSDLhqTZuj4oiYqMlRFglu91XJEyRBsviuKTIwU4+F5dGpwn6siQgMiIS/tDJM2Ck3 BjBkBjyegEOqD+r0PvHpeJ+fJEXc8T+u5tfp/1NOIgnTI5JCdwCws1faX0pngcrUiYa5 a4pWQGEeiJfjQz0wDGCvHugwY9dk88Uj/4dOjtO1/qsLGKOLk8tH9OCcAY+MXwm4EpYz goQghTzygAvOwo3HJFg+GnjazkT+ha12EOugEjKLZtQtc32rlTI7jUZejnl8CmvT2+ak ZiFw== X-Forwarded-Encrypted: i=1; AJvYcCW6jeBnXIeL+jIP+p1Gi9aXM7z83MauuA+AY4Pvw4OsVyQOfs5joojvmCNz3RqbiyLa4xlvGM/cuj5B7Ec=@vger.kernel.org X-Gm-Message-State: AOJu0YwP88fniWt/HppT5d7FGmIZi9NdJ89aCMjrVmwoJkQ1QWWja2dY N+b9GPjuFUFVPTmWggunG9wPsMDZUTItWBq9yfzOTnj5ksJpq0zq6x5AcMKLbT6Om6Y= X-Gm-Gg: ASbGncuSUWmZBWGBT4NJQW2qf8Adqc9T+qTljKwKK2RWYPnaSynI+hViPetni5oEffM manfjCffCQKTt4UaDpqz/aurb2ZpBlx1zjhlgB0bXVcpp5mraQRWTgEqxhWRHXeReaoTvTppLC1 rU4tHI4ZwpJOOY4IZdLi8UZo672MKGXP4sxLMC0E5BslZMsbobUaBTp4xAXAjInj5Fc+j1ppMDL kboeWyiJur1h4NPfsJVHknzu6Br87Ba8pbQCsaQelH5eBrNYUhw+I4kaMv6k2O05t7YJTPjd60i eEC1qPDQElm1k60DFnF+7pr/YfP/DV8ODQlOTz9PUAyxEE0WnCLKr/X/ X-Google-Smtp-Source: AGHT+IF+yPov1WXgvQWnkfLsinR57y3qTb4t0WeCxrJa8Y7SocBwE9AbliORnizqDHQNwN4Ap8x84g== X-Received: by 2002:adf:b649:0:b0:3a4:dfa9:ce28 with SMTP id ffacd0b85a97d-3a8f4549152mr10743050f8f.5.1751287042643; Mon, 30 Jun 2025 05:37:22 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:22 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:09 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-2-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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/ZANAwAKARGnLqAUcddyAcsmYgBoYoT8zNlPt3WijyL9s04lgnhitIoAxw6Q6ZF7z B7V3fBsAzyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/AAKCRARpy6gFHHX cny9D/4sIMpXxyrrAAiliWCXfPWaunf7lCW9BJ1TPLMbrbfNGvU9hNnLZSmRO0pn41KM6LboSSP fy+81uDj6t8BjbAeBkiPs8mhLfax8axl8L3igbOgJ0pTn4hk+dLJIx+s08NeQPjvwyk/TOhLp9v odEOMjgVi0iIAWF7/0sdMO+vA+XeuPBjm+ZQ9FcuZTqjW1A2wS32mAI24WvNBE8aCayy4JoW4x5 GEWND9kX6kmpa4WtzOp6TAGr3d5PvN6LZpd5zi2e+XL/tl+1lalAkXXD2+nk1DrbjJyS09QUtuN xjy+0RI1iL5D/AupuDg9aqLRwMa3rUf+wOJrGXumytzinljtaQ+KWjUPV2zeaeIoh3y1FnIXgfg tyh0IlJI/n7X/VTv6Zod+MCxU1yn4PUET8p6QYIaNmhb3xNAH6cR9BdJJpCpfdOEXgWuFhaE+jS sDbxOEsBjbjPH1RE7/Kis9dfpccf07ojcY6F9WFdtMXc+3EYfukZeSQnK28XKNArEu+leSHhFqM jX2cuZol/bmHJwSQ65LnsxBc79AUrlYlDofQlWoNBD/lqdaZ9B+lJh5IZxM99vVWhIq2RY8GGOX blExIg6ffEfEERVPGyktQdc9Z+vEmDmP0uJkWYjvpS4wbnxVZC76c9+Oq7ClsbU18hzzq8M2CFx ruyGLvr0C5CCHBQ== 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 Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 5DAA128A723 for ; Mon, 30 Jun 2025 12:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287047; cv=none; b=Z6BwoMp+MCBathfipDytVNu4U3mRskCv3UfZYIVhKtOFkyjb2UyKzdYf0/RM8LH/E5+Ozd32ecKKyaFWZz0PEXDQVFyHCF9UiFA2Po5OuamU/eqsbqqOkPdSEsH7dOuhaiy9JFVCg4iHXBLEEKXNSl+T8LlrUGuQGgQ4oGHnWZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287047; c=relaxed/simple; bh=vSJoeqW/0YSRNvc3L8Rq4FI72ozCDU5AyIHLHoUl5+k=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QyZONmuRgGFgowFMWXm6MKVLWFNq1ZdySns5PbeTorQ14maerQIeTdiRM3SPBDJIvpp8b1JwrJBn/HLUQ9tUvhpxmNfFCM8D88zCmHkCSIq+4Z7oI2dlO2XTKJwjV7WD4HbPWZ6Zl0zjexartaZUmIpMIkHrtj73GEXgbsDlkQk= 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=fOewLP23; arc=none smtp.client-ip=209.85.221.43 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="fOewLP23" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-3a4fd1ba177so2848783f8f.0 for ; Mon, 30 Jun 2025 05:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287044; x=1751891844; 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=NBujJaT2ckR8gXJqLyS4Jh8PI0jBXSRVKotutG8LOQo=; b=fOewLP23liey9saXvmCTzUkwDXBpaPVs2BhwSAgaVX9S7Wbf+v54ZPP/B5V1hf/itN Nz+XPkhgFNuKwF6gBOjmzn+2q0MAx290ccfQd6Kfn+yH1+jX4c9dWMsl6L6FPCsX8490 dUPGnQC4ZuLK0cqzj/kwqnbJysFcYWphqzgJT0eclDeAOspBisZip4i0oQNd+r+d3G7X 5tPxuRN2A20RKw/IZvOyEvpDuZ+bwcMch7iwDtbRJ18s7vbFN4Go9C3ufM+mmrC8KdT9 yEYhLEwIf7qmuxgaD1gDx1edsa+7SAkkGVPlDmBXWvR/I4zeAZh4WiLgNfYnuqONKjLf IZ6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287044; x=1751891844; 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=NBujJaT2ckR8gXJqLyS4Jh8PI0jBXSRVKotutG8LOQo=; b=H2D3hK9JEhbONDVIdgN9voKxweDWc0Uo5TN6Rr6JPhh8jZObNb7V4QvMEhm7JRpWmm cP+ImPwF99PJeA3/KrRGX/mrYdIxiqtRiBFioHO6zIHaqnKRXEUJuj4OF6u6zEEp/GYU hEVVioUM6fnM4mr9RoM7JeUFQYTf2EgL5u6zPN4JPWvKq0DqUVcVot2ge7nmEOJPZp8F dCwTD7Ou2ww6uo1pp9XPEAIgTF6SzN4H8g3b3NNC/Dosd/wl8X0swV4pHd0ZI43pOskx 8pTtUI+bWZpjQbCYRkWU+7Kg0w2m71o01cbLB0TvfqLnzNbTUvayXMNpdbY3pDC8x4qS Eb5A== X-Forwarded-Encrypted: i=1; AJvYcCX+vec9JmaAx9j+IFa/InI6vv0X0Yeth/A3RVe6mzznubfhmMZHMnlpWKW0pWQKjZEHUQlwuXJ36HntB6g=@vger.kernel.org X-Gm-Message-State: AOJu0YzjEu5ONsf8YN5jjxzLYWyjDMHeAiQO5OlZ6MejoKKouamf5h3Y ZSub22oeZffxM1fX9IyT5ipseOme3/rf9UveVUDm5OwZWv9v0lz3lZ2WkqEV2UF/ccU= X-Gm-Gg: ASbGncu+y0b04yIBdOhYFpxuLQN/spXivWg9v13xrZEHv/Tb1PSIkmplQu7jMpX7Qm3 Vk3E+HwqN3GPaiIgb9QnEzskXxoqgsKue+6Yn3wgW8HrCNx0od0u8YqEIrr8P5RCpBAWd19nxB2 6EsKZUIU8tF2il75RS9pYS3bZ2nXbZyK7mjcK9OZOkop2aWkqGW0encgzLH2fPC4jXH2whWmPGe Ag0F1Lxqfcbz8AKSLCERvaJl5VKpl0QSNj992r/UnPYmfkcf8vXVMHn0OlWbcZqeJ2DkM/t3lqD BfXZ8kf9QZyjHBEN9QGVycXIvcPGEyWihTp7/CdyGZK3KIen6GHqEQPo X-Google-Smtp-Source: AGHT+IHglAXB1wnvkqWxyHxMYu72HLDiEZaxm7U9T8x9s8smG5cJzd9yYqNquK1LeDcO80+diHi/Sw== X-Received: by 2002:a05:6000:178d:b0:3a4:f7ae:77c9 with SMTP id ffacd0b85a97d-3a97fcd2905mr10665040f8f.5.1751287043715; Mon, 30 Jun 2025 05:37:23 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:23 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:10 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-3-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=3193; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=Kq4vIpbMDkM9HUAJCvHdAXUcnUau3HDlw/dUGiXf3t8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT9E/maTlsY/nE0aovpxqbzCj3vTAlXvXCR0 v+MhxV/q5SJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/QAKCRARpy6gFHHX cmZfEACgDyaxXOf2YWHa1md8hIOOqEJbcwTKNfix6jO8pX8zMcTpTNt19SJtFcwaonfup4v3aEp mjbLEe6IrHnG/yZNE/NgV1DspecIkzQkO/7Hf+3FI+hSz5GRlORvi+vdfSiSjfnjMzErSbEERnV wPPeX7IE2EwkW8igcQTgktvJQV++RJagEpvcQgEJZeS3VNK0qKzzYDSw6az09DJCnc2Zq8M6I3H pRJGgn6TXHtwfQUWb4RHCtJrjnUKjJFeY67I5SSW68Vr7fYdyDZZN0ly2pzzgCVDWYZ594Q4lE+ jsqGzL46zrYbS6dbT9K2NM/AL/zakLSkRohnsQy16R64Cey801cKbJJOw5OrXJNYuBaePtewPDY zN4Ff199EYwX4xtd99KqYltpkro5azcOfRo7A4cn7wK0VxqU4cMOp/IYdCjmp/Dy0+yqiVRa6VW 3TqbXzg8YOJByzjmq8lniTkh9hks6O4ERzPYVC18lf9Fq5mRqULKhpUWjuAMOxv8jG8KtrquzlV je02XE3eztJzaC1htqSitjgMD/dkzdgsL+F4VsbIKcywXX63DA4zRopcT4zjTxjGtJrTTScMjDN Q4cFfpfXoD1fgO544MIOiJ3JsOJvvdlpelbCCjt1PTfPg6loneXhBddM86NrYgznE+FYU8DL7tf gXx8Cdkz8o5Tq7A== 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. While at it: change the name of the kernfs node field to value_class_node ahead of adding a second one for the chip-local GPIO line value attribute. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 990db0405cc86c42bad61295dc823f970199534e..80bb58c96b9b45ce4e1a4def808= 5d71baa0ce45d 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -36,7 +36,7 @@ struct gpiod_data { struct gpio_desc *desc; =20 struct mutex mutex; - struct kernfs_node *value_kn; + struct kernfs_node *value_class_node; int irq; unsigned char irq_flags; =20 @@ -156,7 +156,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { struct gpiod_data *data =3D priv; =20 - sysfs_notify_dirent(data->value_kn); + sysfs_notify_dirent(data->value_class_node); =20 return IRQ_HANDLED; } @@ -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_class_node =3D sysfs_get_dirent(dev->kobj.sd, "value"); + if (!data->value_class_node) { + 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_class_node); device_unregister(dev); =20 /* --=20 2.48.1 From nobody Sun Feb 8 17:12:22 2026 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 7FD4A28AAFD for ; Mon, 30 Jun 2025 12:37:26 +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=1751287048; cv=none; b=JonV5I7mRHYH4jXVCYcDIp3DrgK2Y+ul2Vdq4DDqwdAGR529dKplJpPD27tb60xQ3kwjjxlqJkTAuWZR38AgcLmNabgw7HWKmv72TJux6czO7QefRmedW6+yXjYn795O+YEXaN7E3QTAu3+aha2uwXwG+aW+bb7v78TIpU2JITs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287048; c=relaxed/simple; bh=cUaenc3rvl0teJ/NowJgsUrKnZg43rV4CQlKHGo5Nbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bzWDesfY9OTLg+bfr6u8PeqAk2KoOaTSwn+p6qGQIkFOplFNSNDL1JRUr5hFfvbFmTvm0haDXqK5HQj+s1/2tbOMQm4RKKh0L1f4qdhtPbj/UvTfFkVhoh5+LOwqw3SU5iJRMvuPHoh8lMIhgiBN/BmbAQYVzwZ3NpFpoJcXCnM= 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=SO1iYkty; 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="SO1iYkty" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-453634d8609so30460255e9.3 for ; Mon, 30 Jun 2025 05:37:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287045; x=1751891845; 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=F9GLowzR6otD4zmMujrvPO89qTOr5wAjt/UHwvcJE1g=; b=SO1iYktyfKAi4kuCnoYfj7iQi54uo+QAi/OLuaX8XzM+2No7aCzbd0NzauqCke1qv6 vDVNhMUtnVPPdb5/RXOUYVK6hzM0/dPDfFnX0AaSNfebGbOPmpqHCBnzjHuomC2gdODd 3gpbw5OZFJLvmSWMSfjpnAE75lrF4ArBTWTW/kJn18IJm3lw9m1p5Ks/IZa+p7OONOed Gw8Xl56lKJU4mcYuYgHJiiw95uL9woIF5NPclT0EeHAUgK6SBszIYhRrY6vlRgOvFnkn xLCWTFZjeaxIOl5ySvisYw8ivDmiCF/VUMBLDFsja6DJafuhX42DGY913uJmoGCddZtH qrjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287045; x=1751891845; 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=F9GLowzR6otD4zmMujrvPO89qTOr5wAjt/UHwvcJE1g=; b=S06m/qdT5GsGqmZWXROCuxYulyT5iHouwL2IOHmo8luhcsCsnvfay9UZjJTdBc26Lr UVrsRg61vVI4BpKPaWhRw9MNviCKkggwxAFz/tL4bAU2GedVZqi4/gfwC40xN5sCetxi sFEuQUAEgBPOQAb8HCvVqX/z33SEG31qoh0qp1e04NRPIrJB7Ov5sSBYh9CMHOv6LOi6 qXoopEkoa6hJxJJxCS1HsZF8xNZBxSWGmiWaDWIM7kFQjWUeBY2QDfzTAuQ6Yom5flX4 4TyjmqDardUL/PA3H0H5Zkwc1aNqJAUuey4xHwzEN9Xhv4agEX+bYEcXrrP7LPD0ng+E CU2Q== X-Forwarded-Encrypted: i=1; AJvYcCV4mwbp2wSKtpp6x3+CQUS9spEqSKNCqZ1UXvFfRHGaxnFyaCZrpo9H6Gj3Ns6RNGfDVRqx1b9vWgaWFII=@vger.kernel.org X-Gm-Message-State: AOJu0Ywdzj1adilZUnd1+Str9W0SXf1Wi6iCN0//qh/wMi1CIuQWBbo1 EasVAZCRjHyg6CqU2JhiHb+Y4rTpcwJ2ackmykMRaDF1bTzXM3jagi1QUaX7Q3WY3SA= X-Gm-Gg: ASbGncv4YzxU7jvf1Mk7a7uiFKjaDOvonNSytQnhpJDoKVrV993QP7/DWJSXPfso1wi vfoHFMx3QKayMsdvMy8a1klUc0EAyPJJFbwKrzEOmsrfIKT0uB+Hf6HK09Txva8b07dS9bUxVZ4 x7srnEP5FETzvBXWFGtC8sPt9S2nXjKwA1ib8RCh7KVqXUgWDl1Y2C9mATp6PlGxsKvS0rYfxmC EVO13nRaRaZS2zXcDMQIPSwfJPvFVSp+ntmBTsNPE4tMYGm4Z9U25Ix6cBbQUft0SDEwLkwVHoj 2PiwUa8aEqwfLOTHJYR9AaqLyuFdxLr1/SrRkjbfkJ5kP5Fg7hPICjJC X-Google-Smtp-Source: AGHT+IHeIscFUoOGPWT6ZviT8ymHKprVMmRN5ZRVeuYCasNZmZbt4cN2gXEocUtjCX/6XT6ra3ECVQ== X-Received: by 2002:a05:6000:2b11:b0:3a4:d0dc:184d with SMTP id ffacd0b85a97d-3a8ffdbefcamr8022219f8f.27.1751287044766; Mon, 30 Jun 2025 05:37:24 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:24 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:11 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-4-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=ms0NUIquAuQ6uIRpaRWEi7RbBvFxHVK11v6RgPGf09k=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT90lCXweh33FmrPJvAtlE/10Ook7ZvIDvUG virgCp7G9aJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/QAKCRARpy6gFHHX cr5NEACUbv07pZaQlQpYhhU+GjzEQaL8DrQ5Uz6q3+ugJ1ijIngNAmOnqQH0biZKjT3GTVzf9tK AsjCxjr6j1WhfMurmhv1vQcx4j84EiS/Web3o8GkBuwXJQRTTqJ9jgS3vojqEdVWvQr+I4ZGaTY voE3lI6RoICo0CJCzU/NarHB+rjLo42jrziXX/l80Wx/UoS/kHxjH8BL5LItsSzIKhvCiVJV56A 1qJlQY9q4SAOB/IwEFdVf2F4OtkFzgd8UZ1+axIyEupU+pBxh5rALS/mnOwcrkFSFUTq6j8xIbP SA7+xYLlH9OA6GM4kZpES+z+pcUQrvcmiRHSMbWTuSPDbld4PmyPKkBSKDdnI86t9lXNlLxVBJf CkK5pi/hxY+hBR02mzV8wYbbnn0W+9pZUNUNZ1MnYZ6H9SD9j7X5iQsgVAsyaJrdEDPumXAv+CE czz3pQdzGXjfQZmLgz47gE5NObViURpwMZ9AGf1Pvwob+KRe5hP2e5/XqaYZ1VICv9KC2WOryTT O2hRqVeFJjYkCThfS/HCS/g3ogre+ZkyP23ZMmovat6eXabehv7CC9d0vs5cAzI4PsEFdiUDVCU bLiayh/K2tuAZOtLNMqqYaiFGWv+bb+ZmX45+OkYE8hq4IB+qt8kGfVU+/InixXyT/wiuD46n0+ uqRy3fOw2HF5pjA== 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 80bb58c96b9b45ce4e1a4def8085d71baa0ce45d..59b66ee222a84b36a05458c8cd6= cfa1d568e6783 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 Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 C39992820DC for ; Mon, 30 Jun 2025 12:37:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287049; cv=none; b=omAOj5h36fx0KVhPFWHXDwX+JvBzKS1J7mhqtzipXpbanejzFtaY4c7UjBtFOd+CYziGAYyHsWdIwd7xgTYf/EWYrB24zj50vYNzMiNygsqrxpIPYlTYelVeprINZRQAZUZX9Dx2Ai8Y2d9gBZ3QVuRO32GourAJI1gvqpXow6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287049; c=relaxed/simple; bh=NJEAN9Al3XjEemr7o+4Pa4oKPW5W/hEOSmrV3Llc/Cc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uo95VCSZHW4m2LAKDUftw1yMC3nnFGiVxiIEYmJdjjfHweOMHG9yqWTOYIi437vVNtJmZpkIKTbHn/tD4D5jcBu+CVMwrKR86jyx6jamzDudus2nP9EcHmWdRi4oBw/PREmrPclbC49fiWdddQ3uBwErmpYI3r8NQJiUfZkEkS8= 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=LeRQsSqU; arc=none smtp.client-ip=209.85.221.53 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="LeRQsSqU" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-3a57ae5cb17so1281953f8f.0 for ; Mon, 30 Jun 2025 05:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287046; x=1751891846; 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=OMK8VVzfoB0W1kbIMTI0Ku045SkeQvw4vKYkz/7sL64=; b=LeRQsSqUnde9xZmfLomcOw7AlcWoId7E+RlhkAVJ/a3dmp8Xr7B9nuDAJbts8anPaB SsxQDnyTP+zxgDYtCWFF0I27TPa1jhclfEWKUQUYAIUpEIdGPbru6Yw4h11nefmWsHRy dEAWIgCb6adgrXcNKj6cy2VX5Ov5zPyelMQNYT6054+/16QlABKpOm5cg/gP5l4qD/Xd 2RepwFvjYoulrAFC9zbf3/G3BTeCi5rAKA8MWfY8R1znF0Buy+gL1cHs/7y3OUNsnXzs UVUhCPbE4hs87xLnhPc19by3NLtKC28fksKzMXr0K31pI0FIWZTHetehPpm3cAYhNfA6 ZHig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287046; x=1751891846; 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=OMK8VVzfoB0W1kbIMTI0Ku045SkeQvw4vKYkz/7sL64=; b=wrzrsbrEp84uePOTRS6hnXohun9GNUwZpCSt83lyxsANk4xfEIMGbHGQIIkpXBvMaa W6XBRMNS7Y6W5E7gz9I46a80SL5ngcpfUhiXr3kR824JConi21jZpZ6iv9W71AWYo2/i fWzLqD4D6Iv6WyIzU9HF03By4G0RlPzryd5fUHxQw4pogA7NdnqZ5y03ZidkjaUC0yEI 77jDWkst6fmrWIaRkYgU/c4tT4fMcYZ8l/EvWt23B2qCBOJcr0SUs58bJtVhY/TlGKV8 0KlIo3W0HAdhD0POX0rsdvfZojjzgQdOuPh1Zvw8L49H8aCG3adpy+XafK+ci8gJU/Zm KEtQ== X-Forwarded-Encrypted: i=1; AJvYcCWk3vJVRQTJ7R7irUZ6lKzT3jI0BT32hKFGAE+ZM1Edt+zY4KB5egrEsqVqPsHmTgxWZycnRHiRG4gl7wg=@vger.kernel.org X-Gm-Message-State: AOJu0YyivEXQOO/Fny+2nAqG/CY6B7YtlybqrHW/4CthcEz53s3ShkNH DhrWT0gNOUe4flieftDxCzb9iVD+771OVX9Oma1nHBPXjABZalt1LcVAmm5V5dPRmMY= X-Gm-Gg: ASbGnctq/jeq8oN9hPdD7Bw2XSMnJFSwW2hDryxgQjgZgEcgwjVeOvyyHE6pyMm0PPj vaISltr2O495LbGYzmMeAmd5kEe65sY1YXn+Tq0ROZewLT8XmREHnq8HTx6Bln0/hkZZYhnBs3Z sZ4RYYyoiUGbRLQ+o1Z3n5BdWsCoVY6mFsNsLHC/JFLynk8Zkxmh1keMXWtOJPOUT58l8qPHgqA VhC0gojseVbvQK0LPddwQJ8rD+lNpo0m28uMCkIWXeIehfJm4KY8xRZZJ2tjnwyumecGfV184xm Iix3e9m4XI8ANafCc43gBdi/mOXksFIjyd+g2e0ZlT0fiEkW60cCVi+A X-Google-Smtp-Source: AGHT+IEQQRsGn1tsNuZ6QZYOQSgf1CNJihzZg9Su9m86hhgZDcgNrjfNcSEBTamy3Cz6TW2216s2uA== X-Received: by 2002:a5d:4a12:0:b0:3a4:eb92:b5eb with SMTP id ffacd0b85a97d-3a8ff8f4ddamr8429903f8f.50.1751287046047; Mon, 30 Jun 2025 05:37:26 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:25 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:12 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-5-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=3528; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=Jj96ppj13/1W5rmHbDNktScNK/XOw2pY9MfzDJyINRM=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT9rg4ulpGk3EMkOyKdkFNILb+RMqPgRci4k +MlCTcrB5yJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/QAKCRARpy6gFHHX cq1tD/4oyfBTSMqAhCTGK5vPL3TU9HQ/9ysX2ZCAwXXPSUYxobejwLtj5tYgrcxyAN6BdbXS9Xm Pze8RQZEkMzks3XIxlaxv1ZJH+xEq0liS31vW4KODvucmjbQsEMjecTIu7+qvcawIYOdK35U3j4 aeSp+1oIdqrkDAjp7IL8IgvihzD6lCnjSFIgdUD5oIdErTuIFJIFde2EBXM7i0TkmZjWD4xKail PDTykVv1QvYKD8i30COb7C+fzjRjj6j8rg5iqUu4OP0H6P0QX0IO9Qt5A3ZHQox+vK7XGvJXBHz wZemopnsY1YF06W3MSpa1mehmF299lHk+pqtk2yyO/MdoRjpto/D+9UuO5nMB+YYTr5YztEZIgC RtFDeAVdpMajaHCYkNd5gPdBvjGtIVsDpV5Nnjlxai5BMTisNt3br2xt+MctxeuVFDimV4JvlS9 ufZLW/T08ktYXNt8yPxFS5jXKxLWybx34YdjaBpQ6HoNKLxaGFQtYH3beSdcGoNyEKOmbdbo2E4 EtvYXDwn4rST4Gro1nLrPoN+Xvm1gmKDZCUrMOSE93yWtgQRQfRPNra3tWxxgNUDpjaWII8crj9 Q0+RtDzzmLxy41n78dFHfqTD9kWZItHBodd99j75rgez7CnD2JhLmBDbcopWcElyQisMDJ332zY I4NjVXiqa1ndaWQ== 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 59b66ee222a84b36a05458c8cd6cfa1d568e6783..dba9dceb5e79db16f466ee40255= c8f646b6b6d15 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_class_node =3D sysfs_get_dirent(dev->kobj.sd, "value"); - if (!data->value_class_node) { + desc_data->value_class_node =3D sysfs_get_dirent(dev->kobj.sd, "value"); + if (!desc_data->value_class_node) { 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_class_node); + sysfs_put(desc_data->value_class_node); 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 Sun Feb 8 17:12:22 2026 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 E425128B7CD for ; Mon, 30 Jun 2025 12:37:28 +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=1751287051; cv=none; b=Adac+qUxmv4Ts/zg9LXeJVF+TAA2NfHm8n+lD2Mk1+Eu6+/CHaD6nmIbzkk5EcFcxxHaQyUxwvkK8mWVX4NN5PuP3tQDVf2pTU0iW5s0x2hHKonMZiuM+hHytAHQKh0CIkj4VQYVZvM1FqhDZF77/960KuFT25byOKvcY/DeE/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287051; c=relaxed/simple; bh=dVhptWyUX31qCV18QbJjEQNflGg+smlFPAVFwZj+iCQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aPVulgcODg1ZepiBaTzH22QgwKWP/RBf8txCL2PXC+PbW06ajxCVoK2rPeWJVC3WSnFHwrWHv82gy9xdgrnchtVOuv680t6ktU/+PktDyNPChtDrFUSEaTdz4j+dZk3+aFlv5SZEIVTlGg+1iZ8aJkrAw2+kEFA+8Ydo0sZBSEk= 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=3gVzq4pk; 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="3gVzq4pk" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-453647147c6so48040155e9.2 for ; Mon, 30 Jun 2025 05:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287047; x=1751891847; 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=imVsZbAQBzDf1SazNgg1aOZFVItNJ6dUg7IELdUFoDw=; b=3gVzq4pko5JNqzs1TgY+w7cZ2ukGP861DHN5TCceIZprvCBO2Rpi6FQurO4QuokMfB Aq8Mj9FeMuVj48UngTb8HVd5mn7L1jfjERHaUdUqNRqS8iNmVhKP8UGUwATQoOiL7pNL M3dWa2zvRB4CCxXYXmheSQNs+dvQiAZnZDQHaSvKy0X2ZYcN4qS8p/o0zLTk8lyLtLjt 8NaC8HtISliSmzTv7cZZFl01Hh6MSufAYhEqzrIETeGrHvw90eSo61zMzo7SK1O6BF2f QZxFMH2s2Napx5ah+plaDYQbTYFn2jQICza7/lI9PE4OkB3BBUjCAouWW+TxqNQAf7ji IVIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287047; x=1751891847; 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=imVsZbAQBzDf1SazNgg1aOZFVItNJ6dUg7IELdUFoDw=; b=kkNOKMOd1jNHl2wK1pyKcsPELjvqzPDjm6Adp7qZWrO659HHyB6cV6753/tmE8piEB O8nROqQBFWCv3aCFQzjLxUIErhpyb4h8soetZKjM/RUSi2gNG09X5RQ5U4iGgjNCRByF fS1F7Fht4r0Rg5932kVZ1HIeyTWDeWHs5KRV1ZTQjjbh2lxue5fta0vBC8KPNGV+TCkb ldg1ZJqlYdrqYAbPWF/24luJzGGSKhFSFtIfWzY2mPEoJMFKhdO4LYTd4RRXTf71KYwH DZ1UX6wXrk0X65trjkCbpU1pL3kMhUqMfx16FGn7+RcuFLJkZsreEmZfbH6iyJfTXFEh 1XLA== X-Forwarded-Encrypted: i=1; AJvYcCWvF9BnoZY7CZB7SjlKvpav/B5D0dYAFrB4UJ2PW3Ph6ObWdxD7ulPkZ9p7yo1iiNLRm21QT59KEn+2ARY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+ova2o+HIMdbKHA7C71vOlklB2hyPhz6mL1WAiK8+Bdh6kD/v A/e4WpvfEaOrgSq5vxLz1gysXQGpxCkOeuQ5GdKi1VqjTBKL0KQeKQe1H2xHvBgDVe0= X-Gm-Gg: ASbGncs9Xm7BuoYCIT/CaHHlfPLA9y9JERfSCktFQg/BRuLoDKxdGgcc6PSF3TlLnHn Mzk3KRvD3sLFkJ4KUZVuVphNz6tqTba+dY+WLRPkq0MH896fI8WIIYuxOwCoz6Sk0DV59aME0a0 TbWdfjVfDXo2pztixJRMPYYgJNBi2HPNNDNwDJgQ0omeaT+8LJMJZQi7G2K6BsNyRbymVcb8CTq hNcFPA+fK96hliwsfadB33mHMz44q1cAJypIgVm4aC4/Azs/81K6wM88gWXc1JgqT0WIa/JN2AF uOWawEfUhWlAqgAYxak79s9GnAL4qJ0GZnreAo+uEg+ZSOaPW4tQuJ9E X-Google-Smtp-Source: AGHT+IFy8BmpnlqFffwzEz5rP8UGbLV8yOnRroXjVD1iAIVS9avXwdHhASRds44KvyfDifpY4wEa4w== X-Received: by 2002:a05:6000:402a:b0:3a5:300d:5e17 with SMTP id ffacd0b85a97d-3a917603734mr11753529f8f.29.1751287047155; Mon, 30 Jun 2025 05:37:27 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:26 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:13 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-6-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=9706; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=Nc7Thy8NzSvpAfuT6mt4NjvezmoUliNEfqX7HBQaQK4=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT9Vrl01mtlYmTmCiQ5Nrdm+1CUdCDUY0MLB CQooHmbpu6JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/QAKCRARpy6gFHHX cn5TEACIjXKqB2x+cELon4IFX0pg0YFRYxd11UsJzkA7Mihr9oTasNh8pSBOpJSkkkphvR+O+/B 4IW/h+DZJ7j3cUBtyPyQytRmsynzry+AXzEcYQGdxlW8UNZSK+Cs5ZiS9aXy/MxoIEViZteSGCF eDuY6PCrX7R2CFzDXKaqDiEWZ6uFi7m8YcKiMoCl/SunfK6jbxbMK0hzHZdp5qh0ImMMbsTjhRU HclLYhnZWV1EBt+lktIA2gHXj3PJJDUpIDR+zy+xzE0xS3qhCWIxZqfMQAEwWby8hdQLB2i/qdH eP25ft3rr9SUqDtPE0J+bv8CW9s8E+lU91unsXfzq91qK94ubH0/794cV9jyXj0GoPkI9JAOIn6 64xlDbVthzB2JEzm/Z2WoCF5ERHzj6GDkUbBbbhqVumpc73T5UtLVV15F4EsopzD1tIxul9DPAu 4sCXO7oJ44t6LDDGb28+av8c3VlTLd1KgfEbm2otikCA8Vpr6z+5VtcmZzQe994sez4mKn4Ah+s dxyMwon1RifyXVEc87wvpgwPz7tyi0tuoivJX5lw5uV3ahe3jhfnw/82FglNSRCRR9y+rsGVUYC LEklLk5cNL2b+2LvE6Qg+nbOn7zAoH4torTrKlBsqqK/f3VQcm2PPMu7WftcR9Qsly0venA8jgN 9a4s7IfpHyIsL4A== 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 | 122 +++++++++++++++++++++++++++++----------= ---- 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index dba9dceb5e79db16f466ee40255c8f646b6b6d15..c1de8846cc4c1fc9e871dfa4a7d= 7a8f287043c7d 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_ATTR_DIRECTION =3D 0, + GPIO_SYSFS_LINE_ATTR_VALUE, + GPIO_SYSFS_LINE_ATTR_EDGE, + GPIO_SYSFS_LINE_ATTR_ACTIVE_LOW, + GPIO_SYSFS_LINE_ATTR_SENTINEL, + GPIO_SYSFS_LINE_ATTR_SIZE, +}; + struct gpiod_data { struct gpio_desc *desc; =20 @@ -41,6 +50,14 @@ 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 *attrs[GPIO_SYSFS_LINE_ATTR_SIZE]; + struct attribute_group attr_group; + const struct attribute_group *attr_groups[2]; }; =20 struct gpiodev_data { @@ -79,7 +96,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 +113,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 +131,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 +152,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 +170,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 +266,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 +282,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 +310,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 +338,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 +353,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 +366,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 +653,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 +688,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 +733,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->attrs; + desc_data->attr_group.is_visible =3D gpio_is_visible; + attrs[GPIO_SYSFS_LINE_ATTR_DIRECTION] =3D &desc_data->dir_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_VALUE] =3D &desc_data->val_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_EDGE] =3D &desc_data->edge_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_ACTIVE_LOW] =3D &desc_data->active_low_attr.at= tr; + + desc_data->attr_group.attrs =3D desc_data->attrs; + desc_data->attr_groups[0] =3D &desc_data->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->attr_groups, "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status =3D PTR_ERR(dev); --=20 2.48.1 From nobody Sun Feb 8 17:12:22 2026 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 0EF2528B7FC for ; Mon, 30 Jun 2025 12:37:29 +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=1751287052; cv=none; b=q7MMUxP7FDA3WMExdwFfcSATqi8tNBShxQUspT+jRRllnrjwiMwK2Ff9P4HpkEwpS0McNe04vf51nw/Yhg6Q6mSNMLZxs1ohLY7vjU+kkv1havazWCsIa71mzryxfBIsDfVYTu68hQN70R6B2Gv8mll2XJXu9EJCgUYW8Xmvmvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287052; c=relaxed/simple; bh=NhLED6KS6iQSEvuMf/1jSR9yRtIa50EjnBWBDOqIhXQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MMdo76xNEZ0iuU+6H2TluDu5ReOlqqQ+4deOxmsc+PGcvZ+ZejHsXvJt0jmpCo+l+Yyjaxx0KHUjk/1qxxEJjTFjk/V5we8DoaqhYrGceV1dvIeVIil+Q3EUPuFS0djmffxcDkzk+QsSU78+TamJ3IcMaZjIuZaJ+c5hNu8nGp4= 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=lawykocl; 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="lawykocl" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4531e146a24so25621855e9.0 for ; Mon, 30 Jun 2025 05:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287048; x=1751891848; 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=ja11BRQ4dxRBQehmAA+JWgfhvIUUWfex9nN3gp7sVB8=; b=lawykoclhLNDWCRcYllSWi5sLbF36wo3hU6QbVDbwuSZtS7TIcfQomG4Raf4O34d20 zTCfBDiDEg3Oix1sOy2L9a6x/+ZDNrEpwPxhui7aiAvM6X9kuWKoHow5qcAiEzL1/KeE 9aXRG0NwH2iZcGkARwr0FYEAST1wlHppU3+24jfhOe4AK140GFwFfZ8tQWH5H4UprvsV eHZvJwg/2vwYDsDu6/AhX1EEFbpbjRB1ThlnBTbskVyVPEX6aYWsgtBl4O3puvPRudp0 eIusVIcHZs4Utgg9G6fekd9ljC6BRKvxMWmsKj0PZPJbdps3FEy4Y+PrdpvNDWAkXpCJ lLuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287048; x=1751891848; 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=ja11BRQ4dxRBQehmAA+JWgfhvIUUWfex9nN3gp7sVB8=; b=j+TYy8c3zgWUeDltwdFTJ7gMoRUbvKU0AJKtfQiYAd05Ex+fYFufAwJTs58UMviyw/ PGLkogF0Pr1eaLHxbpUM4LeJsQ67VOS6HSZD8uJziVVSL1f7Oo/yh+l9pBU8n6rqHStW mn87ZM8mzw/Pf0mjWLegcrNcIqrj70j6r03s9j8qyVL3af+Ds0/SMrmMEQ+fx4P7qQae 65lrEP2+OymnfIrjsNJlY9DqrZlQ1re77/FLPRrKttTdQcCrh3kM9oVGO9m1ftITI6y3 Nagr0vK4s03HfhM56Rk7BacNm8B6bHqHj/4vCeu2vGiaIZeLee1SncgHOBVnpSFJBx2I tHkQ== X-Forwarded-Encrypted: i=1; AJvYcCVqiCqhYZ444Fe8JKPSqMtPnT3mWcNut36PK4dljQu62Udfe9ai1/sEIsb7m3GtDkK1+gBKO5lEp1vz4vc=@vger.kernel.org X-Gm-Message-State: AOJu0Yyiy62D7Mjb7Q4XDIJMBFuYlTcgfW+6V0d9DV9H2pIY1+uYU7uE aLFW0d15STqU+IZC8gHhHxRccwxJIxbmrFEP1tXvFDGvQLP/57HBIIRUaRWW/TzrFbY= X-Gm-Gg: ASbGncuqX6Jynj4bTsX3/37XNH48aOnClAhTAF19MI+87N+c9BMFwXpV9mBdEgOZS9/ gOzJ3jDGz2q9f2qgPF09bco1gdkvlirgXqEXJowQOpP1nvWTdlsksnKYkxGSNgHBNqJVY7d23Wc /cuEpQA9eIbbtVrVaNbRam4e0XbTt6vx8N0Qdd5KHnKVnckgO+lQkzfteCvD8jLI5mNBT2vwGv4 vKVAJA5RQXx4ArLRZ4BG23uJ2DgxixIA3HhbKKJbQSpVv9kEnJzI+b+uKCezYts9sbpUWd0aQX+ VFAY3OGsWzOlyzyeIP2nloJkmNbfD45rggvfG3G3cbSZaXOK0z0ggO+N X-Google-Smtp-Source: AGHT+IEflkpfWSN28PECBxjrq4gDHiZyEw+zm0ocJVWxo0nIFmGDKmXgZgqgR4g1Lh/Pws6bxh0KdQ== X-Received: by 2002:a05:600c:4446:b0:442:e9eb:cb9e with SMTP id 5b1f17b1804b1-4538ee85917mr117313145e9.26.1751287048295; Mon, 30 Jun 2025 05:37:28 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:27 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:14 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-7-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=4757; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=lYevZUYsEbe/Cg8VTtiEwRPXET3KKqPxl76YbS96r5k=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT+BFPrDJM4GofwXtG2+dFIuMwz7n1Uy1tFY x+LXHn9yjeJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/gAKCRARpy6gFHHX ch+VD/4p2b2K/poyiDdOzCogeP03KURsY3W9/hGSGndIjSLT9606IdKgFBLc3Ot9SFz95EFOXeb DMy30KeaLy1pdrstZ0fcg/6OUl9yCIxqXz3WpaxX1lksX/XHvv6xPoytP8Ea8Gl6MBvikrc6M2j aPvfOyq9JQiKWiKRT2Ib2GB2TFs9GqhO76Klzn+oy/Hvc0kG6uN3tWfS1QjkjOJCoy8FoEdbbse M5RfxQ669IfKiIC1RaunmA1DTcbEFYqGSex8/FYXxXBOsqA/p6M9CHNbJwnftexQaitLv61O0hh mdL0crEDTRp7EulNlep3qIYsvMIjI17SLN8/QDaEBgT731TVjzOcNXRzKK2Eoa29lKZUJawKMfH KHFzBegMXS8d1RI7z3k3LTCvHpp6ebFmvy/3aVNoJp5w5Oyln9ka/r+U1zWT1Nz/6RcKQHZ7m8g bWB/CyYHxDV9Kt4sdNp/3ib+uydZKk1QDDQkTbeluARaguvXyIQbTVD1czn7RPTbzMmFkYCNl77 IcJVpzpKhh8CjsBsC65rgRfPP3WMWJJ1mNKdk4m/SINhb+4ZWBi+E+bxXS5UP5puZxjYMtYr9ia oZ7ffEBzNWHi5E83bDKEoBHC2kFX+4ZTVGl2sVk8a7FLtfIYak+kjHMGdMfG8VakttLvk1Gdi0o waBoZInn9mEStnw== 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 c1de8846cc4c1fc9e871dfa4a7d7a8f287043c7d..bd84489ac3cf7a25c4c876af066= 8a14858d7ac34 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_class_node; @@ -61,6 +64,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 */ @@ -686,10 +690,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 ... */ @@ -750,25 +754,40 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) desc_data->attr_group.attrs =3D desc_data->attrs; desc_data->attr_groups[0] =3D &desc_data->attr_group; =20 - dev =3D device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), desc_data, - desc_data->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->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_class_node =3D sysfs_get_dirent(dev->kobj.sd, "value"); + desc_data->value_class_node =3D sysfs_get_dirent(desc_data->dev->kobj.sd, + "value"); if (!desc_data->value_class_node) { 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: @@ -827,8 +846,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__); @@ -839,14 +859,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_class_node); - device_unregister(dev); + device_unregister(desc_data->dev); =20 /* * Release irq after deregistration to prevent race with @@ -856,7 +884,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); } @@ -898,6 +925,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 Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 5C2A028C000 for ; Mon, 30 Jun 2025 12:37:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287053; cv=none; b=YcMW8XJcvCPW1A84U0vGnkk38OfDYgZTFPphj/L7Asaqh0zJCuN0eHgUF5hgDzSxZ7Thm0BbyewO/9bcZ9nYmD2ItVTJgmXIprRJdExSJcdQRYugyaClgjc1tjWMW7rM/WJzNzypwBNQz+KfpJj2bWvm9soICbsQ02ht540uNj4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287053; c=relaxed/simple; bh=eglVm4aXDYM5iHFQM6M76a3TqhcrfnOeaj9qGJtdDLw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KfUsIjvQ4m5fR8KA+mDHYv6/UPnxZOnIOWVkcUj9aKUAIErekKvkoe1Dw7Py3CLsty3bTFVFoWFRT0T10+lcQRqPeSGDlRxeNPVRWrjMv9hbAOXCjDNj/p6sfBX7knHpuLrDCIqnRgb29KrcNQonbRyTwMJDsKDCF4aXg0jQ6Kw= 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=ehzA9TCa; arc=none smtp.client-ip=209.85.221.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="ehzA9TCa" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3a4ef2c2ef3so1873854f8f.2 for ; Mon, 30 Jun 2025 05:37:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287049; x=1751891849; 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=SNk3mglmCXfdk7eF7/NoaZmh6n+n5KqbCwR9GHfo8KA=; b=ehzA9TCaW5JFuzgTcNn8RWwqXQDsBpzE8zqrgmxt4QaRAfqA6EEUNBnwNWIrrJNT94 Hs0bKuzu4Lk7CtSg4yYl4Z3v7+GSc2IHT0L9sxYu0dYX+72Ka/RS/8vH9SkDh6/TIqoF i2jI2pj9odew5SbHd1l0K+gL5PDF+jNyPkA27dlaY5gAPVALFm0Lh9mWALAOnol4zGr1 fyfulKJqAFoX9Voc2xfYWNMczvrr7lhuGUbqltZpuvv1MT2WJNSfKeG0FjLdIarrbA73 Gv1jD5eBNtLvmpYprXEciZKERfEva/CfNLBBDnRsANYNTIJCb9ObwypAQKPrHhR2jBlJ 9rOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287049; x=1751891849; 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=SNk3mglmCXfdk7eF7/NoaZmh6n+n5KqbCwR9GHfo8KA=; b=SUzemGtV7LJ2lo1GcBmbozYbdj1IFYGqBXfmSQiMPlBzpjBJnEiDvG+pEJ9Q04B3h8 be0VygPpPa0JC1oB8POnlw0tnZ9VDF+BlyQOS7NKtmhfha2y/KmlJ2zoORzE+mcUPUj7 h9Ei1VOpw7lSYYcLmSBJtowrTbXOqsC06+qj4Gn1kHJr7MWizvai+N4ekr0aoetgpa2K zamEPdxFlowWr6VOTBPyCBv4kcG4tW8+FXBFTarFdzSp5BlQS2mYwP5VWaU+xXeoXF/g gvd5VbYHQ9ONozVkL1r27sPQIre2LUYVeDuDCj25+Txgcy40UnK1ltQLRfCibc/ED+qT 2ZMA== X-Forwarded-Encrypted: i=1; AJvYcCWXUunnoDzozvDgJiGTg0h3uHQLdqL7/yZV2ncqtNMOGLjXgmf2TJRGyEM5hZfC15rRgqJqbIPmJhZq/bI=@vger.kernel.org X-Gm-Message-State: AOJu0YyDpz7xP327ZMSB4Iqfbl91CMw9pR1sdFEupU/b7VnzHyaod7CY cHhkovDIugNVkQnVvNME9l6kFVZH/952tX9pvFZHZAQ5g16D24xLXw+BOHWFpu44ePc= X-Gm-Gg: ASbGncuwrXu0eMN38dsOZMlNrrJP5wuWHBoYN4tJDzVCMLMULaenvZrp2TN42xkS7s8 4s4Mi/k7GleKcbxPb9OV1HVqZjx46iYbauALtp0sjVkqy4TFz0pQN9Jf2xW39ocXY4T9ec5f5N8 3VNfq0JLHoIcXqmgeCD4xEM+knajl/CCusRjRLX9LDj2OQDadYTfLzeomtT34WGB4pQyGYPArrU y8T1GZx1yJHT6naAg3tlVdgGX06rAsxcwp3v9JKxj6VR9WmlIKHedLjYg+cc5C4y9miv1N6a3+F lIJ5D+Fm7GAgh5qM/ftaHK0dwF7nMoUcx6kKpyS3U7RTh+qSQkTSPwrd X-Google-Smtp-Source: AGHT+IGfucfcpThrHxHNsFB76Hqih9iVpBqlcNZlSBk/8H6FCaHgLxQlqsvBRStKi2zYJmtrF87uIQ== X-Received: by 2002:a05:6000:21c4:b0:3a4:cfbf:5199 with SMTP id ffacd0b85a97d-3a8f435e0c2mr8090824f8f.9.1751287049388; Mon, 30 Jun 2025 05:37:29 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:28 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:15 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-8-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=4298; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ChZzdWc7iMdehLwGGD/dAiyB0Imk7PHH//mUyZ+oln8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT+Kh/tyCRSHlMzMhmFl7fxaQV+8YUorZUKw 76UluVwXwSJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/gAKCRARpy6gFHHX crjXD/4qxn2Ql9TMgPHWHI8Smj5SBVtxQFjQSJOmiqlqZGRfH6Lxijxn6RfqnhbVotUTkFGPfhF HjEXYsSQu1H1lzq/3Q2rHlswniM0Rh13Crmo2oRZjgihrhq9njaC7fb5+pO9bjIyMSyJa8Gwvl8 2jDdoMUY+Tfb3USDT+fxnNAmIcdrt9szVRd3Ebgd+rY6sdn+GLHYt8DPBk8b6+2TiHGzIofSp1u WsgmRi2UqAacK/xrQk/rFf04POGLvZ8c7FKe1xiBflUHuOzMEkXD6P9lNFbHT9cwHqumiM5GKVf 7Fm3gIWig0pGmwbxPuvW4DAxx2UxwnXv8TiDEVI3qgq8/HUjXyGmGqT37wMieHh7FcZJ1CWLEMC hox7YzhZMS4K1ut79HpKmtHNyd9bW6NZfoFMmUVKZpuXAe231532t7iHC+1UURm13fb4zSiBThH QWLuH9Vh4+BtxvSyPwlMhrlTYRkk8Vka0vfkV6DWL5UCFn4h3GYUrPTKqVhoXvknr0U8+a2JHFH vGZnztZRuUGeMLIaLNNeWjFgU4ns8jUlQNcI006rHcDytV1+fiUOdqwV2qw7Mb7+EjzfSiFaHce OvhwL9pUZ9IZmh3nlXHy8gjka0W+jxu54fcclktzhUrrGPbmOq0ZQj4sRyKoocE5WPUTsEVOrg0 QuDV+Or7wu/EDeg== 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. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- Documentation/ABI/obsolete/sysfs-gpio | 5 +++++ drivers/gpio/gpiolib-sysfs.c | 40 +++++++++++++++++++++++++++++++= +++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obso= lete/sysfs-gpio index ff694708a3bef787afa42dedf94faf209c44dbf0..c0bb51412a912cefe032c4e8428= 8f99754acb1b5 100644 --- a/Documentation/ABI/obsolete/sysfs-gpio +++ b/Documentation/ABI/obsolete/sysfs-gpio @@ -27,6 +27,11 @@ 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 + /edge ... r/w as: none, falling, rising, both + /active-low ... r/w as: 0, 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 diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index bd84489ac3cf7a25c4c876af0668a14858d7ac34..5b8ea601a3ddf0c8442589db8b1= 111ecb26e1221 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -49,11 +49,13 @@ struct gpiod_data { =20 struct mutex mutex; struct kernfs_node *value_class_node; + struct kernfs_node *value_chip_node; int irq; unsigned char irq_flags; =20 bool direction_can_change; =20 + struct kobject *parent; struct device_attribute dir_attr; struct device_attribute val_attr; struct device_attribute edge_attr; @@ -180,6 +182,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) struct gpiod_data *data =3D priv; =20 sysfs_notify_dirent(data->value_class_node); + kernfs_notify(data->value_chip_node); =20 return IRQ_HANDLED; } @@ -690,6 +693,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; @@ -779,13 +783,45 @@ 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; } =20 list_add(&desc_data->list, &gdev_data->exported_lines); =20 + desc_data->attr_group.name =3D kasprintf(GFP_KERNEL, "gpio%u", + gpio_chip_hwgpio(desc)); + if (!desc_data->attr_group.name) { + status =3D -ENOMEM; + goto err_put_dirent; + } + + desc_data->parent =3D &gdev_data->cdev_id->kobj; + status =3D sysfs_create_groups(desc_data->parent, + desc_data->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; + } + + desc_data->value_chip_node =3D kernfs_walk_and_get(desc_data->parent->sd, + path); + if (!desc_data->value_chip_node) { + status =3D -ENODEV; + goto err_remove_groups; + } + return 0; =20 +err_remove_groups: + sysfs_remove_groups(desc_data->parent, desc_data->attr_groups); +err_free_name: + kfree(desc_data->attr_group.name); +err_put_dirent: + sysfs_put(desc_data->value_class_node); err_unregister_device: device_unregister(desc_data->dev); err_free_data: @@ -875,6 +911,8 @@ void gpiod_unexport(struct gpio_desc *desc) clear_bit(FLAG_EXPORT, &desc->flags); sysfs_put(desc_data->value_class_node); device_unregister(desc_data->dev); + sysfs_remove_groups(desc_data->parent, desc_data->attr_groups); + kernfs_put(desc_data->value_chip_node); =20 /* * Release irq after deregistration to prevent race with --=20 2.48.1 From nobody Sun Feb 8 17:12:22 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 3909C28C02C for ; Mon, 30 Jun 2025 12:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287054; cv=none; b=Op0sNF73WhSr8qp5VSJjZKWiwWkNKix+7pUC+rbf5WlkVJSkLy07dwtPU3nXIPyhSjCMaNUEOvqCHizAQYB2aygobk1WZeLFRS+N2DBi3nJ8dz8EYC5oXkmjjrJrEJ06SSLW89dW5EtZKQy8RzQby6bKMNJQmOE9kHB5HmIkq4g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287054; c=relaxed/simple; bh=23b6/Z3jpUPlARZhu1s+kq1yhUnFkH81V7+LRTqVNVo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qIk+jRp7u3UwR4mkAicNVlcDEV5nxf7gvFqM6N6p337+Y/jyVzAuetLSoVVGhzGtfR/EIMij/WVDDFo4sUvBSZwG8IUJyCj1dPQk+VkRWH2ofMpCPIxlNnRe0BShRrwPMP9PafP5e9vFHsQX+1+GxUMklrxvHDCtwQIoiCTsAZE= 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=agixqt5S; arc=none smtp.client-ip=209.85.221.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="agixqt5S" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-3a4e742dc97so3404657f8f.0 for ; Mon, 30 Jun 2025 05:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287051; x=1751891851; 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=AdWAQt+95IqdYcYPGNehzGVHC2x2ZtKPSDdNvNq4Rzc=; b=agixqt5S8oylIvHVO8idwMerMOqv7dSylO1Ce+UBei2IvIBN2THcs8UhqeOpmR2Oon DN+kCxBNviBKz6jhHTTDIvhRdOWggyt0W3NX05mzC3sKCKFpuXq0ebt2e27yC6Fs2Wcu qXKERWA95gPM4LMZnrb8rk3C/Z4sYCoOu0x2VkJdX3yAlt78DJ4YsDn3RFkovFK7S9Qk /TOkwTPHzjoTp4ewYjjzmK1SxMWavmHZqgZE0lMpb1LDSgl4ej6ecdEfmt1jEa0hKMIX 6Pwg7NDmuLyZxaQzFos8RUJWPxecE/3lj1Uc69HoA2/cx36fS3pvu4iPRlbMjDo2jkB6 xJzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287051; x=1751891851; 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=AdWAQt+95IqdYcYPGNehzGVHC2x2ZtKPSDdNvNq4Rzc=; b=PfmvLg+WfHr+V78yaCcF83n3CPHQg0KcY/06tbRsVXW+06uDfsaApel8VMeloyFOuo pm7WYqnYSrC53H/mCXId13LOHEwEycLjin+oAoqZowjzy4ZeXVpIwINjtHahypE7/QZX HUcA0s7PEKfheJj5svMGVtYpXqetEQMkOEgkbdeWERhuIJ1nnHS7Bcf+i4eITL4bqJk9 mMmvc4aC0ElBd7nvtEyUf0itxaUonRHxV3+znOcmpbzkj0aFCUOJHkAG9NDhMcUwm6E0 MhpG/CwerxJop5Zz4zAgq5w3FJkjCN9WnDHy2v0aLOMFvcmpQ064O7TsFJHnW6AUnjxp 6vkQ== X-Forwarded-Encrypted: i=1; AJvYcCWMBGAMWcAjBKVAN/mYiDqT+3X/JxzGqDGJg1uFVdf8oy8KxC60fqzB2AvAc6RtTGqj61ITH775IoGzcZ4=@vger.kernel.org X-Gm-Message-State: AOJu0YyamMIgfJvg7WgXEDNQz4nfYhJh7RWdXRiX+rdw5MqQ6+lUfdiA Xt0NrLz39IJ4zdwRVwkRkdN1fs4ZLu5lW4s/gAu3m6xyp7rQFuiBSIPWX3LuqJ6qfNI= X-Gm-Gg: ASbGncsAvZoO3mgOXir6OI2GiX2/sBXUUPwWJSClJ5mZthU0aFV8EmUbU/i87Zy1sII 0+9d1X2BTI5IfYhBsqRBJhH3edL2Rsc6zH1KlYn0nVW1LgIehccjwVjeoVISJ5PRy8ORweKYFsO tV3PBxL3nGWSnF8V7r/Hc1XhY0qSAQcXdL+hpcapD/6+6787GaiiC2rqp1ug/glssov4k75TcEo KVQlxKpI2ZUyKr7JbyY9jU6+De/brq/D3XJQyHA2Wnil9PQja7i2EG/vrz5PSz+hzwK9JG4dXZs x7uqx5bMwP49G2rFeB3671fiUQqN/Q3NIJooJE7/b7OPgMYvRRSWoop7 X-Google-Smtp-Source: AGHT+IF7Z7Hj0aUDxS5KQh9zw1ZXHBJyFQadgAf4SpY9yn87LESuKIOO0c5PTEb5IXYDDK0jov4N2w== X-Received: by 2002:a5d:64c7:0:b0:3a4:eee4:cdec with SMTP id ffacd0b85a97d-3a6f30fc1d7mr12913861f8f.6.1751287050599; Mon, 30 Jun 2025 05:37:30 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:29 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:16 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-9-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=8085; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=9hvB6qNzFbQWyGdxmQdVykCyMJnqCezngFxsVt2KrAc=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT+D6KsRSlzSE5FBFO0IopkSmEtskOdSw8mC 2cpQB6EoiSJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/gAKCRARpy6gFHHX cgtrEADSpM8n3BF7tT9RoyrQaPzRlrw7xPZ1THM3ExegvocRqZjddo6SzIiIMxMceN1haJVD8Sm bbnISjFSmQf2o99RX5dsU3GamUViEHrfZVQHl82JjXr3r7CMy2tM+THdlzEQOv4RuxlNJuVSQkj skLHDa6ox0d+aAlfwUuB+GSQ3P5F3HMHNWn8ESVsq+hi0CbHi4d7RAe5w2X2NZwtyZNUD1mg/Ur Pcw+IpEmJNjUaqHaGUjt699T7cMNCvpNHGs09VX6M7urlppzuuaYsI8J09tBkKqJ7jRHv/YbkpB 8+Y+C1M4wFNY545Bj4g7QXYl54n9e5GTTguhhzRmTbuVBybkwuXzF9gaNBJ2irdzH3PSA3dFSo8 APpdmU9QBMYOrTdsspvtFjZo72xBE+oc/RHLBEG3rmVR9KUEbhcaNWO/+IPlksHAJO5B5AMqVzq 4fmi1SPJOnllq7gF0LvwHva1mhtYSj166qV1HTdyhtwb2szBh97LZ+CwyH0pHTBupSn3NZ91nwe aQPwtdjA3WVhdimuq+LuVb9foqedAwmxiRWf3AfgykcMa6lAnG1huWRSaffwePoM/Qh9TfW9M2u CR98EoIckw6kmojWE8dpaKWOL4HSnl1eZH6FfZdZYtGiP595ygfLjYaWmEPsa4CFtESpNT7MW8R nO2hcd+EoxMCtGw== 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 | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 40 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 5b8ea601a3ddf0c8442589db8b1111ecb26e1221..d33fd7eeb82b2dc69861c4fc896= 13380df7efeea 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -48,7 +48,9 @@ struct gpiod_data { struct device *dev; =20 struct mutex mutex; +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct kernfs_node *value_class_node; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ struct kernfs_node *value_chip_node; int irq; unsigned char irq_flags; @@ -69,7 +71,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 /* @@ -181,7 +185,9 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { struct gpiod_data *data =3D priv; =20 +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) sysfs_notify_dirent(data->value_class_node); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ kernfs_notify(data->value_chip_node); =20 return IRQ_HANDLED; @@ -416,6 +422,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) { @@ -424,6 +431,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) @@ -548,6 +556,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, @@ -555,6 +564,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, @@ -565,6 +575,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) @@ -629,10 +640,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) @@ -763,6 +777,7 @@ int gpiod_export(struct gpio_desc *desc, bool direction= _may_change) * at least one known user of gpiod_export_link() in the tree. This * function still uses class_find_device() internally. */ +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) desc_data->dev =3D device_create_with_groups(&gpio_class, &gdev->dev, MKDEV(0, 0), desc_data, desc_data->attr_groups, @@ -779,6 +794,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) { @@ -821,10 +837,12 @@ int gpiod_export(struct gpio_desc *desc, bool directi= on_may_change) err_free_name: kfree(desc_data->attr_group.name); err_put_dirent: +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) sysfs_put(desc_data->value_class_node); 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); @@ -833,12 +851,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 @@ -855,6 +875,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 @@ -871,6 +892,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 @@ -909,8 +933,10 @@ 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_class_node); device_unregister(desc_data->dev); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ sysfs_remove_groups(desc_data->parent, desc_data->attr_groups); kernfs_put(desc_data->value_chip_node); =20 @@ -967,6 +993,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, @@ -978,13 +1005,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; @@ -1004,7 +1034,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 Sun Feb 8 17:12:22 2026 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 8460228C2BF for ; Mon, 30 Jun 2025 12:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287055; cv=none; b=uH5x1273S7TNNTSaKKO5etfI+bPkqLZly19IaDfF58how/GyF3sWv92gViWMuCsNLHwYHEvPSifDaBwtgjGlbGQMcNwdTDScrWe3FTQSNJTRrhsVC06WQrClmUNji/gBOrEzOcbwmKp80Akt+y+Dt3leYqZMOv31T7AXQVDXFcQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751287055; c=relaxed/simple; bh=qKH/Xx/gFP86G5ibgMZ3u7lxWPymmr9dQIqXb3a5NY0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bz8GLKNND3qwq4YspZNLewVvKa5koFcV7F672XwOVpCb3rMepvBhL2tETV2bEfZHefgm5/i9WwB2IOo8/3YSXcNMmPG9yllJVe3g/d/45pAkL93n0bAZX5CBmrcl4to01ilgDryp50UVi4T/CZ5JbEQ3AFl0rsa9OPBA5o4GyYM= 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=SUurTdlm; arc=none smtp.client-ip=209.85.128.52 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="SUurTdlm" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-453749aef9eso15535815e9.3 for ; Mon, 30 Jun 2025 05:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1751287052; x=1751891852; 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=Tm+AP9yf/4s1zahGdn4RMNsFWWCbX0hdSX+OspH82js=; b=SUurTdlmaJjfBsFQaeHjC8gq7c/ln5p/jSHcl3ddJvdvbkjr9GOGGcqtBNlatEfpLf cVdIiD8fPmsT+9JG9EOUnqEYYvWdoL3V4Q9UVxYNgf+qb/uFXSCv0GdRFi3pDA6Ymxz3 zbBdXKdF+8fOyI8Fbs+7qDlpulq91lqfLBkGD9Wu7skIySXmE2gHLTA0IcWWT/2wugAC h5U9xX65XXDhUser2WZWTB5kJPkDA+JPXbZAYmMk7C0vCBViUeL+RcyT8IZd7rKottQa MM2Zzf9f33YrS+EMZzbl1bRp0VL5hsm8d0pUatLNBBS97sf+vLVRt37HpkWH7C13C/aY OaSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751287052; x=1751891852; 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=Tm+AP9yf/4s1zahGdn4RMNsFWWCbX0hdSX+OspH82js=; b=m4ubP/u3gXfoCPNM+xaQSl2XJYwRXwIJhSSpKIl9KG8nkIfGFJNBhBwSAEIo6D82CX 6iKSrDU1SVxUFeEMDpiiwQYr7Fw/bBlGkQXRYSYXW+Yb9z8usLJUVKZmtdWRZkmh3cDL j0kDRwwN+oGiVN5rvk6UKWvN6a/DasJpNdUPAQYEkE9hQ19VUWiKhIE1WEo54VbZwZ/d CdK79SroUGVSNIyiIni1aFBZNtXPlY4hpbMuZMkk/zTV5toTruboxl/PbX1JxKJBJ4Gz v4muuoKeszhWVUcpIxYXyu0mrGx1Z4z5lIFJUGJEvYhE5+um+7rqiMNeM3iPVAXuQmNa 0FQQ== X-Forwarded-Encrypted: i=1; AJvYcCV0foHKvSFNXH53S1sTZ6xQ4qN/YuEMgmGxCOFE38b+r8bB7IGUvkI8D7Qx+5QZTikJZjOT9nd2SYPWK0U=@vger.kernel.org X-Gm-Message-State: AOJu0YzfNj5bDlg76+0sOxV9pUDgpLGF+12NCDnqAwF3MJzQc2mAZZon uR7lSWE+Ll8SjIsquLe5Eu9vf9ETgzGfGrUpshTfiC8JMhZ9x4BxuEX8NuqrGjA3xjo= X-Gm-Gg: ASbGncvhwb8gv9xPIR/XsrC8cnZui3URLEo9dH82iHDKzDHJ4kMT0dKyJsZOJ+pzxQg KYbCqamK95eB1of5Kei5Mm7qwKJOT9o2WVydcxS1LR0QBdj3KhCVP5dtiDZuMQHNJ/xK41EhcNb jPWFkMcm3OMk2z664gln2mwqC41g+sDzcFqZtsx5zgHnFfC8foI5cpUXEt/bj+nQgZVVQPIzgUp +TR1DM6q7owSnAVtkrGIEnlVvNEmT0YqPDDV3tEddsKLNzQqHAhVaygci7WKPpbBh890Pr8TV/a Pi/zlOjlS7dRCbp6B5rGZh4NGhcsXN+xv8uNsL6EDT+mY9YV8zRa69YY X-Google-Smtp-Source: AGHT+IEdVt31nj+P++csUDxqjuagbEh5ULVO4D3+RMjfhmemFzD9hX4NJb0J2PaR7MVDdJHgA5O3JA== X-Received: by 2002:adf:e007:0:b0:3a4:f55a:4ae2 with SMTP id ffacd0b85a97d-3a9014bb92emr8982583f8f.50.1751287051637; Mon, 30 Jun 2025 05:37:31 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:19e3:6e9c:f7cd:ff6a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a88c7fa2a7sm10238192f8f.21.2025.06.30.05.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Jun 2025 05:37:31 -0700 (PDT) From: Bartosz Golaszewski Date: Mon, 30 Jun 2025 14:37:17 +0200 Subject: [PATCH v3 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: <20250630-gpio-sysfs-chip-export-v3-10-b997be9b7137@linaro.org> References: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@linaro.org> In-Reply-To: <20250630-gpio-sysfs-chip-export-v3-0-b997be9b7137@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=1371; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=F4uLYTcDjYHCQKRyv318429+cTJ5TfubDfqP7y0o1W8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoYoT/m2wkA9V8TfStoUWd68mbhltDznQO6A7er E4fseJxa4WJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaGKE/wAKCRARpy6gFHHX cuhPD/kB83m2s6pNRR1PsJWHQ9BqzEv0Ac0JcnFNcB1PlAZu0GRcIUZDdLUGlnysVsl7FbMu0fQ hNG0m4AVpLj4DTxL3NuQy7zp26fhyGPXV9EbF9Ix1uzwPLJttB61ZAM55UdWXQDtpx0i6s0CZak 9oXDOblTPkTC0EtGrIjEfFIPfvXSHzYypAMntPcG6HzbCCPqzR+h+IxYaGDI/espshbADclK0Sx Wy5sSj+n6Nx91MbrYS9hTKaszydfbqZmiBbUr+G+N20pKt28OJJWrKQvaRxH20Kzcf99wPNC5zM jRLKoGyu9vAB8+N6axUml+ofIvCgRoHxfZ71gICWRIWlcE5qIr3rAy3XJrXMTqVmJe0t/fxhcop iUbEHXExcAVvxVrAJ9KZOEEt921L2KOI6iVbsWlEaydpvSLrdAt7KXZvsi0AtHcH03sNJfIjL2J 2qwXCiacm9+JYAjjlhjqyZQEL1qKdhKexSQliR1EeNHmPI5yzADHPFIzdylG8ZIrvj9uW8fKHk1 B5pS+l61XXQeSs5JcDVKooqff5RvfT96onwX/dsILpkHybdjajWuJsLxSV55zj3sCjwbwQkGMFm DayRQO/XObUexmv2r4AHgJrH+C2SI9P2pTEbpvPDQP2LfRwUZccJ1VEn6OLbXH4OJuqL8e8JujV 4790VcjfuWcyy1A== 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. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/TODO | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/gpio/TODO b/drivers/gpio/TODO index ef53892cb44d7c01d100f10f1b805c0aca561b46..a6380e51699cc5704aebefbda90= 6762fa60cfef3 100644 --- a/drivers/gpio/TODO +++ b/drivers/gpio/TODO @@ -188,19 +188,6 @@ remove the old ones and finally rename the new ones ba= ck to the old names. =20 --------------------------------------------------------------------------= ----- =20 -Extend the sysfs ABI to allow exporting lines by their HW offsets - -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. - ---------------------------------------------------------------------------= ----- - Remove GPIOD_FLAGS_BIT_NONEXCLUSIVE =20 GPIOs in the linux kernel are meant to be an exclusive resource. This means --=20 2.48.1