From patchwork Tue Jun 10 14:38:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895362 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.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 555541A4E70 for ; Tue, 10 Jun 2025 14:38:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566313; cv=none; b=HfWw6tpncRuzIKbRJihualJ91jC5CZ9l3dlBGKEoIZWSoVsfiVsY1Wz02UC821QDfjXlLfj4rUPk99ypM461r3PWvo+B8FyodMc2xSRAh2vggUurszADysvKXtmbegqP1ySoWc9iwiQIiJ1GtmzFSuycGV32wMFVlj1ic2OwYU4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566313; c=relaxed/simple; bh=K0a4sQIijNrwuXNNNxuWxoMUfCBVUYiHrw1VRd7Sx9c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S8vKsNmtZGvfohC9lhj9MNhBIGySC+8Rf7hh525ENuqcrOrEkGUdenVDC8ute2rxnEUGBA2ln6Y06l7pzqRljKl3sDKgKF+6cXjO5U9xXQOHuMHEvWWg1hebbF3PGgxvjm6CNomaSO0ZJDO7mmbonMhJvK0b2I9aj7TaBPm71I8= 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=2v2+jGi7; arc=none smtp.client-ip=209.85.128.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="2v2+jGi7" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-43edecbfb46so46644245e9.0 for ; Tue, 10 Jun 2025 07:38:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566308; x=1750171108; 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=npwAzi3ntbFCWvxDilBFPXXBoRhcu7pjhvuvWorGBsI=; b=2v2+jGi7jo+PCnSQxUI2yYW3khw+nPZ+FiH2jPvBxDLtdpmPGTf7mLsXKaehTZNDGd oyPAoiJ4IJb3tc/AjlRxPXpLNNWnyQQpV8vidSSBhOtCMTgxAhRocH+d1SQtWKbzip7q AXvl2YTFwFx+rGgBGE8p+CDHhyuQ5yqonSSh+rA+P9ACJSQ9jv3H91i4+UF9eub5tBHg uEBIzLoA25ZNzXdUnlqcwhxTgC9MLE7L4ILZf/51CqgGVN1DRkOt+5nw2axEcbEp7z4t 1mQyJ05L206ZxDe1jaNIjzsipIIGRwx2DPCkmAzZLpJmF3j6//kRmrbi7yXX8wHz3gJ7 gRUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566308; x=1750171108; 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=npwAzi3ntbFCWvxDilBFPXXBoRhcu7pjhvuvWorGBsI=; b=LtrlMUdLf7c8yfr5nRJOTLxJQDXSv1IkYgnJqUkHaSVEKIO7/fIefvwTsYs7Dl3mjp BCW76xyuSb/ece5PNuXBu8mqOtURYvqNkcl01MSYb7BAyXh3p15V5Hr7CrlqPtMtv+Ny 0ZzIQGppNsaWPJAMxe2LMmQ6FbyaqJugTo/bTBiLok3E53ZwjO7fWypD0KKLmFJsbkcW +tBJiIE8M1Hkacs14PPVxi24Q/FN7qcMXBXoaNENMPM+tDPgW3r/qYJJiXE6sQcUXr4N 8ZLab5DxIdNb6NgA40ZEs34hAymIiwuD+J4X43vgVcbBjDMm3uJU8HYooDD20Wdk0WGh HymA== X-Gm-Message-State: AOJu0Yzgy64pPSgVJBDv22BMxK8yd/922rukqTosyYxm2g4t4ZYoPkgt THFvgV33+U4oBtPs2b8mqjSfw0pu3GdA8rdiaX4oTdTjof2319bGuHIRg2FNozmrEjw= X-Gm-Gg: ASbGnctZGFRMcs2HJPbRTxcS2mh/FMzQnUieaykNMKY0YrIar3NGoRYiftiUV1yV48Z z/utyJsNcO2TEkdgfO6L/hzt48OzyNhW/WxBiVzq0noI+ZtbJQE3Lp/N5StDVOoh3PSc/eVRgC7 uuYc0QmWesXQCdDbPnTKYK+Zma8WS5jOz+N7yX4AauvvQSP2mmBKRF/9KsP0n4xVSwi1hOONP3A 8uvX4JRLNvNHuL1ykFjSCdFDbiHLvn7Sjvatu9K26KrtQ4+FGZBW+4RwXjsEDNa/EKc0Mh3NLqi A+HNdq6ZZMFcTwj9VNj/qjCzsCUj9P2vpQJ1mB81p/95gSDLam// X-Google-Smtp-Source: AGHT+IHADwDUiowP1VqDn6bHTYazy1fJaU3+WvOB375z0PSS7WCTUy/V3eQbQBUDjfOKEmlrRO24Mw== X-Received: by 2002:a05:600c:46ca:b0:442:ccfa:18c with SMTP id 5b1f17b1804b1-45201426873mr133231485e9.32.1749566308472; Tue, 10 Jun 2025 07:38:28 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:28 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:16 +0200 Subject: [PATCH RFC/RFT 01/15] Documentation: gpio: undocument removed behavior Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-1-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=1083; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=THG/Fz9qHVr/JyTG5u6I/vfSnnEbM8AweVBXQl5IyE8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENfkjw1VZTrSh4NbqOsxZmL9+q/ZIF6oWn4O g43+cfrquOJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDXwAKCRARpy6gFHHX ctNYEACf6nlZ8E6yIMGUwH4HSRiL+mQ6qLM4ech26E65ZPzzO6TcQSFgPesQjtKX80XnB/ZPaq8 VC7BrxymFJQaf8XjCx5UNDuM+m/KWJaoHleNY7ZlgrIgAkxRT8UVFXv6gBgyp0BK+7rVAowS92X L39gKBaeZQOVA5vLzsITNEYwEFLIigzjayfyIEec3FcNRTlW/1TkNHdt94P0cU2rT9tREhUSwNu z49YUYQr8LYrp2C+zlhARIMfDtE9yzcL5Ty9HpacAguopewUkc5pE31QlpMAE90x7kTJJrUExib 4DTiUZk49ymupXD/9dcf5BefJNgLckOJlD7HUh7V13xbhbJVuuQNbqfh5HVaMz+XhmHM1TBsy3l rJ2Tsb/8+DjHitGqKtCkG2uZLgY/A4kltzcdp5bBAqfTJ/f8u8Ub9alnnsgj+U6ibdENWGyRaG1 3qLg9WrXSy1Z/kdc/+QQqcsMJl5paszD+bEkH7IeggotB7iyI41s48JZyNvn4SfaQ9891JPOzqQ frF2ElHMomPSVIHFx7CkxgcdcKiA6eiDfBijisVXzXy42+AAGSL0iB7Azd8Gpxj62z83oHLM5Um qUFxBb4zEPACFKgnVx6atHw+zI4EePC5lKdx6KO6VjRI1nd8cIuwtcXtm9Xm4HMXfcwoZ+dxrKb nWUmrEVoy6yjbZQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Since commit 700cdf7ed00f ("gpio: sysfs: make the sysfs export behavior consistent"), named GPIO lines are no longer exported in sysfs as links named after the them. Drop the misleading bit from the ABI docs. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- Documentation/ABI/obsolete/sysfs-gpio | 1 - 1 file changed, 1 deletion(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obsolete/sysfs-gpio index da1345d854b4ad40ddd99af090597574fbc07565..8203bc2128db7eb9ea6724884e680ed4b669853c 100644 --- a/Documentation/ABI/obsolete/sysfs-gpio +++ b/Documentation/ABI/obsolete/sysfs-gpio @@ -19,7 +19,6 @@ Description: /export ... asks the kernel to export a GPIO to userspace /unexport ... to return a GPIO to the kernel /gpioN ... for each exported GPIO #N OR - / ... for a properly named GPIO line /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 From patchwork Tue Jun 10 14:38:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896396 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 4638C1AAA29 for ; Tue, 10 Jun 2025 14:38:31 +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=1749566312; cv=none; b=qHDXGIswmjvS+qRnyyxKQhvgda2R1G9b2wd7br7BEFm8jZobLoKWJ8+kiqoJm6hmJh6BtSDql7VI7uRzZrInAwP2M/43Si0+JXXPLrZsKAfsKuImrCu0uS/rPWs7TpadrQSgk8enx/OMk/y5LOtfhfReye7ZN7l6SVmzCi3dVv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566312; c=relaxed/simple; bh=y6btqwIDw//7bl16rRxqja+q+WLuFh516AhK3+npkAc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Y8hYAj+3BDHnZ/UeWEgWjxOjWoZH9vKGRKd9zEeLKVR3X6V0czsWRaNb8XZQ7NTSs/8Wv+DuF6MtuF5V5CNTIltobQn7EM4AE/LkNBAL3JVy9kzaGZacL8kbS/WhZUfPQWjq03kRaGZnQbUfCAVhMudcXSbLytGldb2fwocB8Cc= 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=HkbFtcr2; 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="HkbFtcr2" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-450d668c2a1so44446765e9.0 for ; Tue, 10 Jun 2025 07:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566310; x=1750171110; 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=s9jr3lI5fcVvceMahRG3Hmp3DwAffmrkbyN3OMLcVqA=; b=HkbFtcr2ivqBZ0buQ9RBYYMxsee99Pdf+9RARVryKDhLj3fo/wfhI1JjPqKdiNGVA6 JO4sovID/zLs8oXVru13FNuERjIbPTeNgBnfgVHJORdfJgA7POTUC0Fy9KmhOq2NIdpy Qumkq5hOm3kYiqCPxamWpwILY/UFREji1+UH9R3izQkwHAD794e4VnBJkOd0abwGf1Uj l9bxrSWA/WNEvaA9b/UrYpVWMbg1Y1W9NKhL6ubbQKYVVmUNOztEJ9sD/pblZZaIb7Vj WscmK7UcqDYBVNQL+WaqpmeLS6jgJAhaM81mUyIbdkLXEoNXTKfjFNMJOkQV+7RJtQOS CMYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566310; x=1750171110; 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=s9jr3lI5fcVvceMahRG3Hmp3DwAffmrkbyN3OMLcVqA=; b=A2ZZyCk/4J0chmJfhWCcGCWnFtiYJhv05jBobpc4TwWKtrpSEe85Uq5ySDlmDPMkag bBERSPnnZ601DRfE6oTuTZAh9hFvZtRiRRE3dYEKIvQ725yZSI0uF915x0zikSJmje6l aRhW02HU3nCjl8FQTCrPSIwKyV7l0YEVSC3D2NhEiQ5F47qh91o1l3QTaLVLCtSI3lV+ /+5/X3/BkBTfnq94feHrKg/nMP4mEkKmHKMSTzTFYr++mk8iESYcoTCJ7y9LPHIyO85s LjmmWE65iDZfYJrL8xGnmhLVTiXr50rbhPDxvbZtwKsObO6a7vw/5gdeRv4xoiXHdhvS bEPA== X-Gm-Message-State: AOJu0YyARBAiPEDaLhaD7b7vUjP296Pvgd1pw3SDjJU4LzGQI6vMUm5t o4BffNrseBzVn/4HZL74kMIUNma0dg1KPkqNj5mFfnf3l7+96n5ASbubTepZLq6UFsBkUxJJTyT ekIix X-Gm-Gg: ASbGncs93O05K12US62WxVh/2rcDNj7sQJMRfeFS8X8gnTEYeHdHXmuBrTxJvAU0cXW rJ2343ewwnHHM3Gb4CuBr6jy3UR7/xaad8FMMlVwh5CGpOQ42V7qk04ZZG0uEzwus79ZAbQdUB/ pjQ6C7qYBRdnYlhmnDisE9JvZhOMJjY+BtLXl7iNYgu+yQj2ICw7qjRdhDE2FEJ38cyH7GVyOns MHqazyIn7VNchVq3jUstjytXOHB2qEJWXS2vlX0+gQD/iTjsTsLMzXTvGzw8ggBp+L5I0KbMzuG doYq79t0hoPe8tUOZQubbFVcduvONazyThTUP1421riP1cP0b/7B X-Google-Smtp-Source: AGHT+IFMEdpRiKRmCdxKw8aCmuhUo9l3ENL3IL5N0Xs2JkX6tBt5+XQbLM+8pkMJbmwyZUTaEW9/sw== X-Received: by 2002:a05:600c:4589:b0:453:827:d0b1 with SMTP id 5b1f17b1804b1-4531ce8bfe6mr37487515e9.2.1749566309544; Tue, 10 Jun 2025 07:38:29 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:28 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:17 +0200 Subject: [PATCH RFC/RFT 02/15] Documentation: gpio: document the active_low field in the sysfs ABI Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-2-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=966; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=xbj6qfG37TGxyivMvX+Q5Wvm9h4Ic80LNPUC37eB3xI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENfAUhmYNB9q24XAtLcEN+gyGiI6/HDChX3M DKS93JGMVOJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDXwAKCRARpy6gFHHX cnc5D/0TxSKlKzXvrMYuyQdHutExksJDL94m5z2oHjqNRxZkCzYAhxNO/GUiDkGwLuoUKkLX3IF rx1e8JDkmlQaOjhO4MLwfe5ICGBx16aYDJCl06JWfRQu44bwMTUY22ps+cxV8R8i1kYR+hxO05X LIECT0ko1GMiAM/7PxFRz/8o5G1GshisUcEyGXyaAc+xwico5tnSspuL4NNif0lLhloFf6eGJI2 b71Ox1+XaH6rq+rPbTzRWnAD2RkHch8OWucu2tq3lnkVvyTLUn70ekEc0k/QzuC6nfK44wlkKJB u/NV8HtcjP2PchH7zSpaJeRo38uf8S5KXecxaNdqZpi4DVCmBnk5A2ssiqPXgZWz223WjnqnYsN kUxhg5PUE9nEqgaV605YHIfBULNOueGC5rZSqq6yM5QGevdEdPMAXgOuD9KEaX2/8XwxOR5TzNA vfhI3hHAtr84vrTO+L7sndowv0fHrhkxCMx/SXhU5HhfzFp/J6/RIc8kq4iWwhQEhJkUxqy1VSH eYRCsZNa4rjZQTXm4K9JLFYgk79r3gqSKSuEnn4c8mJenAbBO18UMu5s2dBFy6hI35yt2BMiFZJ r0LmiQDxc6V1VhA7JDNzuKxaLqGmcsyOSQWCRYvB6tA7OA7KIrecYq61r9OgrAHjcaEKWhpQSB8 3DxHLUqWbbzBwvg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Exported GPIO lines also have the active_low attribute which is not documented. Add a short mention for it. Signed-off-by: Bartosz Golaszewski --- Documentation/ABI/obsolete/sysfs-gpio | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obsolete/sysfs-gpio index 8203bc2128db7eb9ea6724884e680ed4b669853c..480316fee6d80fb7a0ed61706559838591ec0932 100644 --- a/Documentation/ABI/obsolete/sysfs-gpio +++ b/Documentation/ABI/obsolete/sysfs-gpio @@ -22,6 +22,7 @@ Description: /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 /gpiochipN ... for each gpiochip; #N is its first GPIO /base ... (r/o) same as N /label ... (r/o) descriptive, not necessarily unique From patchwork Tue Jun 10 14:38:18 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896395 Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) (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 7F30B1DC9B1 for ; Tue, 10 Jun 2025 14:38:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566314; cv=none; b=bBK/XKY3LlOLKs69dCtu0Xf+nOX4Vgs1X2OEvXeSpaPH7k6wR2HOQpLAHFNVxDG5UQV2BDLX8rN2p5UpMSvCvdkghGdlvKDK0QWlQNDMLoA/6FAU7OuUxUb7q/MS4oQCaZkFazCRyg6qWNADQHej5fVdcCkBgrPlEsSOFv5lJYI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566314; c=relaxed/simple; bh=r9K+DvpICcJ4ZuUsbWlhbJUgVdpRNGn9i2eo8rHrwoM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PGwoHLlxJdNfCIWN7tqU3E277udlQt5mfYwfnJFd2OruQbPRvlAu4kz4Anpv917OrVrXesjfAvgi9/OusysLYa93dWIpVPZ/qy2SLZlcCD4Zy9OmaUhb7A7cXkDNX5LCPl/yHrPhsGxRXxUXDAHrETfS8/3nvmx68J0Ue2IpbaY= 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=VKbTzDWS; arc=none smtp.client-ip=209.85.221.50 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="VKbTzDWS" Received: by mail-wr1-f50.google.com with SMTP id ffacd0b85a97d-3a53359dea5so2335352f8f.0 for ; Tue, 10 Jun 2025 07:38:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566311; x=1750171111; 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=WHQOcKZ4A6xyy0RM96i7C2PXvKO3nwwvUylDj/GnkE4=; b=VKbTzDWSOUtL5P+b3LIswuySfLIhfHbuCgotEwjpky3Wos7ydpnteaaTxkz0VQOAQA HoJm1WTWG+F4vLvNpIsXuw77kQYoNLuWXhbI+Soc2d6jBE/JzZCCgB2jWOeesHC8zV3O zaXwSWQbvP+RwkWbd8fwhlo6ajawG4ziH5cG2A/yHarSHNYXASD+v8eVYGq/bUKzMbb9 gf+ls0W6Xf6TDQQkCozncr3Zn9CE2WnriGncAGA4IemGu6jwrGsZGkXNuYgSxpgfxXY2 Xlxe5mOwXBvVE0bbGvjtpKo6Z14b6bscfCd7Obb9zwHTeC3Gnh90HczffApEV0eRsISj jHwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566311; x=1750171111; 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=WHQOcKZ4A6xyy0RM96i7C2PXvKO3nwwvUylDj/GnkE4=; b=k0ryt6Fudih8KeVe5qoRWH3dr6ODTV4Yhvo+x5qDiG+odfGZFVxxv6/mEG2Kg3GaQ4 ikkRK+umjZs/ysbhShmTJbXHwRNmPiXhwJRK7zfNW8nzuDMvI4S4tEqU598M9xo5HdAI q5KSt0c6N3FPkIeOVKZFKEHFtNZ7K+R7+pZKoSaoU/LV4PBazL1KFHavRbMgYD1JjS8e XAc/vKjtDJfkvhLnbc7UEYhe64GW28cymu4wSoMggVGXNtveE58v96EyzA7qan/E/u/N rlZqYCfkx1+pcyXCC2+P+upR8+Mye9dUE02jrJUXV1eUtup41ONDr+yTCK6SLtzcK5Kt eLfw== X-Gm-Message-State: AOJu0YzRwSdR+XDde/7M6ptb7bMmktklM0BwTWiKmicBRT+jtoRk7Azt qaLA+gF1OEhGD0xzx6VHX7tw+TJRRKnjyBlabzqgm3ONcT2uLD9r+Yi0bmCz8iWWtfA= X-Gm-Gg: ASbGncu4hJU7eI8x+Wod8TXr/QeQvJPBhTwhSIzSdCcpBvXzVTttysCLf9yoMXLg8RD yk0D0Lta7xhsjQiAGhupltyPfMbwkdmFbu6tqvpD1YI4jpdnlq0EDsDjhpJH6tcvwHEDOSyKsmw 2kF3t+AT5BXle4A27J2PAHE3J/P0gHbr13yfs3hldn379Ww33uVJkR/HmitpnGQFI5p0Dcnt6kR ETcRlxl47CnAVBv6L/7skab/PetEp5MAOvn8fOrFA//AudADoLYx4Gm/BRkHSigx0sqMDCldLsK d+fE6TixIk3c1QQJzKriQ6BZbZEzJmRa8hMQE5or7OdCubngYX4x X-Google-Smtp-Source: AGHT+IEUg2h/Bn0JvR5KjB/GMwIW7yranfSOQUrVv9CYKqUG47gWBzJ153JCz3umhMUi9Nky7PXHdA== X-Received: by 2002:a5d:4dcd:0:b0:3a4:fefb:c8d3 with SMTP id ffacd0b85a97d-3a5319a7a59mr12007111f8f.40.1749566310625; Tue, 10 Jun 2025 07:38:30 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:29 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:18 +0200 Subject: [PATCH RFC/RFT 03/15] gpio: sysfs: call mutex_destroy() in gpiod_unexport() Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-3-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=753; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=RD/CHZwJ+oTe3UN6/TzEIj3HviHoO043bsyJSK0ioIo=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENgBD1Mcsx5nGcQWupj1LesrLbb3He40WwEO 59YvulbaqCJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYAAKCRARpy6gFHHX ctnAD/0Uy5oh/cOhkErWApxCGt2fUcN2smJwB8w5shl5w1uko9j6R3jyYZHKxMFHebGlcpS511F ZwCgF93nMkndVYmp8qnUNIIIJjjTa71lPnw4xLqqPOluDAjMissvfgTHB60hC9PVz6lk+AIcFcm YcSfUSA4zHXQSbXfuu2IzI+T7mZTCy9y5VUw5mGoyufEWzPrcxINufDGWs1+uWUcyxkyagl+WtO Q+ZRUEz72lFcG+8/DzyWy4UJn8EuyP/fU7aqk2Edxxc88qXCnYX6aSQbOAODztxgUfOZWMqe0j2 fviyE9QJI3nNV5C+1R+izsz+BYCBAdav0WWXkw3Gx95ucfjFE+91U1kC6f0hfnewFuiWGWOD+h3 Hn/mFdEBldRDnoEsXGGyddSq/0S/jqglTRT4OHn7M50BU27/jsLCJns3K1cS+uT/JKHrkzE5rxw vsfVOXATQQccSmD9kMKHylcZ4WCQcw/sXRQvMKD9uxzcC74zAtCLbQe2fGe6kOuDM3viDEY/TdA 0gd9G7vctG3LWkR6c9q3AMHkIFiLrncTntqfO6gloVx3s2xhjy4hiIzB5CTv/aRYyqxRz6RoBFS pFhyVt6r3Hs14sZi5ZjMG4O/RYCHnQhmPHPhxcX1VzN92hDcTlJoSI597fGgHulFASVsZcO1MoC NdalhrgKRg6zxMg== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski While not critical, it's useful to have the corresponding call to mutex_destroy() whenever we use mutex_init(). Add the call right before kfreeing the GPIO data. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 4a3aa09dad9d54dc77f28d596723fd5546cb3ae8..cd3381a4bc93a94b9a975248ae3e4bd8c2a3eb4b 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -713,6 +713,7 @@ void gpiod_unexport(struct gpio_desc *desc) } put_device(dev); + mutex_destroy(&data->mutex); kfree(data); } EXPORT_SYMBOL_GPL(gpiod_unexport); From patchwork Tue Jun 10 14:38:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895361 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 5C4331F130B for ; Tue, 10 Jun 2025 14:38:33 +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=1749566315; cv=none; b=FlJWGvS5XHWhx11k8qKMkbC9H3c3CLzW+lYn5QtyMpqUu1szNcP9CB+qg2AV1/CiGrAiYglaS2vu2i7YufAceiFBHNaXy/6UQgnjhfFKfd6+D1uRiuzfO3mc+EfPvTJ3BvIqzhvAeQRLg9U79qZ90F+9oPYjgp1CfogyIoR/SHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566315; c=relaxed/simple; bh=3iywfMmfWuguiGrQGZCARkYMwz88+y8SW6qE3RQFQbQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=kZ+0ducg0LLFIWd4ADYhUfI3cWdq6Q47kSFKoSEkGIEi4R5ihtB3gXBR1JmC61KUHIzbcWlHK9VdrEPihu8c+f8930EEm8WObLjYnztKqcPmvHZ327sdO3pCESsI5nKwYLWiWfJsabVI9Af2JDmhgddADnjASd6eXkO21n3lPog= 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=dcGzJ6EE; 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="dcGzJ6EE" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-45024721cbdso48009485e9.2 for ; Tue, 10 Jun 2025 07:38:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566312; x=1750171112; 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=RbAeNQNfAA6yD3395Up6TwuixaQ4LQ4OsQ45S++RIdI=; b=dcGzJ6EEoAnF9WeTiriEvCIv3CGffAoZZ7YcdnNzecHt9hc8CagyAhsFx3w+qQfoux L92SLZknMBjVJgRYI/S/QrFUaFXlRuhirh9U6KpcnEr7XQ2+KmldS4wquvZja78pct3E ekfgx3meI9HSvnmu9Af1AK1Clwi+rM+Q0s3hUDdwzN3u0GhqH08bBOw+QkIvjGB2/4xi /01enJEcvqwlY5TqgI33qeLF8bzYVsXfDAzddQH8Te/FlDMzcaQElSNiHG2VK6t+Fc8k og+3b/o1oSsZXbibmDLZ1ivv5z7dT29um+iyj5YXsAsISy26m68SxgZ++XqXHdV6UZqV NSnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566312; x=1750171112; 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=RbAeNQNfAA6yD3395Up6TwuixaQ4LQ4OsQ45S++RIdI=; b=Umvdon48NCDlP3+gm+KaO4oc3h49nHLigtuBS6BGy9qy5CJmTpTRbnDsIg9Uh5Y0vK fyxRoQ17NQhoKuSRnNwRIEStE+qh4z9/q9hCcPjVm4NG5ZmLZPs6/HHUFSavSOJCLsPL uxJMAp4XQSDLG1M5QwVzn0PASZ7xlRFfD9tiWQBbyzHuHSluj47pkcZS5bcaumR3COew ah3KIJv/Mfbv/EnaUkclxhJmbePIK3uT+/4LtDJI0hW9xv3f+SUSMRdWT9lYJ0zBFAoU H857Vatz1+HZmOkbHHuNVSJtCv7sp55T2JrtS8CVWupsWwe/Z7tGXuId4pqfyP9+UI5h t5pw== X-Gm-Message-State: AOJu0Yz6D8ieUGsOX4mjEi/3ibflrIL0JvOBmGSIa7brBcUhtsL8lJ/2 88Oytb7uw5LC5OkfRpFj38Vy3Uj0fg/WRLpiJRtK/nCaYSrepLbzkkz54V7R2l29Zz0= X-Gm-Gg: ASbGnctAYYhzeHbb8751SPmXl7MseLyswMhr7+F1Q9ngthBvT9bx+lgVdQt3buXXDv9 QHCMply3GeuGowu2Xh8IapcE6Aazv9ABpJ4rb3WQNuSV1+3enE9IuxQ7Os2t6B4tpDGT9d1Zw3D Xb2XPsDhIqu13ADWqK8qI/p8GJmkgxqq9nIwz83quN5x4O7QV4cw3OXj+37ygm+bzAieIEsP0ok Z2rtusxeUp/Ug6Ml9DfwTV3AwPzy91l7TRr88QqvGhPfjKjFAvZIIc6E1T7KNiN8XUTysAoI92U nc0eTaWET+1rRflt6SRf2UqYqQwBeBfUOzTkRsf04lU1rdSRtp++ X-Google-Smtp-Source: AGHT+IGNoAiYQhAXMTIDwG94By+OiA1TtpkzZkBJ/W0lgErFNRiyObiTaY3Fg7oTYTkdJbB8ZGUVgQ== X-Received: by 2002:a05:600c:6994:b0:451:df07:f437 with SMTP id 5b1f17b1804b1-4531dea9c40mr32956955e9.30.1749566311703; Tue, 10 Jun 2025 07:38:31 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:31 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:19 +0200 Subject: [PATCH RFC/RFT 04/15] gpio: sysfs: refactor the coding style Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-4-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=7880; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=zLQu1FIKLYBrG00ZMRkDPgP4mnshxpjIaGpQE6BbTbI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENgPxH8hZgvL6dsa6Tj3ckOBEhY1xZCFwMEl YzLo7uB3omJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYAAKCRARpy6gFHHX ctnVEAC07XkQBi0m2E/8rFvXYo1msouUY/fyTCXM6HKZyQQYwGD4C0SfqV0rLG3MzMrL2MZtjqN Zffl1iIFjAM+fQ/SiTwQ/1OhKVQx2xOGjvc/MaER8/5OKV9jP93na7sTr7X2B4eTnxxj8OOLKlo QtveQaTq/ExxSmZq0l5xYcsiqGS/l0uw/zPnJ1TUIixjJaittsHQBM7N+gFEm4ejt/OxHhhTAS0 bkqrvaImD8jGTjvkIUIMbgyKi8YrPHWW2/J9eRBsqTHjoHMMmfER9vF2qDqnCLyiLLd5mOelOYv noWJBvpK+AN20Q3JV+kIagt35RXA5hnb8Wc4Yvmwl1uqkgknmFIRG8Rdgvl+4EP/KKFikNxy4Ns LbZ1xHhW38TWgJebZkAYQUQu+kd0cUOvpvYQeL0kpr6q0HTMT+DdiAS9Hkk086BKxqWbsr0YWsf NIMwbr7PYT/yXCdwJSjUDhGR+TllEfH9OA5Zj2XF8FJGjXGMPDDxadeP7e6cqJjDOtzxjrluXXs DIdxmMR06hGKbk44bsidvIN3R99/viChoEKqEhTRYuWKwp+XudwevuCk/PBfsQ/2qZe/gyHWJp4 l1Zx1ZK4/hAaXzLHY/gA/ybklpxDYTS2Cm3g9bLR9yI5YO3GlmJ9hI2fimGb5GPvnSatuMJxBtu lp/uZrbCWZBf/lA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski Update the code to be more consistent with the rest of the codebase. Mostly correctly align line-breaks, remove unneeded tabs, stray newlines & spaces and tweak the comment style. No functional change. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 67 ++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index cd3381a4bc93a94b9a975248ae3e4bd8c2a3eb4b..88f97018fc7995c1e1195c0da4b6a8377af62e0b 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -73,7 +73,7 @@ static DEFINE_MUTEX(sysfs_lock); */ static ssize_t direction_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; @@ -88,11 +88,12 @@ static ssize_t direction_show(struct device *dev, } static ssize_t direction_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) + struct device_attribute *attr, const char *buf, + size_t size) { struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; - ssize_t status; + ssize_t status; guard(mutex)(&data->mutex); @@ -109,12 +110,12 @@ static ssize_t direction_store(struct device *dev, } static DEVICE_ATTR_RW(direction); -static ssize_t value_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t value_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; - ssize_t status; + ssize_t status; scoped_guard(mutex, &data->mutex) status = gpiod_get_value_cansleep(desc); @@ -125,8 +126,8 @@ static ssize_t value_show(struct device *dev, return sysfs_emit(buf, "%zd\n", status); } -static ssize_t value_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) +static ssize_t value_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) { struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; @@ -179,22 +180,22 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags) irq_flags = IRQF_SHARED; if (flags & GPIO_IRQF_TRIGGER_FALLING) { irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? - IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; + IRQF_TRIGGER_RISING : IRQF_TRIGGER_FALLING; set_bit(FLAG_EDGE_FALLING, &desc->flags); } if (flags & GPIO_IRQF_TRIGGER_RISING) { irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? - IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; + IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; set_bit(FLAG_EDGE_RISING, &desc->flags); } /* * FIXME: This should be done in the irq_request_resources callback - * when the irq is requested, but a few drivers currently fail - * to do so. + * when the irq is requested, but a few drivers currently fail to do + * so. * - * Remove this redundant call (along with the corresponding - * unlock) when those drivers have been fixed. + * Remove this redundant call (along with the corresponding unlock) + * when those drivers have been fixed. */ ret = gpiochip_lock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); if (ret < 0) @@ -240,15 +241,15 @@ static void gpio_sysfs_free_irq(struct device *dev) sysfs_put(data->value_kn); } -static const char * const trigger_names[] = { +static const char *const trigger_names[] = { [GPIO_IRQF_TRIGGER_NONE] = "none", [GPIO_IRQF_TRIGGER_FALLING] = "falling", [GPIO_IRQF_TRIGGER_RISING] = "rising", [GPIO_IRQF_TRIGGER_BOTH] = "both", }; -static ssize_t edge_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t edge_show(struct device *dev, struct device_attribute *attr, + char *buf) { struct gpiod_data *data = dev_get_drvdata(dev); int flags; @@ -262,8 +263,8 @@ static ssize_t edge_show(struct device *dev, return sysfs_emit(buf, "%s\n", trigger_names[flags]); } -static ssize_t edge_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) +static ssize_t edge_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t size) { struct gpiod_data *data = dev_get_drvdata(dev); ssize_t status = size; @@ -302,7 +303,6 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value) struct gpio_desc *desc = data->desc; int status = 0; - if (!!test_bit(FLAG_ACTIVE_LOW, &desc->flags) == !!value) return 0; @@ -310,7 +310,7 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value) /* reconfigure poll(2) support if enabled on one edge only */ if (flags == GPIO_IRQF_TRIGGER_FALLING || - flags == GPIO_IRQF_TRIGGER_RISING) { + flags == GPIO_IRQF_TRIGGER_RISING) { gpio_sysfs_free_irq(dev); status = gpio_sysfs_request_irq(dev, flags); } @@ -321,7 +321,7 @@ static int gpio_sysfs_set_active_low(struct device *dev, int value) } static ssize_t active_low_show(struct device *dev, - struct device_attribute *attr, char *buf) + struct device_attribute *attr, char *buf) { struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; @@ -334,7 +334,8 @@ static ssize_t active_low_show(struct device *dev, } static ssize_t active_low_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) + struct device_attribute *attr, + const char *buf, size_t size) { struct gpiod_data *data = dev_get_drvdata(dev); ssize_t status; @@ -397,8 +398,8 @@ static const struct attribute_group *gpio_groups[] = { * /ngpio ... matching gpio_chip.ngpio */ -static ssize_t base_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t base_show(struct device *dev, struct device_attribute *attr, + char *buf) { const struct gpio_device *gdev = dev_get_drvdata(dev); @@ -406,8 +407,8 @@ static ssize_t base_show(struct device *dev, } static DEVICE_ATTR_RO(base); -static ssize_t label_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t label_show(struct device *dev, struct device_attribute *attr, + char *buf) { const struct gpio_device *gdev = dev_get_drvdata(dev); @@ -415,8 +416,8 @@ static ssize_t label_show(struct device *dev, } static DEVICE_ATTR_RO(label); -static ssize_t ngpio_show(struct device *dev, - struct device_attribute *attr, char *buf) +static ssize_t ngpio_show(struct device *dev, struct device_attribute *attr, + char *buf) { const struct gpio_device *gdev = dev_get_drvdata(dev); @@ -439,8 +440,8 @@ ATTRIBUTE_GROUPS(gpiochip); * integer N ... number of GPIO to unexport */ static ssize_t export_store(const struct class *class, - const struct class_attribute *attr, - const char *buf, size_t len) + const struct class_attribute *attr, + const char *buf, size_t len) { struct gpio_desc *desc; int status, offset; @@ -498,8 +499,8 @@ static ssize_t export_store(const struct class *class, static CLASS_ATTR_WO(export); static ssize_t unexport_store(const struct class *class, - const struct class_attribute *attr, - const char *buf, size_t len) + const struct class_attribute *attr, + const char *buf, size_t len) { struct gpio_desc *desc; int status; From patchwork Tue Jun 10 14:38:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896394 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 70C5C2165F3 for ; Tue, 10 Jun 2025 14:38:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566316; cv=none; b=rW2RPj+r8DwuxeZyABGyesVuWYo8UHSRiYbV6awHVT6hXmZ/RLvAzud+rZCof+X2nuvgCVNknPATBcdMBkJwf9RvV1GqUkLk2RUaU0hYWUUiru2ycHgFtk0uTyDf2HdgIExZK1Va2qCeqzIrEOoffa8+earMlokauHtPEpl9WYA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566316; c=relaxed/simple; bh=Qq9fIseB6gb/ver++jBeKOrouYgQmp9/vrQcSFqI4mg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Q8sRPF0sfnPqkD43iQAA7r1NzJfu46MCvAoi2AFGN5leFgDDeIn5E6/6ViQNe7HH5ZP7Me2Lec5RbZEtLbgTmMS71mG5YLsNoEFXUGGUrJR42x3i5X9rzc4f+e5jg6GwB6N+MH/0m7SDEWEPOeiH4CAmVWaTedRwUb/Qeaap7OM= 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=oZ30zpe3; arc=none smtp.client-ip=209.85.128.47 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="oZ30zpe3" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43cfe63c592so63847425e9.2 for ; Tue, 10 Jun 2025 07:38:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566313; x=1750171113; 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=cxAwG+kplqaCnxCSj5FTH8TFj3pQX00WZhLLV2ey3uk=; b=oZ30zpe3a1Y5tTnMYyM7uibd4THq8tiOvg0xuB/Fi07S8wYUg98PnD2fzZhtzMTT/y GIpERtvijYK+Isn8QwVLthORC3XMxbmh4V7cBjB7xJVI6hZ4o16lwdQsegWQUESIZVLB 36og5PmjsTnnCmOJQ5iUZyVLHAek4JSZ0jrLfsViLo+mvMcZ9OaSMTh/WijAumM4IXHp WV6yqZ2D+v0X1BuVZmCVO630WMMTbyr/7EU7ImWZARYQc9CUb6ZvAxO/WolysAYPWHzg 7VbkOeK24qCrILzUiUISJ/JHTMyB/rKRNElSmvGrKV7qEM7oThFaQC8LKhqyFl9GBfzw hu/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566313; x=1750171113; 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=cxAwG+kplqaCnxCSj5FTH8TFj3pQX00WZhLLV2ey3uk=; b=hXQ4kAYk/ciCrOOlgSQngQ0kYEccjbQNHod64NZvUP3qeec9AloR4E+LjGGLf/dZnw Xk4Ito1qaSPl3foH0HE9N30O4FfI1gvZpFvWoDyFHNJq+CiXpS74n6XAUG+wFGQxs/ce OK5/VuqHFcnEoYoJk7YFF/vdtSbTHAH35VHGDjlCPjAXciYL13yunV1nRkalx05cynXf iJC6+7zu1c5Bs3xRkXor9j37dOTRFeKcArsWGiBdIqBkyhN/APiYsiJLuSiB5Zq4V9oi N+vM96kji+dG1pS3hlOONtKdqJMbhEeEeePpYOrAgT1Vcbr5kW+aovewVB467gsTQAZU OXcA== X-Gm-Message-State: AOJu0YwTdflUhyN3PbbYRLLTTIOhTS9UrmEH8RNNB42F0k+omBiiSIaz 6UWAF/ODL09CJ0ri5cHAcngFduy2sDQ5X5Eyp2rTkTjNK+tDhxsrhngMTZgYDILCldM= X-Gm-Gg: ASbGncvCn+k3XU/JJzTqFnZazxZUXg/QSLc8uixdv5M1ljdTqKO9pcE7AE7vMhR0cyd v1w7XyirbLpMsPCc9I+m1JoGttfnRKS9MUNwQPt5RRftPUor5On86vmuwgGqTPHHUjJ3sNzKiVj g5ZRmajpdXf4yYadDrLQyrmHs+Pizzx0GHzGB20kP+c/L5GS43CSn0owxt+gFnZURHNDjMRwVor qWTQ3y4eTNLRC2tpHxrbe+ROfWdIJg4whmf/Q5uOI4Fe43AS4sTHwiotJOBcUH1ICY5KB4EVT6J LqIhxQ/1u/MXPLLmlcaRnlrIJqWH6skX6funjPrZtRKa/qcgtOXw X-Google-Smtp-Source: AGHT+IEFyaeIP3T0Ehi8PeMDhGrDKSKdxzezZvGSc6n8IFLaX5lda2NAuMtyShPdC8E0HiY6ckXmbA== X-Received: by 2002:a05:600c:6792:b0:43c:ec97:75db with SMTP id 5b1f17b1804b1-4520138974bmr162802165e9.11.1749566312788; Tue, 10 Jun 2025 07:38:32 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:32 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:20 +0200 Subject: [PATCH RFC/RFT 05/15] gpio: sysfs: remove unneeded headers Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-5-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=1058; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=ZzKrszs+G8SUIpo3FlFljAL+3IaTQq3RZ1Iz/yMv618=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENgtdqTN36J6Qox+cSHpKqwAD9+WMqD+FfJB O5atuCP4ZOJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYAAKCRARpy6gFHHX cnTfD/0YorOW4Ei+N4MZBlIZyNGgK8lOHbL+HNZhFrp/s+Zoh2Xx8ZU6mnhKCYBOIl7QAwyDo3c GdhVB07w4VQ0dEUM9PczqLhmbngp4Hr12I1OVLRFf2YR1b9zcqdT80A6nC7fpWRDgcNYWWB/8qO +SagL6UW3zfMgzv82PBxUWnGLCPgUAXDLMszFapYHPL4Z3ePACnH2vi/81nf+DhcyB3NKI4ycTr BmqQTrZHnIyxM2392Dv8Rx2UlFAtQD1myM6VWeNreSEP7k8HIaO9VRsgorxJFDzbCF4Jgad/Nbp vDwgBB46nPx3V/tvo4psJyqk/46OwHktfFPn7vRJfuFyX6mV9wQNAMYur7JKuNbPNqxWz1MGBO6 B8GFOB1aAy2q+VUfFqF7ucb0+a6/OAMysrZJQESwbxadQORTduXeyMS5QVELcWStBFnuePICpUX b4KRFbvbXEFlu78lD8Ax7Ic2nZDU4QptsMqVcDF3iFZdoYjnoTMQ29RDo3tNMegNPmjgUKZm+4W f0r5szXPKWVUB8gBYtuGoVcmU5zbGywRjVNEGWwoP4Xmh5uiC0vUxsd3d0946rKjeGyusZxSSY8 keELNr1ncsvKSbvTPYcu8otg9KkLQ3meVVzuivn+pCBsRa9kyOXQK9b3QgquIuvj6mTaecvjalV 5z1LFmCt3xRIk+Q== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski No symbols from the linux/idr.h or linux/spinlock.h headers are used in this file so remove them. We also don't technically need linux/list.h currently but one of the follow-up commits will start using it so let's leave it. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 88f97018fc7995c1e1195c0da4b6a8377af62e0b..f23b4efea5905a9eab51ed9e50b5159135a8e26c 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -12,7 +11,6 @@ #include #include #include -#include #include #include #include From patchwork Tue Jun 10 14:38:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895360 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A3BE221281 for ; Tue, 10 Jun 2025 14:38:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566317; cv=none; b=ZzMTdjX9CO08VDTVR3gedoNTH9EZdG5Wkzw9cy+49dZeZTfjEi1WbfNsIhOTgOQW6sdFRb9ejs+BKPMnxyLUVx4Q9Db8OuasQjHZ5tl+OV1UW0l5Y8R/BJi88PBwLm63FXP1qNaUtQIdzM7i1FDYRv2a1BiIvAIH/ydy+FFPMsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566317; c=relaxed/simple; bh=SuhcWnQjnt1V0zaDkIpP3r+TFOAIWMDQ1nvmYS1xN+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ksrYMNvQBohzQRGxAmhd9hKYOSpxYR7Q+joIWS8ioBsnv9YORrKZlKZ3buG9cOfBa8llyYR9EBGy4Bnuw+IXIpPa1c/wXm7pOYmKBI29+BGNeVEEHuZD6mbcAv7K3WtJLGyKfdmMW7Hx7nUN0n0fNa131kSD0QlUvjQ5n9N32UI= 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=vYk1+APO; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="vYk1+APO" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-451dbe494d6so67518335e9.1 for ; Tue, 10 Jun 2025 07:38:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566314; x=1750171114; 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=Shn2eyZ5fd8Sf9FUXjLdmt+2r+pNCPfrOT0YWQfJc1Y=; b=vYk1+APOhL/JkXmtx77pRYXlmiB/wffHut3LT4UdqcajXcVePVUEdQnZTj3topAJZc gPK9XczQt/fpoBiLjPgF06E+fh7ZTRyovaViFoDU/jBEqqFGVRNLYTKDVanxa4KMcC9i Qli59hF3tEc5ueM3XewLe09CJijW9dkJhNvjaoDmJURV7ijth5CwwGmqLEnX8Jjlg8m3 jOdd2b8wou4G3dPFQHy5Rm5/lDJrmJIs6QdwirVy0WAjz/Ek0rZAS3gc1nqnTihA92qZ 7tQK3Lv4wrQcKW3FTPjRjJDqpwAMnP40j0obKFU+pgdMGixfTMPIichW27pYoPA0LjNp cnSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566314; x=1750171114; 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=Shn2eyZ5fd8Sf9FUXjLdmt+2r+pNCPfrOT0YWQfJc1Y=; b=orgjWK3+SMXXblQm3OAZvJ36fdHXEM1vmCUv9aBOq4V9Bql5JL5DBlJqKYAqNY9pca 81RcJNhokUTtvrMaG26LGWBrH3Lidm0GbbrIg9Hy2ihK67D9h+s2p+vcFwQ7MUb0a5e8 i+3R0SOGlHIQnONz5R4+xzrqilcbOdSPtUBoGkigfrXsa/qRJ6xgEK1aQHKdWskuJp4h LqK9whGxDfqx3TfglEhB0nIEubLiC6PsMSOLc/jNDQM53jmCzwNhGsYF+MSJFa0J5day vC0zA7nkoCB22LvFEMc0iQp5pQ3alFYMTnYbLQFemD9vkqpwTTn/QKAFtes3Q25kk+fU 3UMA== X-Gm-Message-State: AOJu0YwkRd0c7mvEUwGBNbdqlbWtNTavVOoh7BKvXGaf1lGyPPK1v0Zp MfaEgFYZxlGg3E8C1xLc/Tr6Rx+HSwe04h9D7TGUTfns5d+VqFI26rjkq6n4k4Z8pkI= X-Gm-Gg: ASbGncuILJEMl+tfnUtszrmqWSBIzr6E67EB4am41vfMN2JedX0IhW6Il5tORX89Y1s Dt3hUgwFRcI6gVzsfXCOlLrPkhdEFTMC0Y5S7VqpKpJlXtOJvyjDQak8uMzPRL9wQsHk05N4LTO RW31l35LaPUuTkI6zDuMJ9A1rfPPxJRBu7NJ7Iw2twGe5B+wzGhG7YwCDIAVurpGb5QKizdVFz+ bM43adbrw5qmFR9ip5H/NsrnC7dZl9LkIe50zRPADAHoCgA9VMP02UR1xGVyIhZKNW83gy0uSkZ VHhNA/34DYjv82g0pEBAAptcmAyEgZivn7GkAFzGQDAJbt3e0HXVghuDud3MHEc= X-Google-Smtp-Source: AGHT+IFQxMr+KpfJbCsHx4fMzLU8Ewr+onA/3HvlnZLPIEF4Pbfk+QHCSRE8DIYbR5+FKFsmMZn9+Q== X-Received: by 2002:a05:600c:4e88:b0:442:f4d4:522 with SMTP id 5b1f17b1804b1-45201364b20mr151409425e9.5.1749566313774; Tue, 10 Jun 2025 07:38:33 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:33 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:21 +0200 Subject: [PATCH RFC/RFT 06/15] gpio: sysfs: remove the mockdev pointer from struct gpio_device Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-6-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=6366; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=je470wIsOKjy+Wgh3vMCa95VKbv92LlyIwF4JpS1fa8=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENgMzYrTrIqo79b7bugZj00GqsKV3l++8Gvu Dgz89ZkFJeJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYAAKCRARpy6gFHHX ciedD/427LXr8cn0G7iqWrhFjM8Ewz+h+HQY5DVXsTqUfMe4R46IvTfJHW/JwJGT6DxflIice4r bRD1dMj6CyTLuYnc4aOCTw2mIJd006otLq+fV1z2uqwdf5MKE+O7VeHHuNyJtBejL0os/altIEh Wz5Iio0yp0VZ8yWTgGVs+15budcVQ8I8qdLzo53o7L9j6PeRNWzIPDC+CfyUdY2QUgFup786G2D Mr1q91sRH8VzkUyXAVawG07RTmOD7th1kTH0yEWodWQFpBuQrJG92YKcc+q0n363lzmhS39bXno iR8vdq674gUvGGQf/JFtey7iLeh/AQ1eBuj5HB+WCUFEXNS9ESmXCoRNe4Z2zG7K1RBR7hHa7W4 DrjBqvqNvFRQJPjp1iNUvjpNwZqv2zmxMnY4qrcNdo+iHKpKphNgh+LRkTJj1ATPAEk902rwSn7 QC7WJir6buQtT/oUgUzYUFb6IYy7HbuGV7k3n5420bm4rFHjKK66p8rTkB3PeGhW31bMci69GsK K/Vr0YZMuqbSkUnl1scq/4ux9xeBEDEKp+CXAfhwykfuoeMcGd2zCVYsGQuZD6y6xTIOCE1yo/L EXXrBb05K8pdId18H227bdT1Lok+4seuGzXHAbReOKDLbOlVqizlCRENqPxyNRwig0paxtF+RPV hOQJkk3e46ar/iA== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski The usage of the mockdev pointer in struct gpio_device is limited to the GPIO sysfs code. There's no reason to keep it in this top-level structure. Create a separate structure containing the reference to the GPIO device and the dummy class device that will be passed to device_create_with_groups(). The !gdev->mockdev checks can be removed as long as we make sure that all operations on the GPIO class are protected with the sysfs lock. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib-sysfs.c | 81 +++++++++++++++++++++++++++++--------------- drivers/gpio/gpiolib.h | 3 -- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index f23b4efea5905a9eab51ed9e50b5159135a8e26c..956411fc467a26a9827c616d8dc067c70f9244bf 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -43,6 +43,11 @@ struct gpiod_data { bool direction_can_change; }; +struct gpiodev_data { + struct gpio_device *gdev; + struct device *cdev_base; /* Class device by GPIO base */ +}; + /* * Lock to serialise gpiod export and unexport, and prevent re-export of * gpiod whose chip is being unregistered. @@ -399,27 +404,27 @@ static const struct attribute_group *gpio_groups[] = { static ssize_t base_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev = dev_get_drvdata(dev); + const struct gpiodev_data *data = dev_get_drvdata(dev); - return sysfs_emit(buf, "%u\n", gdev->base); + return sysfs_emit(buf, "%u\n", data->gdev->base); } static DEVICE_ATTR_RO(base); static ssize_t label_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev = dev_get_drvdata(dev); + const struct gpiodev_data *data = dev_get_drvdata(dev); - return sysfs_emit(buf, "%s\n", gdev->label); + return sysfs_emit(buf, "%s\n", data->gdev->label); } static DEVICE_ATTR_RO(label); static ssize_t ngpio_show(struct device *dev, struct device_attribute *attr, char *buf) { - const struct gpio_device *gdev = dev_get_drvdata(dev); + const struct gpiodev_data *data = dev_get_drvdata(dev); - return sysfs_emit(buf, "%u\n", gdev->ngpio); + return sysfs_emit(buf, "%u\n", data->gdev->ngpio); } static DEVICE_ATTR_RO(ngpio); @@ -545,6 +550,26 @@ static const struct class gpio_class = { .class_groups = gpio_class_groups, }; +static int match_gdev(struct device *dev, const void *desc) +{ + struct gpiodev_data *data = dev_get_drvdata(dev); + const struct gpio_device *gdev = desc; + + return data && data->gdev == gdev; +} + +static struct gpiodev_data * +gdev_get_data(struct gpio_device *gdev) __must_hold(&sysfs_lock) +{ + struct device *cdev __free(put_device) = class_find_device(&gpio_class, + NULL, gdev, + match_gdev); + if (!cdev) + return NULL; + + return dev_get_drvdata(cdev); +}; + /** * gpiod_export - export a GPIO through sysfs * @desc: GPIO to make available, already requested @@ -590,12 +615,6 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) guard(mutex)(&sysfs_lock); - /* check if chip is being removed */ - if (!gdev->mockdev) { - status = -ENODEV; - goto err_clear_bit; - } - if (!test_bit(FLAG_REQUESTED, &desc->flags)) { gpiod_dbg(desc, "%s: unavailable (not requested)\n", __func__); status = -EPERM; @@ -719,9 +738,9 @@ EXPORT_SYMBOL_GPL(gpiod_unexport); int gpiochip_sysfs_register(struct gpio_device *gdev) { + struct gpiodev_data *data; struct gpio_chip *chip; struct device *parent; - struct device *dev; /* * Many systems add gpio chips for SOC support very early, @@ -747,32 +766,41 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) else parent = &gdev->dev; - /* use chip->base for the ID; it's already known to be unique */ - dev = device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), gdev, - gpiochip_groups, GPIOCHIP_NAME "%d", - chip->base); - if (IS_ERR(dev)) - return PTR_ERR(dev); + data = kmalloc(sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + data->gdev = gdev; guard(mutex)(&sysfs_lock); - gdev->mockdev = dev; + + /* use chip->base for the ID; it's already known to be unique */ + data->cdev_base = device_create_with_groups(&gpio_class, parent, + MKDEV(0, 0), data, + gpiochip_groups, + GPIOCHIP_NAME "%d", + chip->base); + if (IS_ERR(data->cdev_base)) { + kfree(data); + return PTR_ERR(data->cdev_base); + } return 0; } void gpiochip_sysfs_unregister(struct gpio_device *gdev) { + struct gpiodev_data *data; struct gpio_desc *desc; struct gpio_chip *chip; scoped_guard(mutex, &sysfs_lock) { - if (!gdev->mockdev) + data = gdev_get_data(gdev); + if (!data) return; - device_unregister(gdev->mockdev); - - /* prevent further gpiod exports */ - gdev->mockdev = NULL; + device_unregister(data->cdev_base); + kfree(data); } guard(srcu)(&gdev->srcu); @@ -798,9 +826,6 @@ static int gpiofind_sysfs_register(struct gpio_chip *gc, const void *data) struct gpio_device *gdev = gc->gpiodev; int ret; - if (gdev->mockdev) - return 0; - ret = gpiochip_sysfs_register(gdev); if (ret) chip_err(gc, "failed to register the sysfs entry: %d\n", ret); diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 58f64056de77b05e8cbcb2395a55da793b1a52fa..9b74738a9ca5b1a4826c8d56d871f8a7cf6ea1e7 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -27,8 +27,6 @@ * @dev: the GPIO device struct * @chrdev: character device for the GPIO device * @id: numerical ID number for the GPIO chip - * @mockdev: class device used by the deprecated sysfs interface (may be - * NULL) * @owner: helps prevent removal of modules exporting active GPIOs * @chip: pointer to the corresponding gpiochip, holding static * data for this device @@ -65,7 +63,6 @@ struct gpio_device { struct device dev; struct cdev chrdev; int id; - struct device *mockdev; struct module *owner; struct gpio_chip __rcu *chip; struct gpio_desc *descs; From patchwork Tue Jun 10 14:38:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896393 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 7AA72225A5B for ; Tue, 10 Jun 2025 14:38:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566318; cv=none; b=aUyODlnN34QshCKHpU8T6Kq9qT2YClEcX6HG5Sv2ie2WO0CTUibWRm7XvaVkr0kN9v7Kzp/AWd/QkyelMS3/crR3vZ2YtZ8FknvjBjz5uwmQp6K26YkFI6EuyLkwHnDfZTWKr4UA0yd+R2MkcyR9rEPNrzj8xGreBkmlFZvsijk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566318; c=relaxed/simple; bh=2i3eMCTDD/ZK85w+pfSMGIh1H7DR5YiKUKwBrEFjB0w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KqulWl83qYIVp62WDhWmSTIYDFIspDshDjgjGwMLirdvT8rq6f/fMztXHHE4epeNcaKIZ5D8DX6R/6WQIlzoX2rMIGabD33oldCx1XcR3sx0zaxBD8sQF0RGktVHLgpWngzqPRJkEFJ1hsZlSZSdqVe38iuHmlLd2MXUVXX16K4= 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=xzqWTvjM; arc=none smtp.client-ip=209.85.221.51 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="xzqWTvjM" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-3a4f72cba73so4536890f8f.1 for ; Tue, 10 Jun 2025 07:38:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566315; x=1750171115; 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=yFKF+c+Y40KVmL7E85VKf6TTXAyUq7dCBYKSOqXQFJM=; b=xzqWTvjMILYFmwRjRtMFB2HTyEcW/Nyr7/PtH/HDLBY0Uk2zo/Ym5+/Y7Ky6LPDzYL HcKIW+ewpk1nk3UjBD7mVymKf7n2nLpQIsRik+b914+fzsLUBmcKclr3cWIKUBfA0JLP zp3biStMHyS4yWVFWOiE4ZSI/P2rFRRaIY5jSu4dKj50jhUQRTVgklk35gBYV+W571hy 0v7gexF/TaVW42em/tDLEOEg8Kz7J9bI9g9qzLNEpYimDGc4vpTUfsFKWw9joMo7P0ec mHQDh+/smm8tsLYsF4DPcRZsV++ZeG2OPHxW9Jy5xOb17k+PGy6Istbew+WCcckp/FTl lw9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566315; x=1750171115; 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=yFKF+c+Y40KVmL7E85VKf6TTXAyUq7dCBYKSOqXQFJM=; b=CjIVB678M22/VdgZ2AvoZp/YpUKWW6IE+EEGoCByH4UXrHPeeLuUmGHEZ2dBQtbf0k jLgeGTVYDz1MHuhuzr7RfeW6hJpt+v/Ku/BHnoh9ZnThr4tZRnJHucAvNP5L9rm9pxyA fn1taS9MJpmbt6ODl5a6yvIC0Z4QDJxZOKt+RpnFmbl6gEy4wr0i4I/qT10ZBgdyTtfj cn8TuMXMIEZaW+Q0D4/gg3IfN6vVttBLI8zG6x89Eup3VryednwCJ7wAv9ee3CAoo6w3 Q9c8Nzj98ynN6a4ACfpmF3x7aGJvG+7g22B20IskOwLJBjlxYpqlTn5uUQq2GnkCdFJI WyJA== X-Gm-Message-State: AOJu0YzsW2IXRqeu//C3ulid92+usfC8cSXcUmaNuPxKE+sgGsJHdfmX egdajCbo6uMFQD93BIvQLYmVIkfU3+Thr4CwR9bIfuUomNLF2Z/wdRr6jx7G08enucIiniWte0s 8C763 X-Gm-Gg: ASbGncufdY385nyk6ZT2AIzt1qFSzOIu1JP3anz2DSc0R0svU9ezLanUfRUSBp7YBR9 6KcUwZouU7VEutEKzNaP/HqL3WSkwj5ksyKG5Ita5t9co6eSlycAdT+8tMgqD4OMp5FDG4JzAoV pumneFqHlN9DGLy8oywq1SD43nJutKeZkrhsCOEAtgjnS/SNvS1EjTer0ekdglY9qq2C7aYwMbo lhnQbx9fUC26fRDn1TF74uF3/JRLXhUX26TTx9XGfhtStUX4L/myNkzdNsgJoyLMmAjWJytjOmd Q0Dfz22uTSf3lRinKx2efMgDy0nWRUEZ6UFif+5XDi8tVSiu4ahEtr6ofAwVYH4= X-Google-Smtp-Source: AGHT+IECbU4hjZU9sCCG6i4ZxFM91y8FwBqtSLg4Qf5RSAv8WzK3WKhk1i/LqRYNTnbUtcdd56QJBw== X-Received: by 2002:a05:6000:4014:b0:3a5:1388:9a55 with SMTP id ffacd0b85a97d-3a5513de3a4mr2961541f8f.5.1749566314767; Tue, 10 Jun 2025 07:38:34 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:34 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:22 +0200 Subject: [PATCH RFC/RFT 07/15] gpio: sysfs: add a parallel class device for each GPIO chip using device IDs Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-7-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=9657; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=w7p2yull84975cImPopktS2uQOfBsB0R5FKe8qO70gA=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENhEmxY4aZlgWJMH11gEUNSIR4WcLQEjT2HQ S1PxDMP4luJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYQAKCRARpy6gFHHX chK1EADYlG2LY7SHs50ScXDfPYSEoxyHNpcHzohgWjYDOclTcgHIXHnu7WauGqxcU+R4CC3mK1x e2GOVvZ6aKIg2Z3GckgiJsqyGgoW6KyaaNfBSMIxQIXZpvpQI9fvQBpCaOr9wz39s/vMkTf0EwP M5LtNxrqRFcF7tHCVAteKVoxVWLMU0ob300Zs9UJwZInO0mP9pxXB/JhGazhg2HaZWzWeCa5LSx Msd1uIe6fSj4ydBgz7imvEY/xmIwyAsY6yWwSq1ayE0RR8f76B3IUdbwEJjOfC3FBBPVBu9pRfN Vu0gH5ujvxe7qlj24ISHshW+kqMzmvHWDwTY+arVNQgU/MtRQrbE8+3sfbTx5OqA5YqUm7x0oEd sVDLYBh17tptCx1ySYwejEd3N/NRZBFGHQt7hIRnCuDnZfd94P4NJH3FdmBpjHDrkkzrInsP7rE 4f45QloN4lVIsZIvK9WaEgDAFOP303OPiTBfgTwqq4BDlPOPFfPVlexsRZ17DBJP93tVcm3l7Tp P3kVOO8jlfVdRXDOgiolfMpZNUZooRqKW3R95q1VHCsSX8Th3+pGZWH0KXrH8xl20FA0KoaLFlN fXvJJ9ur7TXSih0EGalulEUv6J1TuYMBTJnV28uQ+DHR9DBGPGO4cwva3KvCZvUizYn024mz4ug cTEQEX//BD7Z/+w== 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. Signed-off-by: Bartosz Golaszewski --- Documentation/ABI/obsolete/sysfs-gpio | 5 + drivers/gpio/gpiolib-sysfs.c | 191 +++++++++++++++++++++++++--------- 2 files changed, 148 insertions(+), 48 deletions(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obsolete/sysfs-gpio index 480316fee6d80fb7a0ed61706559838591ec0932..f856e286051d6bfa4990660dcb25b3fdb27cd0f2 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, not necessarily unique /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 userspace + /unexport ... to return a GPIO at HW offset X to the kernel + /label ... (r/o) descriptive, not necessarily unique + /ngpio ... (r/o) number of GPIOs exposed by the chip 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 956411fc467a26a9827c616d8dc067c70f9244bf..a3403b963d6488aad24e47e9e28e0439676de704 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -46,6 +46,7 @@ struct gpiod_data { struct gpiodev_data { struct gpio_device *gdev; struct device *cdev_base; /* Class device by GPIO base */ + struct device *cdev_id; /* Class device by GPIO device ID */ }; /* @@ -399,6 +400,14 @@ static const struct attribute_group *gpio_groups[] = { * /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 */ 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); +static int export_gpio_desc(struct gpio_desc *desc) +{ + int offset, ret; + + CLASS(gpio_chip_guard, guard)(desc); + if (!guard.gc) + return -ENODEV; + + offset = 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 = gpiod_request_user(desc, "sysfs"); + if (ret) + return ret; + + ret = gpiod_set_transitory(desc, false); + if (ret) { + gpiod_free(desc); + return ret; + } + + ret = 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 = dev_get_drvdata(dev); + struct gpio_device *gdev = data->gdev; + struct gpio_desc *desc; + unsigned int gpio; + int ret; + + ret = kstrtouint(buf, 0, &gpio); + if (ret) + return ret; + + desc = gpio_device_get_desc(gdev, gpio); + if (IS_ERR(desc)) + return PTR_ERR(desc); + + ret = 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 = __ATTR(export, 0200, NULL, + 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 = __ATTR(unexport, 0200, + NULL, + chip_unexport_store); + static struct attribute *gpiochip_attrs[] = { &dev_attr_base.attr, &dev_attr_label.attr, @@ -436,6 +550,15 @@ static struct attribute *gpiochip_attrs[] = { }; ATTRIBUTE_GROUPS(gpiochip); +static struct attribute *gpiochip_ext_attrs[] = { + &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; status = kstrtol(buf, 0, &gpio); @@ -461,40 +584,7 @@ static ssize_t export_store(const struct class *class, return -EINVAL; } - CLASS(gpio_chip_guard, guard)(desc); - if (!guard.gc) - return -ENODEV; - - offset = 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 = gpiod_request_user(desc, "sysfs"); - if (status) - goto done; - - status = gpiod_set_transitory(desc, false); - if (status) { - gpiod_free(desc); - goto done; - } - - status = 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 = 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, status = kstrtol(buf, 0, &gpio); if (status < 0) - goto done; + return status; desc = gpio_to_desc(gpio); /* reject bogus commands (gpiod_unexport() ignores them) */ @@ -520,18 +610,7 @@ static ssize_t unexport_store(const struct class *class, return -EINVAL; } - status = -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 = 0; - } -done: + status = 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) = class_find_device(&gpio_class, NULL, gdev, match_gdev); @@ -785,6 +869,16 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) return PTR_ERR(data->cdev_base); } + data->cdev_id = 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); + kfree(data); + return PTR_ERR(data->cdev_id); + } + return 0; } @@ -800,6 +894,7 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) return; device_unregister(data->cdev_base); + device_unregister(data->cdev_id); kfree(data); } From patchwork Tue Jun 10 14:38:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895359 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (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 7DC3C22B8AB for ; Tue, 10 Jun 2025 14:38:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566319; cv=none; b=KiOUc517zSJIS8j+ydcVNF3+Mq50CDkhavuHAsaUAhpThR8SurepHBHsYl/ET7F3gpc/z/a1OBxqC/M/aQ9T+howJnRdGiDsHrLST1VbItaE+pDjq9xIEz53frWORoCqg5ylSKrmeDkVZGT0iSJPbtk5nr8Otcm88Ub8vDPm2qI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566319; c=relaxed/simple; bh=d+Bxl0NSiM7UA5F5Yp7jtiVxMzixcYH43BuoVTlUtbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pfKTtP6ZbIFkq/Bp+fr0Git1mTWzC1y+vwzrvq6YBuzj6uPoZBHKkkEb0D8R0THCl34YK0SFASGSgOPBj4BOCQHCuR3+0C9f9codfBAmodWEMHuc+ioZMGwaYupzzSO/jabTrsDJoO1azvpH6f1NVCEEzxm7rGr4sjQB6TbjyNY= 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=LAaRMPM/; arc=none smtp.client-ip=209.85.128.50 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="LAaRMPM/" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-451d7b50815so48176165e9.2 for ; Tue, 10 Jun 2025 07:38:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566316; x=1750171116; 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=q7rYTyytP41wrzRonx/qeQvGqjmG0GLYCtZlfrWBrxo=; b=LAaRMPM/J71m7lqGbl+BGSmqrCU672zGAtGqQhNbukLXkcnpex/CEEy3nWzTbHHnEN Sn5+0Flumcojd/WLsQiON2qwAV7vf6HQmlOUx3ApuK5TylvrDdfpvRK8lg4/Ek4ZjsOY B/uDVWf/RmnRyUqu4FzA3g64hQKRC5FIT96RlSm6yOYyhKBeZzMNsErpJ1nQR7Ukw0FK 3/LXKRhRw1sfYZO48re6zE+2qBR/YeDEel0HNp3Gr9OfryhKHQwcEUhSIjb/uEcReHYF G1VkM7r1i0m66VfZYSpcX2+Cy+3/Ia56/vZdUj0vmYHeOMvJq1YJ3+wXeGa52z0Hdzw9 ojsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566316; x=1750171116; 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=q7rYTyytP41wrzRonx/qeQvGqjmG0GLYCtZlfrWBrxo=; b=qL7Hq761gRXiBCythq29kG41MKOYVumcYT8WrNjnX8mg2Qhs42vVGenn+K2RUO4GF4 w+xh6lbSV8Q56kLNnXGAWcDunPtGiikOYBP6lBaazaUDx17eqVSlEK0AEwfsF7pZY/3l Gyk6KyqoKzgGEWgXTlKIEg4DbbQk239w3kwxMflZxQb+ZkTAJRzlrk0tAM2X1R+Zop8V t7sSw0dRxEy543TN83xxHGrxLMxmfuodtDgGz7RK6TitORG7siqXL4gfxPHCta38niIL mnWCOwsHrRYloTbAX2zFNFrKEogErkkmwdKWjtARtY5erYlbXeL46YyoJaVJmIEYU8jA ZwYA== X-Gm-Message-State: AOJu0Yyd220U7Zdf//t3ezTA1ZCp5XpdDfTC1B099XGgJGFDUbnpt2Jc lYEW8R35j6gcG5T5iZu439BvpasPBFpJOvu42y9nNCs57KGSyDtxfnGF2J3NHFkBk/aAFiqN8+0 WQ+Ys X-Gm-Gg: ASbGncvuj3G2h8GiyCX/sqBr2Vz46Noee140Ugfjj2vSmcNTbJePDf7cCIALjZh4Qvl imxP17dmc3Ec2tJjf5xvuz0RQFBXKmb+Gr8EYC+WAmHVnC/MNYXWAJEbaEpsGGfahRMh+frJV4x 8W5aZZzelhBBtKznM13EviVb983OVuyHKwrj3+cMpsJo6lnqvUcLfWV184UPuWI6/TQrarLniSD pbXJz14+SmC3qNUc7SsMoNlIYy07WJd02AxwUVWRVwHne9otpwEjdNKewizRgcrCorU/YevUq+O NQI5u5S5Kwx4xdDLbVleN0ZpQr47NKr7/frtnJvZw1Q0xP19aQD+ X-Google-Smtp-Source: AGHT+IFqsL6AQNgjHvVYwct1knCOR3BWEgK6/JlDG1gE359gCrycIIxTwv7hXlhov+kj+IZkQ+EiqQ== X-Received: by 2002:a05:600c:5288:b0:450:d3b9:4b96 with SMTP id 5b1f17b1804b1-452013916bbmr165982055e9.13.1749566315808; Tue, 10 Jun 2025 07:38:35 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:35 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:23 +0200 Subject: [PATCH RFC/RFT 08/15] gpio: sysfs: only get the dirent reference for the value attr once Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-8-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=3042; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=TO3LbK7dPeG+FDRNFnBsVRIrM0Iiro3kG2oek3lX/7Y=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENhw51P2TaMhnBGwcf0wBuqFshm7H07M2gUq wktCql8YLGJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYQAKCRARpy6gFHHX cjlED/9HPFz5JqtJcL2ZD/+Ti6nEEqSLtmF4iWdyX4stOkurGwfrGeXibADRzBfPk/eO/xwznhL vmD2PMNmkristKf1FXxV9YtsbCsJUcwXePaiqqkIh/o63een8sSWcLPHCuWLUHR0SwSoG5IvMJA wckCkUnyKRoA3DTx/ARkJlgOqf0sPgJuwB2eq7mIcyaFS6NZdhjmt+fXuVuoNG6SvEfdzRhAVoG DM5rklTx0t+Ifm7xDvs+m/xspdpgLDJPJpPXenX5VMs5HbhGXbdqiN5roDspIsVRyU9DIDhhAJ5 KJSz0X/YR1mFBejmx13dvJs74B3vSdYWYVGD154lGMJz0bLrjyjqMq9G0zGXnfL+0zKLWSr8Jcc VuHMBMLKO0rpoYzSbMKU6fgIfbf7TVfWkHLlVr0L2tADV1QNCHtAU5hcrFAiZLtILngqyza3n19 IfdVZaema8GnDkJ9z0StGNeDFRTa4tfbHrO7mcJNLRSFDqppnqhpNORfuLQqNK0Rh6IOR3brliG khqPPFODOU/G2GWl2Ymjts3DyF4OmZntvCSmLin4UMwaE2/Mv4KKpVOyeO4MuYo223L/VeSdwuU vnRr80vwUgfmuyx7VdJ4mFB3N78nodwdySG/cXESClA9zm+ncAIt1lLzKKGqso6wTImX25aEIK8 flleW2TY850E6lQ== 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. Signed-off-by: Bartosz Golaszewski --- 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 a3403b963d6488aad24e47e9e28e0439676de704..642635c9f84bbd869727755e72781fae31a9cca3 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -36,7 +36,7 @@ struct gpiod_data { struct gpio_desc *desc; struct mutex mutex; - struct kernfs_node *value_kn; + struct kernfs_node *value_class_node; int irq; unsigned char irq_flags; @@ -156,7 +156,7 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { struct gpiod_data *data = priv; - sysfs_notify_dirent(data->value_kn); + sysfs_notify_dirent(data->value_class_node); 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; - data->value_kn = sysfs_get_dirent(dev->kobj.sd, "value"); - if (!data->value_kn) - return -ENODEV; - irq_flags = IRQF_SHARED; if (flags & GPIO_IRQF_TRIGGER_FALLING) { irq_flags |= test_bit(FLAG_ACTIVE_LOW, &desc->flags) ? @@ -203,7 +199,7 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned char flags) */ ret = gpiochip_lock_as_irq(guard.gc, gpio_chip_hwgpio(desc)); if (ret < 0) - goto err_put_kn; + goto err_clr_bits; ret = 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) 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); 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); } static const char *const trigger_names[] = { @@ -726,8 +720,16 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) goto err_free_data; } + data->value_class_node = sysfs_get_dirent(dev->kobj.sd, "value"); + if (!data->value_class_node) { + status = -ENODEV; + goto err_unregister_device; + } + return 0; +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) data = dev_get_drvdata(dev); clear_bit(FLAG_EXPORT, &desc->flags); + sysfs_put(data->value_class_node); device_unregister(dev); /* From patchwork Tue Jun 10 14:38:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896392 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B137B22E3F0 for ; Tue, 10 Jun 2025 14:38:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566320; cv=none; b=JZswsHw/4hGRKvSmV/K0L4pD3gDJnbAwZCcrwrJqUn5itBJiNRd0TsluVKcCj7cpAcSsp17S5CYe9ENQkIy82JdsyAYKPNxW4CZ0ghprCD+B9M5NaLqmfplZ4mGNYQS8xnUREr9c8s0dDc8O5EvDF+HP/VJGyFGy8uwwePHKTts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566320; c=relaxed/simple; bh=XNu9jNKy3ua2IQdVl9HbAC1d2wbfpHsCqHYoaysQ5uQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Mnc/4VlYBjK+CaIbk0ClvZO7V9a+g2RsWaxa2zEieKNs/E/avIRRy4cZPMknjMnj6OT1vCqwwvjwAo/2Ijq+oNgJHMHr+F6ZE9logtuqOb7XR2t6FOPcHfM0+tauBH6JOShHipQZeO1nvPUU2tp/81RrCJg0TFH695DIZIDSgKY= 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=WNJie4ML; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="WNJie4ML" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-451e2f0d9c2so43429955e9.1 for ; Tue, 10 Jun 2025 07:38:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566317; x=1750171117; 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=YajReGdgQoE1Z/C7Wj+XydGRMG4Oa8NkzwnsH8hrzWI=; b=WNJie4MLE073hSfzxzaBj4k9hNKxypKcMK3dh2fNcaU8V577bxSSO1H/6GFAUClsSs S2HxsZKoPziw5IS0HxXDPCurlKL6uBBZXSvl5/VYSlZKJtzLeZ+6tUxoy/zW3WLF8bW2 VqW6dWVUPQPk5UuFpaYq5rFl9amWX3KnqJfesVs9isAHTR/+RACyAN7beH5Ibj+gYFib HcSkWV96KStJZ4vOfw8TgFHvt9fSDf+SzKuBam8x9HA6B8jN52GsNfYHD/vTDPcSXgBN HY9wY7n5SszZu1Nc4nVFoKTRZe8pJ7vl5FtfVNbWooq9Gaeap2iWvcfA+nOcjFlHlxKD trPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566317; x=1750171117; 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=YajReGdgQoE1Z/C7Wj+XydGRMG4Oa8NkzwnsH8hrzWI=; b=k6JSiSSNUcfGeKUjBGWbBMr5OBhrwVmub/6miaw2ZmNOmz6j3o9fZK6lWR/fufj5zM Zr6t0LoJUXOZkv0p5CMA/4swBYUlgz1t1CSCnK+9VUy+sXoZU+PpNnZ+dDF7PlitVk+9 a8Ig/wM+Koitz8OaZpoSOhACpS8rCeeUX2Bik9wL+ZN36xuuIcyFr6iuYVIEsFHpYadK r6oCJkCDiZ6STV1LUHs7arPeBDUpAxfslmoTzSFn4ZIW1QcP/8UUmDdR7IO6NzSSXn7G 4aqzn7yVjy1ykiTyCOm9rIU732X3yE48T5eme4w3j2CjML7+31mk5YKlBkfraze1HqD1 Urpg== X-Gm-Message-State: AOJu0YzC6EQnmNqsnpuDQ7BwMrqmBPYTudlv37d2e1Mhz1bqApANLwbL hspByCM+43jLNzyIgBG2pmV6ULLNrF2Bv5Ott20buhKmzGe4FnhbbvZnuIgSXPb9Xjc= X-Gm-Gg: ASbGnct7oAfUJDA4JF5eTy6k4weGCSlh8qn2ryuP2KfCZK9mjW977xgGwVy4uWIVknz cueaAd2ibNUctJxS+0jhh/opGPPbD2XpODeaSxJedL3Mua5HcTk/EtTUpI+Xw5QP0CM76v6Iprc oggGJNXzfN2A9LzJfn4fy3WJtAWjRzmR/Y9OZVjsAi5Y48R/qJtavtdGRklg5FoWF2DBtOddmto JZEdxQEJwPFEjf5q84RbGL4OlomqifZzmtZxyfG10Kr8T0ZgbwA3C6RRi0HG+TKq+xm8X3M5pTX 41XLDC+WSWrPQaRVTeTO/SGuJii2k+SUwbdZrL8wT0z5gwdJnCyB X-Google-Smtp-Source: AGHT+IGpIgzg2zt99tcbqnYnzxYWTCfru7Fp0Z5Kk+LmJUDSRUBZVf/+DrtWRpMW58oPYNNscrudSg== X-Received: by 2002:a05:600c:1f1a:b0:43c:f509:2bbf with SMTP id 5b1f17b1804b1-4531cfe36dcmr39161775e9.15.1749566316871; Tue, 10 Jun 2025 07:38:36 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:36 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:24 +0200 Subject: [PATCH RFC/RFT 09/15] gpio: sysfs: pass gpiod_data directly to internal GPIO sysfs functions Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-9-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=3362; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=HrHcoKPsz+vmq5v1MUbvC7Htqt6DI5nn37F1yRAxQX0=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENhsMp/mzFFyPBKPP4HKjdQsItOwzPyi1qHt xuFIxJry2OJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYQAKCRARpy6gFHHX cmHKD/99QWLVXGKMbnwVeDhRJIx648P0hzrOJ+ygPg08yMj/6wswBGgohasJ8icD0oGMiRxywA2 /gDEDYT6HGozGJAfF/CUeBiiHNuxQ6hXbn6oaPAV+L3dEtO4z3vJwoic3R8tGWpf+Yo8tPNeJe9 qmLfujX1lLR0EdFtsIKcsdUKkRw4tpb8RvuUz6jJV9SkMQxXD7fzfXK1vxWYdXJwnNJJqMzwYPk twYgL8k4XnJ1sAcjIf3Ik5RM5b+X3b7CIjsTkQr0ArrXTFYxOBXuy4QN7ZgwA+NXl9EkyIbGD4e ji+bm5YZ5KQCfJ2kfmMisgHOTloerMQz96P6e7NLoPEupihblRzQ7lCn21aRNKDXLFJbG7Ng5A1 e4yz9EzO0cC0GF4Cf6jeXYhgMyUlLX3N4vw3ZVrLNSndAA/1Jzyn4KSxy8hDaX/+mYcy+BgIePT jrTwytSidulC5wAnl31PFRB1vBi2rr452ex1iUPWyYoPkWPUhFeM1RVNZijLPT9qrctFvit0TEz A9+mA9oJddx8i3DvD+ppA4Nkzoh1i3Um1/o1nCff1BTz8TOghR5ObJsF77AiVz4hjBFaHpSi0Qh ZO4xo6pPFbTG4uqxVBQXZTvjbSHSSXAcPDxGeVE+QRXlaJ6dOb5vSDOXhqPbR6wiLZpywUt0R8v TkpcFhPD7auNGVQ== X-Developer-Key: i=bartosz.golaszewski@linaro.org; a=openpgp; fpr=169DEB6C0BC3C46013D2C79F11A72EA01471D772 From: Bartosz Golaszewski To make the transition to not using dev_get_drvdata() across line callbacks for sysfs attributes, pass gpiod_data directly to gpio_sysfs_request_irq(), gpio_sysfs_free_irq() and gpio_sysfs_set_active_low() instead of having it wrapped in struct device. 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 642635c9f84bbd869727755e72781fae31a9cca3..811328c8e72d819bcd4b4215cda450c73aaa65cd 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) } /* 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 flags) { - struct gpiod_data *data = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; unsigned long irq_flags; int ret; @@ -223,9 +222,8 @@ static int gpio_sysfs_request_irq(struct device *dev, unsigned 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 = dev_get_drvdata(dev); struct gpio_desc *desc = data->desc; CLASS(gpio_chip_guard, guard)(desc); @@ -278,12 +276,12 @@ static ssize_t edge_store(struct device *dev, struct device_attribute *attr, return size; if (data->irq_flags) - gpio_sysfs_free_irq(dev); + gpio_sysfs_free_irq(data); if (!flags) return size; - status = gpio_sysfs_request_irq(dev, flags); + status = gpio_sysfs_request_irq(data, flags); if (status) return status; @@ -294,9 +292,8 @@ static ssize_t edge_store(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RW(edge); /* 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 = dev_get_drvdata(dev); unsigned int flags = data->irq_flags; struct gpio_desc *desc = data->desc; int status = 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 == GPIO_IRQF_TRIGGER_FALLING || flags == GPIO_IRQF_TRIGGER_RISING) { - gpio_sysfs_free_irq(dev); - status = gpio_sysfs_request_irq(dev, flags); + gpio_sysfs_free_irq(data); + status = gpio_sysfs_request_irq(data, flags); } gpiod_line_state_notify(desc, GPIO_V2_LINE_CHANGED_CONFIG); @@ -345,7 +342,7 @@ static ssize_t active_low_store(struct device *dev, guard(mutex)(&data->mutex); - return gpio_sysfs_set_active_low(dev, value) ?: size; + return gpio_sysfs_set_active_low(data, value) ?: size; } static DEVICE_ATTR_RW(active_low); @@ -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); } put_device(dev); From patchwork Tue Jun 10 14:38:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895358 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 81CBA230997 for ; Tue, 10 Jun 2025 14:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566321; cv=none; b=ulWWb44pth5B+k2AeyQcA8di2vHVt98yDEqhBYJEOIYrwNcvFVtXwICYQlgVxctVx+cEQ+325vyEGsBJuFb/LzefSBIzeeYXzA/rdwzo8194y0Lgw2l4N1Z6r5ahXYYWcdz4tn/ZhxqRI9720syypPutRrJeC/LIBs0CAumSVh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566321; c=relaxed/simple; bh=b8EHdhj3xnw5oclyrVliGAMrvB3IqzLhHzIVXS5RyUY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hZ0TROcAmtKyscqxQRQl/d8WuiQ0c3Au3TcuxU0f2vevVX3lpZW3dhp+giyZs7Dq0vqzm4LLw6keopD7qUo8UnYcD9AcWb8aizwgKAlq2/JaGIXDJiCzsfqXV8knRsoocu43x4qfI4sr6CUAdCMj5Mk5i1Ynfv2iZyF1/bTAIO8= 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=qBqAbxDd; arc=none smtp.client-ip=209.85.128.47 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="qBqAbxDd" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-442ea341570so36527025e9.1 for ; Tue, 10 Jun 2025 07:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566318; x=1750171118; 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=DoP5RvFV2ifyJeEVAaERNQ3+MFbOQYYVwQX6PDXiIlQ=; b=qBqAbxDdPFTy4olUPn4qNWjI68X10BQQIp4ve4+argyWR6M5sfpRDF05psxTOQ5roj Z9b4TnjtDvtjhttU0O5CBZPLyEptChtFYhkpOTY1i26rotIMuYR831imqA1iP6r/cRva EuhjfkQ3l+zebsQHsHEEjmjKXpiyGMYbtrl2KzXsFquTChByLcn7e/ue6x791yOvfUwK 9ah7GT+onMT4gBQ5/X/8BAi9VRaDrrX65SOEpZBFMWBZTo/WpSI3+EoilkDI2CnNgxCn 5PDKClUuZGc/Y20Tq/Rzv0zllpET6yNp1/FGm0eQ6a52OCokQTcwwQjlE7JruAEIfBwq vUng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566318; x=1750171118; 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=DoP5RvFV2ifyJeEVAaERNQ3+MFbOQYYVwQX6PDXiIlQ=; b=s8FQn9Ka2h7t+8aW/imVkmmg0fdnaJngwVVfpoQuFl6RFgZnyBie2TQADz8rYNDKT1 eRAmdra+SryiSzXu1L7C9saH4uZTOrjhu1quw6vK1JoxdsoEG9KL5bQ2J1sKkpSPQ+oG gZHU2r1fXvbx+3+sMdxlY1igSkfnGyanfXzorIsowUCBqijZIvEP037ndyB3GwunH2L8 rXvNMtgyu0osA8aEjfM4ncpNin3oyqnCG/JM5kgDLt3a1kankBrP/h/PIFMcpTd46Rve 3GIwt59WLloLsVD013r3y8LUQyq1GyiS56prhF+/shaLNzjy9abKbOZY9tBEA6CIMdvl 5BTA== X-Gm-Message-State: AOJu0YxagEe0LEIz390E20Ne1Op9nmeVwzvs4jW/CqzOdPr09ew+aPh9 /H3TZ5oP8x7K6eDaLlHlSE87tecmz6Kk0jl5y4pDi7zuwKgN6DeCaraq8wLa9obp7Nc= X-Gm-Gg: ASbGncsmOp98+PMuWNDTTgJDELccBtrNf6XwCV86WSA4IzHdfZzUPbl7htxIS18RzKj R3td7gGGSM6VPDlpMAbrpFjPik+4Ga3rWnpoI7m/5ufByFRaB9lQQ6o14qTvOEfjpsfnVZ+hNO4 HPEaSme1D0DdAqoCxPlEJ2Qkaw+43BYC2/osJxNlcZapT5Rlu95ubTjJqMOt+vLR0x86qnXMtNM gTYjJeKoL0//Whxw0WRw8Gi4nnMOWGwYRLklZiu9hOH/UwY2tQ+2BHHckfJO0wdfHLv9OjbJ4iu /sDwNcdRh/Jg8qkSkFEp4uK2E//VHbAuzBjFi60UN8YOpRDO6+uJ7m0lomAeayY= X-Google-Smtp-Source: AGHT+IFWC4RtUHSgUSrUNgrZ7GSj5JevOQ4eZ5K4U/rexE1ZJ45Jp6j+/ZmPH0+J19iLtIt0zcwpqg== X-Received: by 2002:a05:600c:4fce:b0:453:a95:f086 with SMTP id 5b1f17b1804b1-4530a95f7aamr99365775e9.12.1749566317982; Tue, 10 Jun 2025 07:38:37 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:37 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:25 +0200 Subject: [PATCH RFC/RFT 10/15] gpio: sysfs: don't use driver data in sysfs callbacks for line attributes Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-10-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=9621; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=m4j+fX0TlGurRWTg2bXu1FuZz0ENTYE+Xi6kt5xTUdY=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENhJ8r6ge1uwoYf5B9C3sRyicujal3OEPAcs p909zNb5/WJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYQAKCRARpy6gFHHX co38D/9AWormvfd373nMekiFxkO3mL4uJ4Tf3tLh2azOSLvczM7Ph0T/HraKpYlBi6Ro8BmZVEj YlRjPNAsk/qRN7ap8x9uL77qrjWx3vujFjUq2LS0YB3FAOQtT4gXCusQVx4TeNhk6VInIzGgEHi fQ/gKRx/5Po0wQZvKZFgyRxNJN9TXTGGIpnLupZrXiaQEjNu10vvQ7/j23sTQDWrytwKziUjyG/ Xlp3zyhJFRV/g7aYnJZkTQ4Ghk9lFIJfH4BsZFbEJ2zoY0nesGqDdlbicUVl+D7mL/GSC9vs/jU 1VPYBqqASDJlZjc9IhNC2RS11AHhF2O5UUc6baN6H6/pU+N05lD0XNgEOUqqHsP2YFj2y2+lPQ3 n+3u7kS8YgmAknMus4i3IwHEkyls4eMGNfzqBZ3TJTu2e2zEqJ1G0N20cyrXOnOVSQnO0HVy9rS d1l44ua/4CPE0d/CBKAPcRQDhqpdfgghS4BaBqPvqG/sim+Sf2tQZFqATSvBs7euXTKsjHC7dyh EGFKWrrFvrPx6b06imENissuCkOuo5qhw57AR8hFV5u6AUQC0/8uCnPYH8AyVdbahSj/4YFvvMR f+euFGQAYyHpaZ0N4O+WBq9yPXjaipugserq+LbGXWf/B2d/U8JI1raS8aZCGiTn+LN8tGjBalo bO4bJMUFAdjCpbA== 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. 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 811328c8e72d819bcd4b4215cda450c73aaa65cd..03e97697b7f26a8aa9f527f25f048f25588f3ca2 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) +enum { + GPIO_SYSFS_LINE_ATTR_DIRECTION = 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; @@ -41,6 +50,14 @@ struct gpiod_data { unsigned char irq_flags; 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]; }; 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 = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + dir_attr); struct gpio_desc *desc = data->desc; int value; @@ -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 = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + dir_attr); struct gpio_desc *desc = data->desc; ssize_t status; @@ -112,12 +131,12 @@ static ssize_t direction_store(struct device *dev, return status ? : size; } -static DEVICE_ATTR_RW(direction); static ssize_t value_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct gpiod_data *data = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + val_attr); struct gpio_desc *desc = data->desc; ssize_t status; @@ -133,7 +152,8 @@ static ssize_t value_show(struct device *dev, struct device_attribute *attr, static ssize_t value_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct gpiod_data *data = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + val_attr); struct gpio_desc *desc = data->desc; ssize_t status; long value; @@ -150,7 +170,6 @@ static ssize_t value_store(struct device *dev, struct device_attribute *attr, return size; } -static DEVICE_ATTR_PREALLOC(value, S_IWUSR | S_IRUGO, value_show, value_store); static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { @@ -247,7 +266,8 @@ static const char *const trigger_names[] = { static ssize_t edge_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct gpiod_data *data = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + edge_attr); int flags; scoped_guard(mutex, &data->mutex) @@ -262,7 +282,8 @@ static ssize_t edge_show(struct device *dev, struct device_attribute *attr, static ssize_t edge_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) { - struct gpiod_data *data = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + edge_attr); ssize_t status = size; int flags; @@ -289,7 +310,6 @@ static ssize_t edge_store(struct device *dev, struct device_attribute *attr, return size; } -static DEVICE_ATTR_RW(edge); /* 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 = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + active_low_attr); struct gpio_desc *desc = data->desc; int value; @@ -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 = dev_get_drvdata(dev); + struct gpiod_data *data = container_of(attr, struct gpiod_data, + active_low_attr); ssize_t status; long value; @@ -344,48 +366,34 @@ static ssize_t active_low_store(struct device *dev, return gpio_sysfs_set_active_low(data, value) ?: size; } -static DEVICE_ATTR_RW(active_low); static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr, int n) { - struct device *dev = kobj_to_dev(kobj); - struct gpiod_data *data = dev_get_drvdata(dev); - struct gpio_desc *desc = data->desc; + struct device_attribute *dev_attr = container_of(attr, + struct device_attribute, attr); umode_t mode = attr->mode; - bool show_direction = data->direction_can_change; + struct gpiod_data *data; - if (attr == &dev_attr_direction.attr) { - if (!show_direction) + if (strcmp(attr->name, "direction") == 0) { + data = container_of(dev_attr, struct gpiod_data, dir_attr); + + if (!data->direction_can_change) mode = 0; - } else if (attr == &dev_attr_edge.attr) { - if (gpiod_to_irq(desc) < 0) + } else if (strcmp(attr->name, "edge") == 0) { + data = container_of(dev_attr, struct gpiod_data, edge_attr); + + if (gpiod_to_irq(data->desc) < 0) mode = 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 = 0; } return mode; } -static struct attribute *gpio_attrs[] = { - &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 = { - .attrs = gpio_attrs, - .is_visible = gpio_is_visible, -}; - -static const struct attribute_group *gpio_groups[] = { - &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(&sysfs_lock) return dev_get_drvdata(cdev); }; +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 = name; + dev_attr->attr.mode = 0644; + dev_attr->show = show; + dev_attr->store = store; +} + /** * gpiod_export - export a GPIO through sysfs * @desc: GPIO to make available, already requested @@ -664,6 +687,7 @@ gdev_get_data(struct gpio_device *gdev) __must_hold(&sysfs_lock) int gpiod_export(struct gpio_desc *desc, bool direction_may_change) { struct gpio_device *gdev; + struct attribute **attrs; struct gpiod_data *data; struct device *dev; int status; @@ -709,8 +733,26 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) else data->direction_can_change = false; + gpiod_attr_init(&data->dir_attr, "direction", + direction_show, direction_store); + gpiod_attr_init(&data->val_attr, "value", value_show, value_store); + gpiod_attr_init(&data->edge_attr, "edge", edge_show, edge_store); + gpiod_attr_init(&data->active_low_attr, "active_low", + active_low_show, active_low_store); + + attrs = data->attrs; + data->attr_group.is_visible = gpio_is_visible; + attrs[GPIO_SYSFS_LINE_ATTR_DIRECTION] = &data->dir_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_VALUE] = &data->val_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_EDGE] = &data->edge_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_ACTIVE_LOW] = + &data->active_low_attr.attr; + + data->attr_group.attrs = data->attrs; + data->attr_groups[0] = &data->attr_group; + dev = device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), data, gpio_groups, + MKDEV(0, 0), data, data->attr_groups, "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status = PTR_ERR(dev); From patchwork Tue Jun 10 14:38:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896391 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 A4583230BF1 for ; Tue, 10 Jun 2025 14:38:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566322; cv=none; b=eQO/l5c6QYPTM1VTZgMJwDdQzCl8XL7QCUcCmHn34p5ouIhIIvUyUGonFyype2e7ESPPS2+WWXbkA6lkidEqs71lcVz+V3OiZVR7NKIchnIaA2I4teiNOnQSXdu4O43MQGqsoSkOLUabaLSbQaLI49+CyqP/tW7W9Vrny/ohX1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566322; c=relaxed/simple; bh=f8vXK6IWliyCN7vPGg3hik7hmD2HLv651rEW3W10AHY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DSv1vPT1XHR7PVOGnx9n1EQosY5uFkQrf/ZtgBE27F+fDKvKvwrakW7NiqoR0JG5Ovoee8wOHuadf6k18FjdSL7CmidZsYYd1lYuzeQS9lOoMBF9F6AHUg3FV3NBcuuhczwfrNGvcSFxATIkIXpMUST21cigdK/bn0zAzSbu0kg= 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=uAZ6oma5; arc=none smtp.client-ip=209.85.128.51 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="uAZ6oma5" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-451e2f0d9c2so43430365e9.1 for ; Tue, 10 Jun 2025 07:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566319; x=1750171119; 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=glk+vyiBAA4mAU1wTyAmPtLPG2zXbkDr8YYuwf/YIQU=; b=uAZ6oma5c7i9kdbZXeThlXD1Hpa+2LtbSf67rT1rhN/ag5RpZk1j3WC4GyEoUgi1DP mmfrv1xvjdO0M9TWNQn+/SnK5AU03G3byLLL1bqK37kef9xuPiJJuSK7dMXY6sI0COVv rRcohPpnn8WH09UWHFAiNFT+MQAUV2p5wZ2zQ8byxn2jY+/SDt2zYvw3H2JGgiCYvRqe xph93R4mOnzvSdTeYZc9hgU3bon96jBqQG7B8F4/AHPlPbLz17w7bL8Lf7+lW5MqUnNE m+DBIZ/tCa8NW1kvC01UlM28aRoGQb5HYPyUm7P1iKDqxh1N3dR2uM57tW10BFYthzsI TNDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566319; x=1750171119; 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=glk+vyiBAA4mAU1wTyAmPtLPG2zXbkDr8YYuwf/YIQU=; b=sLbDSCb9lAY0BNgzcuprbFZ0nzFkOWSlX9w7swlrlCY2ECbsNFpQd0BNiC0gPLqXkD gOFuHA/EFsYnICTES9wUrIJDYBNjrjMoZPXfXsYMrdZiM1wGcRV3/XXiZO9BUWcBFfkt SlOlaGWVrtbyz19Qoali9CsJTgwqZY5h86nLW8rKfvmv2sEX77i7djE/bgPx6TICmVFq chT+9oIcQ6qNHbFi9IT+l6FWt5woJWH86JHhvFTuQgK2PdiWTgCDqAbkcU+c6dk8+YEI uuloJOnVCIFtq9KuFv7MM7dqaKhrHfKsZNI8aX66HtBqEWhK/WrLy2rS08PDUc3a8Vh9 wfxg== X-Gm-Message-State: AOJu0YwO2Blu371fb3OZRyeK8jQ7UBYTRB2oh9qiOgT2epzQWHp2420F gy/3FPYEv31N4ZQnG6ZrafUuEcL+VFYr4SHu3Se6G+Q+6dITmqle1e+Sh2ttNph+i6bTvZAIrb1 guYag X-Gm-Gg: ASbGnctoBtzChnltespMF7PeaB8DzDMWKUYS5xvTM6qwN2PvpAQtqFzwjpQLSnjnPDg ZHcg9lfeI4vppGP+SrnwUzCiGAeLKlU1PlM4HH1QEHDb913+AJd1H2CAeP4KPeO784VkN5vFrbB Lt3BBTmLf8U8fWHEmpWYtLGyAaXtAbK0GwmOkYWUMcK+YP6N6J+2twkZeM/pnZ1CyW8H6Y04oxJ QSy2F0cbj/soDv0OhPrZ0I+OgVKjLmJRCDZi3x2fbkLaHJD+d4mMoDQAwPCqUQhDWHoAMI1LvVK zDCpa+r2nASxjNL4IQXfCb4CyLiA5ZPtMfWI5b36PpNl/Mv17yTg X-Google-Smtp-Source: AGHT+IEyoPj/GMY9Uv2pXheakyegmw+fR6j4iVJ2c4+Mt9PcfBd5RiW/KY86czU6MmLDuAepAM4AIA== X-Received: by 2002:a05:600c:48aa:b0:43c:ec72:3daf with SMTP id 5b1f17b1804b1-4531cfc4b6cmr23314475e9.14.1749566319006; Tue, 10 Jun 2025 07:38:39 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:38 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:26 +0200 Subject: [PATCH RFC/RFT 11/15] gpio: sysfs: rename the data variable in gpiod_(un)export() Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-11-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=5053; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=pyuFXLHeJQgyNgRtVSVy026dbWuIhqUgk4nMl8aRJVE=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENhjVjamXFfTOWvNWhGxnm3SYo1DdXM3SlUO I01zN4+Ej2JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYQAKCRARpy6gFHHX csJhD/41uNfEdZ3tRMC75zzp4CnhiXrt46FBQT4psqdelXp98bVEkOHXgzmXYZW5Ik0AY7EST3f 0VQ5IW7Dh0cu4/kLyfMNYKDhqj5fKYL8E81zyQXDrfB2WBLx03PlacQELN4/z4jnWEAYbTWRPFN YJlyLUCtjTJx8JsBByzDPc8VyYrtfvUh4Gzk+Mwh5uM1eZPnDln6HUTh2Ag+389nCJk6JyO2bhv z4qSqM72/dZHtlv3txUeEQ6j8HQKYfMi2nF1lvM6nbkJJfQxYsAJYmzRmQwp0ibv/yFbpiu10Wv lYOfsdXddY9ou61+KgWNBIHsgiPG3b3eJHNqsI7XCA2EcAvhvuJ7FlZWEpwIeMFiYOBf2BMOSk8 CTr6o3UmvZm8v5UALKEi3HEcg59EiVMg8AgwbQ9IRSlm6AVtrWx0tpRn4IGXeX2wm5yNGiVY4xN 0tsDvn/9gdADIcIakQkmpnLjA5vpJSI8EnFwz1VXqwEcZ3Zc6bs/8qjPFNPWPOyl1HIUSbJu1H3 HjU7W8fxe26v84T3oQmPCpve6BPPKBZGxbxhQ1M+2gUIXk5HslIXkYgQSPgC6yDvJfuz2STQ7L/ sDX9cxUN+B28QnwN/Tm8uH9gNtQBRFzQnwIvziL/X1QwsB9xYwtHWLNNGscjIlmjGZ+lbOyk/gO yVyxBk5mpjlvrPQ== 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. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib-sysfs.c | 63 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 03e97697b7f26a8aa9f527f25f048f25588f3ca2..398cefb4be9e389a820dd53f79c82fa70783b5e0 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -686,9 +686,9 @@ 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 gpiod_data *desc_data; struct gpio_device *gdev; struct attribute **attrs; - struct gpiod_data *data; struct device *dev; int status; @@ -720,47 +720,48 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) goto err_clear_bit; } - data = kzalloc(sizeof(*data), GFP_KERNEL); - if (!data) { + desc_data = kzalloc(sizeof(*desc_data), GFP_KERNEL); + if (!desc_data) { status = -ENOMEM; goto err_clear_bit; } - data->desc = desc; - mutex_init(&data->mutex); + desc_data->desc = desc; + mutex_init(&desc_data->mutex); if (guard.gc->direction_input && guard.gc->direction_output) - data->direction_can_change = direction_may_change; + desc_data->direction_can_change = direction_may_change; else - data->direction_can_change = false; + desc_data->direction_can_change = false; - gpiod_attr_init(&data->dir_attr, "direction", + gpiod_attr_init(&desc_data->dir_attr, "direction", direction_show, direction_store); - gpiod_attr_init(&data->val_attr, "value", value_show, value_store); - gpiod_attr_init(&data->edge_attr, "edge", edge_show, edge_store); - gpiod_attr_init(&data->active_low_attr, "active_low", - active_low_show, active_low_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 = data->attrs; - data->attr_group.is_visible = gpio_is_visible; - attrs[GPIO_SYSFS_LINE_ATTR_DIRECTION] = &data->dir_attr.attr; - attrs[GPIO_SYSFS_LINE_ATTR_VALUE] = &data->val_attr.attr; - attrs[GPIO_SYSFS_LINE_ATTR_EDGE] = &data->edge_attr.attr; + attrs = desc_data->attrs; + desc_data->attr_group.is_visible = gpio_is_visible; + attrs[GPIO_SYSFS_LINE_ATTR_DIRECTION] = &desc_data->dir_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_VALUE] = &desc_data->val_attr.attr; + attrs[GPIO_SYSFS_LINE_ATTR_EDGE] = &desc_data->edge_attr.attr; attrs[GPIO_SYSFS_LINE_ATTR_ACTIVE_LOW] = - &data->active_low_attr.attr; + &desc_data->active_low_attr.attr; - data->attr_group.attrs = data->attrs; - data->attr_groups[0] = &data->attr_group; + desc_data->attr_group.attrs = desc_data->attrs; + desc_data->attr_groups[0] = &desc_data->attr_group; dev = device_create_with_groups(&gpio_class, &gdev->dev, - MKDEV(0, 0), data, data->attr_groups, + MKDEV(0, 0), desc_data, + desc_data->attr_groups, "gpio%u", desc_to_gpio(desc)); if (IS_ERR(dev)) { status = PTR_ERR(dev); goto err_free_data; } - data->value_class_node = sysfs_get_dirent(dev->kobj.sd, "value"); - if (!data->value_class_node) { + desc_data->value_class_node = sysfs_get_dirent(dev->kobj.sd, "value"); + if (!desc_data->value_class_node) { status = -ENODEV; goto err_unregister_device; } @@ -770,7 +771,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); @@ -827,7 +828,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; if (!desc) { @@ -843,22 +844,22 @@ void gpiod_unexport(struct gpio_desc *desc) if (!dev) return; - data = dev_get_drvdata(dev); + desc_data = 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); /* * 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); } put_device(dev); - mutex_destroy(&data->mutex); - kfree(data); + mutex_destroy(&desc_data->mutex); + kfree(desc_data); } EXPORT_SYMBOL_GPL(gpiod_unexport); From patchwork Tue Jun 10 14:38:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895357 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A4023231839 for ; Tue, 10 Jun 2025 14:38:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566323; cv=none; b=i1wOAbmFQrp5TkpYykS+vwmKT8RpFA5Vtp41LCYhlNDi+aUAv7NaLsYR9E4MHR0wT07M6BcJusBamsZhDX03sBYf9NrGw2lURAhe2Z98TnzGlwsv9Ia1HvahKi6H8SAKlmwTK+qhqC8DbcLci59Z0rRBtPuxJt/b7uqWWYs9sok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566323; c=relaxed/simple; bh=q0H9vMF6ivh6goehKpENG92UC29koS/f5ZnMtXBTzgA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D3EhNQoE/TorKBcwsiz6z06jOAiiHJlZpjr+JbsJs622bP0rqJsDKEnMFwaag1PVCuVg1kXIh6EwwMO2qW/NfqtrnIDBikk7CNxgvy9R1Y+Cvj0mtq7DkoFE08Imrj9ArlNSrrDQD40F1uFEWd8lDbQrhau1yq38rOkMiAASXGc= 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=lHI+tYRZ; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="lHI+tYRZ" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4531e146a24so5952375e9.0 for ; Tue, 10 Jun 2025 07:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566320; x=1750171120; 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=FfIhJyfA3DlBtdknD+rm+05KUKOC0Zc1LOEud9YByS4=; b=lHI+tYRZNlG8cPOP/YGneudD2vI1kDx+I2wDzUGjt0sBx8bpy01xyNZyRdOVcND8QI e1ELXztttT+f99xj/nlGmwWMWI07/GrOPNk+f0+EXvcNVmy0Rylk6naDz/dG7o7AP2kn q277lqbJlixPFLYpn+VZzFa8COrsIRuug7G6rh04NrLbqYwbf3xmJawUjt+GzqWypUcI 95/Bv2HcjK4LpUyrEd9vfwlPHh0vJL82LIaGE6Qt2HXnfmXQq3cWM5pUu965oAv6vZc0 8mmru6f7fOebd1dtnIV/VBJzmicG0SkC6GtcIbN1aFofsDOQEc6PVjUjdJHZwMdPuucs Rv5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566320; x=1750171120; 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=FfIhJyfA3DlBtdknD+rm+05KUKOC0Zc1LOEud9YByS4=; b=Q8jLvBjeerYczeGvO6d3JCg1dj3U2q++OwecL4tjaliZvDICgVyNpcJVEb79rLT2AY OfwaMNw/i0rM70Hgw8GqAeH+/GgFcsTEJSwY5ET5ezs1jcxe1fhIK7AwXUasthz6hmcl uwTGhd7/AnlW8s2zly0AkWIczFcCYQyceHlXSvwmkqELd53aEuAcF6tQUzFe1IARopn5 gykgt2M/JT9rB/wIneWqO9MQRsfBrvgn+32ZmrfgrSPUkZrC/PUcjH2ucXlakcH3fE26 NWqiMbEHEuZfS5C+WNkdWM6jCFBm+tzjjzx2dr3mq/ce4dGcjN32VlNChzJf4mzYHMZ+ Mc9Q== X-Gm-Message-State: AOJu0Yxx9nTPeQXFnfNDVV9pywBlw2DPAuIeJ8GTuGr8bFreB4ZCPO0k jttxDt+gkBSDK9z+g6xPjPlrfxQFf24unuwSXIcBOL9aaeMTnB+pHCUsHn1lQmbjScw= X-Gm-Gg: ASbGncsgNUyZ+adfvRPFP9nCatryCDc/wNuJxTwPozWQ5w5XqLh8xDC0nLdVuxWQtkE LbEe574dtOsgb4uM9kkVRKWvke8WQpxMmIOSg8oWM1t/dnOZpKcFlrwbgQgHyNG4mdqR5++LzYG YG+FWharfyhCoYn+zyfT0pr8X4YP5f1DRvEO6MKg3LUYiqNeqA500qiis2Tq25xWYDCkLYHtmKf DmDWMs7Px3WKU9tWyEBOikJhRRxeng0AVFrpZQTZW+2MG/lUpqYlSB2pz6QtGo0SoVZkDRTD8Jk LMpbC3Vl6YbgjffPXdDlENkN13yKWXF9fOJCeoVF4d6AmgPyS6VY X-Google-Smtp-Source: AGHT+IFpWLdFggP0LwP2I9yAkdR2cWTkQiNu95oixpk5MrpPkqWu+ChUzJJsd9csLWV8H4Sge9R48A== X-Received: by 2002:a05:600c:a10c:b0:442:c993:6f94 with SMTP id 5b1f17b1804b1-4531de00a37mr24535615e9.12.1749566320009; Tue, 10 Jun 2025 07:38:40 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:39 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:27 +0200 Subject: [PATCH RFC/RFT 12/15] gpio: sysfs: don't look up exported lines as class devices Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-12-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=4839; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=JJYGTProM8qofp65Sgg2w6wsQTPnuW1fKmETy8uZ+Pc=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENicTYjEct+c5k9wyAo1MIPKXpZGxcw4T9Yx SlW0jCeW4OJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYgAKCRARpy6gFHHX cuzCEADXq5qyQcAhrvMKpu8KmDyg6eeoFI/BReuz0O0PQmzJ2/oDQqXMTfCAALwjf5L86itq2i/ nhOYoiLWRlBuXW3t/a160IjSNdTUlcc22uJZ6oOhk6P6l7G0B7MJ7/NZ2U3ozB7s/+mzfc9I7qk dpLKcnvMy5msuGm6wiNLd3nsTWcMakds2BsBcs+jkNpF+J/SCoptikrD9kavWpjoGG3+EtckkEN wII5upubZymMDFODOk956tmtJAOgcrmb8GN1QX9NkB3iLZwx3v7LjBAahfvRalpxdoyENyESIZK lqKxf9h+4L/Jr0hSD+YtLKasIItTFo+pECzEXQdW0IgYP2S9c8Ovo66v3Xy/xhzJmjrY8N55Kcs HpBLUEsbU1ag8tg4+Yq9pjiBT4M+u2hFyJ01hRGJ9+qzl+OJZXTVxGCTLTOeNDJu62I75Y/PcLB hBYNu0lLCHKTEp/TuLJoXixAqTI16DyWA6W76CJXNjeZ2TNEAWr3RKXJnjyl1F4Srbyg1eNNiOf hshBNnvyHbuPWBd4nKp0jShhtFN4NEu2T/Uto3KLhv62Z/DLOEYmPTqxPz6WNcYJ7aRcfZxZ/bP rMqpG9vnMC4hVLikO4uvZWWElg7RvjOrr2EvS6saBOc6FgnqZ505+4grl38YTM3mBZi5LrtL22w WN1mKtoUuHWqiew== 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. 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 398cefb4be9e389a820dd53f79c82fa70783b5e0..aa998d9e96cce5d64784645eea73f987471c7285 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -43,6 +43,7 @@ enum { struct gpiod_data { struct gpio_desc *desc; + struct device *dev; struct mutex mutex; struct kernfs_node *value_class_node; @@ -58,12 +59,15 @@ struct gpiod_data { struct attribute *attrs[GPIO_SYSFS_LINE_ATTR_SIZE]; struct attribute_group attr_group; const struct attribute_group *attr_groups[2]; + + struct list_head list; }; struct gpiodev_data { struct gpio_device *gdev; struct device *cdev_base; /* Class device by GPIO base */ struct device *cdev_id; /* Class device by GPIO device ID */ + struct list_head exported_lines; }; /* @@ -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; /* can't export until sysfs is available ... */ @@ -751,25 +755,40 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) desc_data->attr_group.attrs = desc_data->attrs; desc_data->attr_groups[0] = &desc_data->attr_group; - dev = 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 = 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 = 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 = PTR_ERR(desc_data->dev); goto err_free_data; } - desc_data->value_class_node = sysfs_get_dirent(dev->kobj.sd, "value"); + desc_data->value_class_node = sysfs_get_dirent(desc_data->dev->kobj.sd, + "value"); if (!desc_data->value_class_node) { status = -ENODEV; goto err_unregister_device; } + gdev_data = gdev_get_data(gdev); + if (!gdev_data) { + status = -ENODEV; + goto err_unregister_device; + } + + list_add(&desc_data->list, &gdev_data->exported_lines); + return 0; err_unregister_device: - device_unregister(dev); + device_unregister(desc_data->dev); err_free_data: kfree(desc_data); err_clear_bit: @@ -828,8 +847,9 @@ EXPORT_SYMBOL_GPL(gpiod_export_link); */ void gpiod_unexport(struct gpio_desc *desc) { - struct gpiod_data *desc_data; - struct device *dev; + struct gpiod_data *desc_data = NULL; + struct gpiodev_data *gdev_data; + struct gpio_device *gdev; if (!desc) { pr_warn("%s: invalid GPIO\n", __func__); @@ -840,14 +860,22 @@ void gpiod_unexport(struct gpio_desc *desc) if (!test_bit(FLAG_EXPORT, &desc->flags)) return; - dev = class_find_device(&gpio_class, NULL, desc, match_export); - if (!dev) + gdev = gpiod_to_gpio_device(desc); + gdev_data = gdev_get_data(gdev); + if (!gdev_data) return; - desc_data = dev_get_drvdata(dev); + list_for_each_entry(desc_data, &gdev_data->exported_lines, list) + if (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); /* * Release irq after deregistration to prevent race with @@ -857,7 +885,6 @@ void gpiod_unexport(struct gpio_desc *desc) gpio_sysfs_free_irq(desc_data); } - 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; data->gdev = gdev; + INIT_LIST_HEAD(&data->exported_lines); guard(mutex)(&sysfs_lock); From patchwork Tue Jun 10 14:38:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896390 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 BFE8623278D for ; Tue, 10 Jun 2025 14:38:42 +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=1749566324; cv=none; b=sqPO9oIoVeObTEFOKAY3Ao72EEKVkjOBh5HDEmucmo1gX2vImo0f5nRfrCyAoTj3mWM//ZTQAkam+6kUHJWqt7pWrtFFB+hTQqw2RT4K+a3HkM36b8apJJa3wp2Bmp4QPxGwcnhB1O0VjJ2UNJYkU93ZVsifBupnJoTggVC1mxU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566324; c=relaxed/simple; bh=qVnEdb+boNEICwN7/DRVxb/irxrpifQ6wv99efHfC2Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NVDe/OY+TpauTnbud6Yx0ptVNu9jrwivGdqz0Cd+ewdcYUoHlfJ18O26Pip+SOBVtDlrOlaK2oCFGrXN70I+PdCR7NljGCUeAShfQrhQFq17WMapeSEjchf+uuTQSzxomIken+f1/kitIepTOeiv8aun6ZL/3LxFk1CdprBCrPk= 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=hvqNvHRL; 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="hvqNvHRL" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-451d7b50815so48177105e9.2 for ; Tue, 10 Jun 2025 07:38:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566321; x=1750171121; 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=1Cdlqvlk5WCptlmo2FF6frtmxR+pgET3/5DYOrxB4jk=; b=hvqNvHRLTh2WChBPxkmLLhNDmm5QkyFE7TsSTUTp44JAdR3f//LWil2lOxvqLPI5mF uTxWmQnVEtfo9Os70z6Pwh/Rp81ibn/7hti5PHcpV7mlnF82fMX2j/730iJgy+KS/+P0 vx67z4looaAdcbQKBPjdnfyvpq6553juc3V8e4ved53PvkKFe/BbbbrulVGyNC1YOeSE 8lh7tbkbV0juhuMrE/i6AZjeoSQQeKXxqatHOUKkyVurS1B1pgCgEPPovnISkrpVN96F KnIck5LhBAsP91CfpmzfuEmys4n8YfRP9hNHVcGch/Lv5nCfKQZhlGp4PTivLK5hLlYl 8hkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566321; x=1750171121; 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=1Cdlqvlk5WCptlmo2FF6frtmxR+pgET3/5DYOrxB4jk=; b=JYQDh5LuTT1pRo3b7aFtyl+cdwHa4oQQ8tUCENzd9EW1GApWeX8wgdnwOd+lmEXu32 SN8Y/7r86vrBR1We8jJlL4n8u6IqcwQhtxy0gg1zrDQehkMVVrc8nhandn9Os55qY4XH 2S+XJlLcayZGzBcc8YraJHJj2hXLsgDFQKUxm4lnORlCnfccYvia6WWknfnwcS8IcVdP XJTeKO9SUP0B6tP+lo1OvP86MczEtZpmw89xPcP0+pk7KPWsV0UxAMck+YdhYHeyZevm ZBjJGNBXsd4sUHdEl8oehz9VqHh0fNytVkPvdQl1W9gh3sTPOXxnMY3qcpHDIszrdDHU lAtw== X-Gm-Message-State: AOJu0YyRe6naX+cs2qExj5B4CfOIYpjOPwULcmC5mKhTLdGKIEwdGMUt WQF+Z6RXE+o+MWrF4hmT5tz/8R9auGWFNA31yNjWgPtiWQLqLQrJZfyvQLIE54umyic5Yt295uD UGojG X-Gm-Gg: ASbGncvqzB1YPSV5Kk2v4fYIgf6PuJG5eM1NG+xfJkNdFMtbALBBCMKnzK/vBpt05Gh ponwkc25Da/peFKAMFG4AjetDNxridR1Thfl9SZYB7qTGJii/bHzwWDuO4aV0E2eHxBbRC193zP x8wSlXD3DlVrLPB70rUUmTGXCB4+sGc1HtWPzE0I59mTdqNTffTTUiVdgASAnUjX+LHIGqhJRFE o/Cy3L5WjAu3tHtHyDfyLFHDN452KJatHfRg8+k4jDz96zoPNDRgQ283HU/mwMhiZU7plJUYbaK SAbx0wan2SM7Zw2UYIjbUApbVmgksDPKMUEvPp8ALXHyFJf3eUGg X-Google-Smtp-Source: AGHT+IFIsq70xx/8olAsnKRsf07I+3a74XBw8PpCIhG3o3iIHJGPEqV9s3fUbSbqiPnsLG7GW1+tsg== X-Received: by 2002:a05:600c:1d8d:b0:442:dc6f:2f11 with SMTP id 5b1f17b1804b1-4520140c5cdmr145370845e9.25.1749566321024; Tue, 10 Jun 2025 07:38:41 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:40 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:28 +0200 Subject: [PATCH RFC/RFT 13/15] gpio: sysfs: export the GPIO directory locally in the gpiochip directory Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-13-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=3803; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=vDsA6l8yJFZon/b6LVAymhVnSm8Df8uSF6oGQiN2TvI=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENiOhOzNKeHb6kIoo8Kkamhflhx2AE4hMYOi 5L9IVwuyj2JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYgAKCRARpy6gFHHX cvFKD/9xsCMmUpgjRG4IBY5rd2bX7OmzYthb1jg0WOo2Mtwy56PJBdmj+O3m1W9NHZx6XVuZeDK V1IAs6oGCVvAzyiD/PgOysXZz182kdMZ8yFSjtzDO2FMdtIfKXjlPmxbn+2RaokS+9hkTV6stvI M1fI5VxnLcq87VxNCuEW4g40eQUzD1zVPRGsqfYSgIahYFTrCXIP6Hi6BJUdrMY4yCDiBLXSIg1 QgYShoIC0oTPfxGpaAZgEDm/9OFEfIMsjSAejfiw/x3prrmcPdXnMEk7SjcbYAlnlks04/IlDF4 3e/oSbI8xc6+SaKu80yMlX7zS1uG5SIS+kYCd84/jduryliOt8OFtZxzP1JcZ0lLsTLWe4rAthZ cKey3A/rUXpmlhf2w4yHrD4hNQQxpT4Fo/AcQFq/P0+EZAYu1fSGBUJquHzmp3wRVIkk+o29k7b D7i+SflwrNM6zMLDG4XCWSXMY2ulY/VswDHLHoJNcniEGeQsrLF3YC2GlbAXRVr+CewiAM3tape /yELlwWtPv4tu9Wv07pFhw0tqpYi2KNmC75a5uOhQcn5/fNcmiZ8+nromrTswr4bD13c1tZBDkm HPAJXoCxqg46q5ike6tmlWIx2JYVIylBShMYtnLXfunNNbgpAo2XVDNzFl7x4IHsUTerp6CfnZg WboJtWX49JX0GTg== 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 --- Documentation/ABI/obsolete/sysfs-gpio | 5 +++++ drivers/gpio/gpiolib-sysfs.c | 39 ++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/obsolete/sysfs-gpio b/Documentation/ABI/obsolete/sysfs-gpio index f856e286051d6bfa4990660dcb25b3fdb27cd0f2..3212cf64f43b67b23a1ac17df025638a52a5bb31 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, not necessarily unique /ngpio ... (r/o) number of GPIOs; numbered N to N + (ngpio - 1) + /gpio + /value + /direction + /edge + /active-low /chipX ... for each gpiochip; #X is the gpio device ID /export ... asks the kernel to export a GPIO at HW offset X to userspace /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 aa998d9e96cce5d64784645eea73f987471c7285..d8c17d71d5458011d15bc4239bd4c041244da3fd 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -47,11 +47,13 @@ struct gpiod_data { struct mutex mutex; struct kernfs_node *value_class_node; + struct kernfs_node *value_chip_node; int irq; unsigned char irq_flags; bool direction_can_change; + 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 = priv; sysfs_notify_dirent(data->value_class_node); + kernfs_notify(data->value_chip_node); return IRQ_HANDLED; } @@ -780,13 +783,46 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) gdev_data = gdev_get_data(gdev); if (!gdev_data) { status = -ENODEV; - goto err_unregister_device; + goto err_put_dirent; } list_add(&desc_data->list, &gdev_data->exported_lines); + desc_data->attr_group.name = kasprintf(GFP_KERNEL, "gpio%u", + gpio_chip_hwgpio(desc)); + if (!desc_data->attr_group.name) { + status = -ENOMEM; + goto err_put_dirent; + } + + desc_data->parent = &gdev_data->cdev_id->kobj; + status = sysfs_create_groups(desc_data->parent, + desc_data->attr_groups); + if (status) + goto err_free_name; + + char *path __free(kfree) = kasprintf(GFP_KERNEL, "gpio%u/value", + gpio_chip_hwgpio(desc)); + if (!path) { + status = -ENOMEM; + goto err_remove_groups; + } + + desc_data->value_chip_node = kernfs_walk_and_get(desc_data->parent->sd, + path); + if (!desc_data->value_chip_node) { + status = -ENODEV; + goto err_remove_groups; + } + return 0; +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: @@ -876,6 +912,7 @@ 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); + kernfs_put(desc_data->value_chip_node); /* * Release irq after deregistration to prevent race with From patchwork Tue Jun 10 14:38:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 895356 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8D38233722 for ; Tue, 10 Jun 2025 14:38:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566325; cv=none; b=PYZOirPvaxvzVFiBMsZ/wuIuErTmLEq8ZH+PB9vNoQIEzEzRly8Nf63OdTlzpgQ+gskd9WkMYuOk4CwwUr1AoD7sy/3wQgJWvwNtfSzWh3K+IA6W13Xpvc0RjYEYgu5CIG9FFBUUKz+KGY2SPfZqwmEkN9BNFt/qTrIeuq9vMjc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566325; c=relaxed/simple; bh=Watgch6AAnT5evlx1x6CAOk8UpJc8xtNO01XfNMuI2o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=hJSSyuAFJoRkQ/bXF1wPLL9EPQGHLQkn+jp8Cy7Qh6tmPzrDGZWfTc/w3VlREqGyGbNk0y3g8Vz7GzAGvIFBfyCDL/qhS4+DJyaSWQqmfLDT9siKzqGYdeFvSSycXXpJ0vZEaeBPKHgzktBejk0l8iXZp6voG4trqqmF/hKZQQI= 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=VihMOk96; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="VihMOk96" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-442fda876a6so49549575e9.0 for ; Tue, 10 Jun 2025 07:38:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566322; x=1750171122; 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=wsQ5a66nxiBrUyJ22LI2OZPoXALxCX/O1hriuyr43zw=; b=VihMOk96mrjf/RRojZKr6C9raGvv3g9WDoXEAbIaYDp6CxOD8xs3gHnTUCljRC7mdU MPtqmvAv30uq9DrrG79fXVge+wYhu3fqJdT6t1TX/NDlcGvqzFM3oAJwfneluMEVwnrH 0Iw1ZNI9MurqgobOTlzCEqBVfcm9pnu35jvEKjw9VA8O38pVfUsAFcrGr/At0fpiZ0FL YFzckfPsUOuggRLz5OkYa66AkhvWh/M1wqgPD94Rp6Iv76uihaatSUBWWiimQAbRtcBp jFgDb692HuCdOLqikOj0rJxkAq9v/KwRCtLKxE24BbuDkoylXCpUHwaYTptsHKbellZy i4uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566322; x=1750171122; 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=wsQ5a66nxiBrUyJ22LI2OZPoXALxCX/O1hriuyr43zw=; b=eG6trxYVAz6luZFMmgmBhNtHjlc3Zj6U6DpWhE6ULskfxtCWkeTrLOUscfjeW+PkIZ ZODq7d1MrxeLuAnAyQUUtFnA2RE+vKlzRGHqfnlIkxDXJnxVbE4GyUgjNs4NUc2dbPtc GJq52kMEW5oMP6pnz4LhKVBlK+zpN5+Ts2bu61RHSQsooRH9vE4ixElOorDHvHdMfp6B 34T+bybEvDk22W4AP/0lx/Mn636w0B9vLmGqNBKM/u3OW+toZKKGqpHPB/+/FtkRV1SO 9boSZtJWibX/IWTW87wk9LuAwAEncjwBvDQJdyStRKxdh9L1hNFUYg0He6QpzzAmDFle iKXA== X-Gm-Message-State: AOJu0YyUm6BkYdFXy09L93AYArkt874+9I4YPbAAAa+zKXO4Wco/haET FOZjll0gm7q33aZtPKvnrTDLyOuuWsCHnfltGiW8Bx7cnjkdKzOR0AF7pg7Rx/WNhSA= X-Gm-Gg: ASbGncuoETYZhUdfbgFzMxhKEY3Xw8og3L/iA7idEeRyP5pEmlN/GQRLlGBb9FV3fa4 mLDj6CjGofVTVezR2o0I0JhWPVjTTG5d4Z5V7OehkfrVVE8h0H0W/QirfPilwuu5brCWAdnuRkW Xl8YTbmzmXEBTf5zxAHPov0tTmIZmBNoEtWgQk6GpfXhZuJ26kvDyx8UYo1hhHm2Q4/fwcoUe+2 FC1x9lpnvt0TFPzHpx4HIl74cPNnwm7WQNLLNahUj99RMzrldRhoDE4q+VRlDVS2HcJnzCL+Nm+ kga+u6x6L/u/3AU2l+yCSXoz4GcRMN0ETNXCHDxdK1pR8FFwEs0J X-Google-Smtp-Source: AGHT+IE8haVUbgBb1o6F7r1dAx2SJi/5/9lwUTGlQZmtpVP6Ody9yjja3A446e36G5k7v/fRBb1Nuw== X-Received: by 2002:a05:600c:6304:b0:43c:fe15:41cb with SMTP id 5b1f17b1804b1-4520137bacdmr169574645e9.15.1749566321996; Tue, 10 Jun 2025 07:38:41 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:41 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:29 +0200 Subject: [PATCH RFC/RFT 14/15] gpio: sysfs: allow disabling the legacy parts of the GPIO sysfs interface Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-14-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=7983; i=bartosz.golaszewski@linaro.org; h=from:subject:message-id; bh=SOXWhuriIiQ5+4UQM++qtdPxdjT23ycVoM7KxniJtek=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENi9jG+Vqt3t77PpikSk1CMstUoKh4xaAp5F iZQ7B/cGdyJAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYgAKCRARpy6gFHHX cioND/wM+j4euzloEqj7ceozEge48L5oRPc/ziCgn1H90E9ibzSCl6GCHm5k9YcQ1ZR/E8AHsmP rFXjR18XYCbnZiLjcuKDRryo8Jy8xmcy/HZxo054W0YHaAKe8lSyF1xvKYwToKADgBJnSFbhfUV ZC44YZHxGITR2dR9PIZ7LHGSH4QBMddPocgaxv7QwvMMSwU32ZcFr2mc9Pazlz6yJrQ8+aNtAxn 9zalmqVKNbWah33rRJHQ0tGFQyZbgFHQxGTxOEFBa4SgkOCBqb8yVtGoUOqXZIflsh5cOtveys0 M8y6AE1yAYe53inK7CczGBV8t5FIfaB22/DLhGeWlgokCNd7oNA5irid64MMxhznsce7+2MmzBj AXWWR6h6EMj4blmwwtGHSZWyTRadu3+QK+1F60+2oVXItkwuvWn9R0hJEIJhHc2m0faMhTEVhZU ++QeU65ar2Y1dx7AVPg76mr8n4aVnJLzcL3hWbeIR3m9qG6V9by5POMn2Aho90t6xy37v3Sdyt1 4yZDv+03+Eu8zrXAdNnaAA6wVgAfHQIbl6/J1s671aE9/xOuuAJpBJvyrFDI7EjJQl6reShCbpy oPCG99woe3gQYSpOS0typ9HJ0uGVQac2iMrd8LaZ09w8kIJj7oxZu/80IWHrU+N0vcqPAVy+/4+ TGaazalx4vE3k6g== 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. 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..d040fdd95ee4b19851057fbedbb023f277149c9c 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. +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 d8c17d71d5458011d15bc4239bd4c041244da3fd..48e1353f966837d46f00b552f870440097ecfe18 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -46,7 +46,9 @@ struct gpiod_data { struct device *dev; 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; @@ -67,7 +69,9 @@ struct gpiod_data { struct gpiodev_data { struct gpio_device *gdev; +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) struct device *cdev_base; /* Class device by GPIO base */ +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ struct device *cdev_id; /* Class device by GPIO device ID */ struct list_head exported_lines; }; @@ -181,7 +185,9 @@ static irqreturn_t gpio_sysfs_irq(int irq, void *priv) { struct gpiod_data *data = priv; +#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); return IRQ_HANDLED; @@ -416,6 +422,7 @@ static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr, * /ngpio ... matching gpio_chip.ngpio */ +#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 device_attribute *attr, return sysfs_emit(buf, "%u\n", data->gdev->base); } static DEVICE_ATTR_RO(base); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ static ssize_t label_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -548,6 +556,7 @@ static struct device_attribute dev_attr_unexport = __ATTR(unexport, 0200, NULL, chip_unexport_store); +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static struct attribute *gpiochip_attrs[] = { &dev_attr_base.attr, &dev_attr_label.attr, @@ -555,6 +564,7 @@ static struct attribute *gpiochip_attrs[] = { NULL, }; ATTRIBUTE_GROUPS(gpiochip); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ static struct attribute *gpiochip_ext_attrs[] = { &dev_attr_label.attr, @@ -565,6 +575,7 @@ static struct attribute *gpiochip_ext_attrs[] = { }; ATTRIBUTE_GROUPS(gpiochip_ext); +#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[] = { NULL, }; ATTRIBUTE_GROUPS(gpio_class); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ static const struct class gpio_class = { .name = "gpio", +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) .class_groups = gpio_class_groups, +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ }; 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 = 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 = -ENODEV; goto err_unregister_device; } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ gdev_data = gdev_get_data(gdev); if (!gdev_data) { @@ -822,10 +838,12 @@ int gpiod_export(struct gpio_desc *desc, bool direction_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); @@ -834,12 +852,14 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change) } EXPORT_SYMBOL_GPL(gpiod_export); +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) static int match_export(struct device *dev, const void *desc) { struct gpiod_data *data = dev_get_drvdata(dev); return data->desc == desc; } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ /** * gpiod_export_link - create a sysfs link to an exported GPIO node @@ -856,6 +876,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; @@ -872,6 +893,9 @@ int gpiod_export_link(struct device *dev, const char *name, put_device(cdev); return ret; +#else + return -EOPNOTSUPP; +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ } EXPORT_SYMBOL_GPL(gpiod_export_link); @@ -910,8 +934,10 @@ void gpiod_unexport(struct gpio_desc *desc) 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 */ kernfs_put(desc_data->value_chip_node); /* @@ -966,6 +992,7 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) guard(mutex)(&sysfs_lock); +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) /* use chip->base for the ID; it's already known to be unique */ data->cdev_base = device_create_with_groups(&gpio_class, parent, MKDEV(0, 0), data, @@ -976,13 +1003,16 @@ int gpiochip_sysfs_register(struct gpio_device *gdev) kfree(data); return PTR_ERR(data->cdev_base); } +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ data->cdev_id = 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 */ kfree(data); return PTR_ERR(data->cdev_id); } @@ -1001,7 +1031,9 @@ void gpiochip_sysfs_unregister(struct gpio_device *gdev) if (!data) return; +#if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY) device_unregister(data->cdev_base); +#endif /* CONFIG_GPIO_SYSFS_LEGACY */ device_unregister(data->cdev_id); kfree(data); } From patchwork Tue Jun 10 14:38:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 896389 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A920E234971 for ; Tue, 10 Jun 2025 14:38:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566326; cv=none; b=pgdiE30e2QUc++NXrD+zYXjAAf9jwq8IwdmLSJasIXsGaEk+oYREVZ8BHGCYlOI344UOPsCOyCtJbRRvrz2KDqEecib2wQNNH3QvcmRWZpTm6SuVGRueVcldHPls5hdMGQkE2BvPHx1GeF2H+RUtuyYWjJsjJ9/aGlrDdDAe7Is= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749566326; c=relaxed/simple; bh=n/8Q3QJmovEcO99W9nilHTg0Ks126Kz/UiSEWmyIYZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZWwmxvzxJ1PQ6mCqNLiNONFZX3olV8gTsiWlINqw4PPdNkIVO7XnNICDq/y/5F+7n9OQTztIFsrvm94x5BDSSRPiOFyvKHI0hxhh6UuW2x9qpCNxV3Adn7uh+32NF03LTneK63n4hfpidnA5kvs3KTU1SctgI7twLk1Wvik5CEM= 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=Ekiq1JCv; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="Ekiq1JCv" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-451e2f0d9c2so43431095e9.1 for ; Tue, 10 Jun 2025 07:38:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1749566323; x=1750171123; 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=cLj7DWR3g91ZC5MBjrvyVrHQMhHkaM2qnHIpKV16L3g=; b=Ekiq1JCvHvswu8hozMOOM//VX0g5EPJfeODi2ICyIXpdkxeyPDphdJAdFSVsfly/Gy KvZSPgSmoPOuYlwRB+8BFcWPkXpAEN+VhRiC+ydU/INWOhMG3OH5sqaBju2EvX3bilnD eFJeQbyd/x5J4eGMaCIH9uzk3PMTPftGDOz6VUCy6vyAUqhxQYIagFWif7Ps2ohh2nDV /hFM11+FocBju2hzPiRIWHazGjh6TYIUSRI13pGQOGvyuzNkN2rH1A+0rEEkUAGXfBYw nox7aSpwF/nRh4uwhgrJi7gntYs3SzIWejeIhJdrLhCt+wC8dfmuvstRXHf8c2QNBVo6 lfMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749566323; x=1750171123; 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=cLj7DWR3g91ZC5MBjrvyVrHQMhHkaM2qnHIpKV16L3g=; b=Ir9xR4wVUKvFzi3TLzdZV4JKJSvc4c7ufYKdRmR82dRXX7p7pW+IvuSYXQH0y84x4W eJFjSWh20vClTtZjA/gto8l2lYAzDmz7SoXz9VbGeNaVMqjR0ub0UeG0qClUdv9p11wX 5yEA1VycZUltck4/hDNGsz3ou8wvcVKLyv/0rqEXL+jm3ZH6yT+ky0jE/xc0CBQfHgrZ A+K3BmHqgIs9d3GW7TOwdK/o/GMMK0Z7rj6glGVjXW3QG1Rk3e8ImBBFza2jsmApUmOh l3fPYgx7iZYITpOR0PIKireM8GmT95ClduMsKXhfnPB04HmyQvO7JKC5fML1ehbR8cmG H2Dg== X-Gm-Message-State: AOJu0Yy3ce9gsRMLvzy4CbrLziAITOW46hRSp59jr+xC0TM38RmzjiYZ wogBjG7sMDPEJ0afOT0LcdXf93ek/In8ivfEHk2z0QM6ESYDiQ6MX6oY132+A8UdCr8= X-Gm-Gg: ASbGncvZN0u6aSwzGHfPECPnrEWiRMKQqHA7EatD0j+NWp95QfUBdYcWogGk46CBZRp LNdW638wbHngJIzfF6Zq5jv2KFeK/eG3BHaMetyD398ftxZPnboikvIcXUzRdsyrWvDGky/5cUN w57D90dV0QkWAhqL8bVGuNACE9oN9bQB2/OOIGmC6I0O+WQqYsOEpFWSmTMu7DO7V67A1I8p2JJ +9Weg2UmrzUyshrt6tblAbZa4/XEgW5xQt5TrqJUYC3bFspxJsYEyBUcQ3qDs8QNXbBBAXzrYT8 RUJxJ1QLyThcCoB52Rm0P9wFnRGiTQZ7YN2/5kjlYuXQiBjlrYKw X-Google-Smtp-Source: AGHT+IEywg6w59g2mx8KQEA5DxZqFCbrLHoGShus610IZqWOu2oBuwgUJ83xT3nNW0Y+lQlOhQKrdQ== X-Received: by 2002:a05:600c:6388:b0:43b:c857:e9d7 with SMTP id 5b1f17b1804b1-4531d6fdab8mr32062795e9.5.1749566323035; Tue, 10 Jun 2025 07:38:43 -0700 (PDT) Received: from [127.0.1.1] ([2a01:cb1d:dc:7e00:4d:e52b:812d:eb7c]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4526e056138sm146001345e9.5.2025.06.10.07.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jun 2025 07:38:42 -0700 (PDT) From: Bartosz Golaszewski Date: Tue, 10 Jun 2025 16:38:30 +0200 Subject: [PATCH RFC/RFT 15/15] gpio: TODO: remove the task for the sysfs rework Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250610-gpio-sysfs-chip-export-v1-15-a8c7aa4478b1@linaro.org> References: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> In-Reply-To: <20250610-gpio-sysfs-chip-export-v1-0-a8c7aa4478b1@linaro.org> To: Ahmad Fatoum , Kent Gibson , =?utf-8?q?Jan_L=C3=BCbbe?= , Marek Vasut , Geert Uytterhoeven , Linus Walleij , 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=FrDvVu23TJm5ghXSfiA8hCOI1OUNHhCK1w5KAsAVwJY=; b=owEBbQKS/ZANAwAKARGnLqAUcddyAcsmYgBoSENi73tPISvj0xD+HMTPCvZKJvIUOegaNu5uO y3wtnEYSI+JAjMEAAEKAB0WIQQWnetsC8PEYBPSx58Rpy6gFHHXcgUCaEhDYgAKCRARpy6gFHHX cvdTD/41qLITo5HP3W1/ezMXOITtIMegRdx3dV4RXRA0XYNgVnGdtIv+GtlOwW8GgkylTyZnOP5 Wfsrj/Up9MFtr7QGsC5a27m0Htw7fkUn/UVqRr7MeoQ8DvvfAk32r76O8EK8mjvPRTTUFVReoi3 uAf60JE6IClr1FoTU36dCKeB5xl49K1D0D+HsMd9uIrrqxlgSC15xIp0y56R8f4l1AnTR3WIedz YZL+mTTw2XSxnoUjO6wb2cwYRMKWurtH8qp3lS0fQEPKw3xT6OsfqfzOQLuDrvXX8LnJhQU4VT7 PIS05fVZHGPBQVv5wug/7MbgFAm58VZv6uYBK37niJVecMiKPda75xXiASpcQuxvhgB+QoqKUKz A7W3Lp0hqOJduExEimuvWx5A8A5DdhJXo5DrzKwUl1yCxYno1XOGe5G1VCoz4tl/85yUznOngXV A0dMBBp4KKarcZvL79wRTHRPYHEBnZOXmJ43W8+qdDT7mPPVDyDz3DQu3Nl36JXSyT7W7qoP1XI 4oWV9IpKkGBDrM3kDz4wIuTQ3pnN6NCOSAsTR+lY2bFJJYGMXwtTwBxODx4AEpGx160o1Tvb35O QrbS9vKZg9HXhdd8zpigNSaxAfBJWw53Koph20N01/y857F1eQEnkFPHXR8ife46VIAfPyoQAzI k+HcSd9LFpI0Whw== 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 --- drivers/gpio/TODO | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/gpio/TODO b/drivers/gpio/TODO index 4a8b349f2483a91883c74b07a43efb1462dbd377..97024925f14ab92b311741b0b7944acbddcf5c4b 100644 --- a/drivers/gpio/TODO +++ b/drivers/gpio/TODO @@ -183,19 +183,6 @@ remove the old ones and finally rename the new ones back to the old names. ------------------------------------------------------------------------------- -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 users -off using global numbers from user-space, extend the existing interface with -new per-gpiochip export/unexport attributes that allow to refer to GPIOs using -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 GPIOs in the linux kernel are meant to be an exclusive resource. This means