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

* Re: [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
  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-28  8:32 ` Bartosz Golaszewski
  1 sibling, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-10-21 11:17 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel

On Wed, Oct 21, 2026 at 12:47:25PM +0200, Bartosz Golaszewski wrote:
> 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.

Leaving the dynamically allocated attributes with non-const signatures will
make it harder to remove the non-const APIs later on.
Would it be possible to switch those to const signatures, too and cast away
the constness in the store handlers?
I see that this is a legacy interface anyways, which might be gone by the
time we want to remove the non-const APIs. But that applies to the
currently proposed changes, too.

> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

The code looks good.

Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>

> ---
>  drivers/gpio/gpiolib-sysfs.c | 37 ++++++++++++++++++-------------------
>  1 file changed, 18 insertions(+), 19 deletions(-)

(...)

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

* Re: [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
  2026-10-21 11:17 ` Thomas Weißschuh
@ 2026-10-21 12:28   ` Thomas Weißschuh
  2026-10-21 12:35     ` Bartosz Golaszewski
  0 siblings, 1 reply; 5+ messages in thread
From: Thomas Weißschuh @ 2026-10-21 12:28 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel

On Wed, Oct 21, 2026 at 01:17:54PM +0200, Thomas Weißschuh wrote:
> On Wed, Oct 21, 2026 at 12:47:25PM +0200, Bartosz Golaszewski wrote:
> > 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.
> 
> Leaving the dynamically allocated attributes with non-const signatures will
> make it harder to remove the non-const APIs later on.
> Would it be possible to switch those to const signatures, too and cast away
> the constness in the store handlers?
> I see that this is a legacy interface anyways, which might be gone by the
> time we want to remove the non-const APIs. But that applies to the
> currently proposed changes, too.

If I understand correctly, the dynamically allocated attributes are only
necessary to retreive 'struct gpiod_data' in the attribute registered on the
*parent*. Those registered on the gpio device itself can just use dev_get_drvdata().
Instead of registering the 'direction' and 'value' attributes on the parent,
you could use symlinks pointing to the child attributes instead.
This would make the code a whole lot simpler.

Currently it is not possible to create symlinks to sysfs attributes, but I have
simple patch for that locally. Let me know if you are interested.


Thomas

(...)

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

* Re: [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
  2026-10-21 12:28   ` Thomas Weißschuh
@ 2026-10-21 12:35     ` Bartosz Golaszewski
  0 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-10-21 12:35 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
	Bartosz Golaszewski

On Wed, 21 Oct 2026 14:28:56 +0200, "Thomas Weißschuh"
<thomas.weissschuh@linutronix.de> said:
> On Wed, Oct 21, 2026 at 01:17:54PM +0200, Thomas Weißschuh wrote:
>> On Wed, Oct 21, 2026 at 12:47:25PM +0200, Bartosz Golaszewski wrote:
>> > 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.
>>
>> Leaving the dynamically allocated attributes with non-const signatures will
>> make it harder to remove the non-const APIs later on.
>> Would it be possible to switch those to const signatures, too and cast away
>> the constness in the store handlers?
>> I see that this is a legacy interface anyways, which might be gone by the
>> time we want to remove the non-const APIs. But that applies to the
>> currently proposed changes, too.
>
> If I understand correctly, the dynamically allocated attributes are only
> necessary to retreive 'struct gpiod_data' in the attribute registered on the
> *parent*. Those registered on the gpio device itself can just use dev_get_drvdata().
> Instead of registering the 'direction' and 'value' attributes on the parent,
> you could use symlinks pointing to the child attributes instead.
> This would make the code a whole lot simpler.
>
> Currently it is not possible to create symlinks to sysfs attributes, but I have
> simple patch for that locally. Let me know if you are interested.
>

Sure, definitely. Is this something that will eventually make it upstream
though?

Bart

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

* Re: [PATCH] gpio: sysfs: use const APIs for legacy sysfs attributes
  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-28  8:32 ` Bartosz Golaszewski
  1 sibling, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2026-10-28  8:32 UTC (permalink / raw)
  To: Thomas Weißschuh, Linus Walleij, Bartosz Golaszewski,
	Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel


On Wed, 21 Oct 2026 12:47:25 +0200, Bartosz Golaszewski wrote:
> 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.
> 
> 

Applied, thanks!

[1/1] gpio: sysfs: use const APIs for legacy sysfs attributes
      https://git.kernel.org/brgl/c/7607a865e435066087b94a42fef065756ca91ea2

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®