mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
To: "Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Subject: [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
Date: Wed, 21 Oct 2026 12:47:25 +0200	[thread overview]
Message-ID: <20261021-gpio-sysfs-const-v1-1-3d89ac247086@oss.qualcomm.com> (raw)

Replace the deprecated non-const sysfs attribute APIs with modern const
variants where applicable. This leaves out the attributes embedded in
struct gpiod_data as this structure contains fields that are modified at
run-time.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
 drivers/gpio/gpiolib-sysfs.c | 37 ++++++++++++++++++-------------------
 1 file changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c
index fc06b0c2881b9427c7c2e069047b0896156eda65..08f5149925694320a2fc6615ff7593ce439fd1a4 100644
--- a/drivers/gpio/gpiolib-sysfs.c
+++ b/drivers/gpio/gpiolib-sysfs.c
@@ -442,33 +442,33 @@ static umode_t gpio_is_visible(struct kobject *kobj, struct attribute *attr,
  */
 
 #if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY)
-static ssize_t base_show(struct device *dev, struct device_attribute *attr,
-			 char *buf)
+static ssize_t base_show(struct device *dev,
+			 const struct device_attribute *attr, char *buf)
 {
 	const struct gpiodev_data *data = dev_get_drvdata(dev);
 
 	return sysfs_emit(buf, "%u\n", data->gdev->base);
 }
-static DEVICE_ATTR_RO(base);
+static const DEVICE_ATTR_RO(base);
 #endif /* CONFIG_GPIO_SYSFS_LEGACY */
 
-static ssize_t label_show(struct device *dev, struct device_attribute *attr,
-			  char *buf)
+static ssize_t label_show(struct device *dev,
+			  const struct device_attribute *attr, char *buf)
 {
 	const struct gpiodev_data *data = dev_get_drvdata(dev);
 
 	return sysfs_emit(buf, "%s\n", data->gdev->label);
 }
-static DEVICE_ATTR_RO(label);
+static const 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,
+			  const struct device_attribute *attr, char *buf)
 {
 	const struct gpiodev_data *data = dev_get_drvdata(dev);
 
 	return sysfs_emit(buf, "%u\n", data->gdev->ngpio);
 }
-static DEVICE_ATTR_RO(ngpio);
+static const DEVICE_ATTR_RO(ngpio);
 
 static int export_gpio_desc(struct gpio_desc *desc)
 {
@@ -529,7 +529,7 @@ static int unexport_gpio_desc(struct gpio_desc *desc)
 }
 
 static ssize_t do_chip_export_store(struct device *dev,
-				    struct device_attribute *attr,
+				    const struct device_attribute *attr,
 				    const char *buf, ssize_t size,
 				    int (*handler)(struct gpio_desc *desc))
 {
@@ -555,28 +555,27 @@ static ssize_t do_chip_export_store(struct device *dev,
 }
 
 static ssize_t chip_export_store(struct device *dev,
-				 struct device_attribute *attr,
+				 const 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 const struct device_attribute dev_attr_export =
+	__DEVICE_ATTR(export, 0200, NULL, chip_export_store);
 
 static ssize_t chip_unexport_store(struct device *dev,
-				   struct device_attribute *attr,
+				   const 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 const struct device_attribute dev_attr_unexport =
+	__DEVICE_ATTR(unexport, 0200, NULL, chip_unexport_store);
 
 #if IS_ENABLED(CONFIG_GPIO_SYSFS_LEGACY)
-static struct attribute *gpiochip_attrs[] = {
+static const struct attribute *const gpiochip_attrs[] = {
 	&dev_attr_base.attr,
 	&dev_attr_label.attr,
 	&dev_attr_ngpio.attr,
@@ -585,7 +584,7 @@ static struct attribute *gpiochip_attrs[] = {
 ATTRIBUTE_GROUPS(gpiochip);
 #endif /* CONFIG_GPIO_SYSFS_LEGACY */
 
-static struct attribute *gpiochip_ext_attrs[] = {
+static const struct attribute *const gpiochip_ext_attrs[] = {
 	&dev_attr_label.attr,
 	&dev_attr_ngpio.attr,
 	&dev_attr_export.attr,

---
base-commit: 8f7df005a7564bd7ffa75da9c3085d5b996f1e16
change-id: 20261021-gpio-sysfs-const-19e060af900a

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


             reply	other threads:[~2026-10-21 10:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21 10:47 Bartosz Golaszewski [this message]
2026-10-21 11:17 ` Thomas Weißschuh
2026-10-21 12:28   ` Thomas Weißschuh
2026-10-21 12:35     ` Bartosz Golaszewski
2026-10-28  8:32 ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021-gpio-sysfs-const-v1-1-3d89ac247086@oss.qualcomm.com \
    --to=bartosz.golaszewski@oss.qualcomm.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thomas.weissschuh@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®