mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
@ 2026-10-21 10:47 Bartosz Golaszewski
  2026-10-21 11:17 ` Thomas Weißschuh
  2026-10-28  8:32 ` Bartosz Golaszewski
  0 siblings, 2 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-10-21 10:47 UTC (permalink / raw)
  To: Thomas Weißschuh, Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

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>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-10-28  8:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-21 10:47 [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes Bartosz Golaszewski
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

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®