gpio: sysfs: make the sysfs export behavior consistent
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 30 Sep 2024 08:30:29 +0000 (10:30 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 2 Oct 2024 14:30:12 +0000 (16:30 +0200)
For drivers or board files that set gpio_chip->names, the links to the
GPIO attribute group created on sysfs export will be named after the
line's name set in that array. For lines that are named using device
properties, the names pointer of the gpio_chip struct is never assigned
so they are exported as if they're not named.

The ABI documentation does not mention the former behavior and given
that the majority of modern systems use device-tree, ACPI or other way
of passing GPIO names using device properties - bypassing gc->names -
it's better to make the behavior consistent by always exporting lines as
"gpioXYZ".

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20240930083029.17694-1-brgl@bgdev.pl
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib-sysfs.c

index 17ed229412af9950f5cecaf23c707f30a5934d3d..20426d6e04d5b82eeecbbf212d97d399678a7b9c 100644 (file)
@@ -573,11 +573,10 @@ static struct class gpio_class = {
  */
 int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
 {
-       const char *ioname = NULL;
        struct gpio_device *gdev;
        struct gpiod_data *data;
        struct device *dev;
-       int status, offset;
+       int status;
 
        /* can't export until sysfs is available ... */
        if (!class_is_registered(&gpio_class)) {
@@ -626,14 +625,9 @@ int gpiod_export(struct gpio_desc *desc, bool direction_may_change)
        else
                data->direction_can_change = false;
 
-       offset = gpio_chip_hwgpio(desc);
-       if (guard.gc->names && guard.gc->names[offset])
-               ioname = guard.gc->names[offset];
-
        dev = device_create_with_groups(&gpio_class, &gdev->dev,
                                        MKDEV(0, 0), data, gpio_groups,
-                                       ioname ? ioname : "gpio%u",
-                                       desc_to_gpio(desc));
+                                       "gpio%u", desc_to_gpio(desc));
        if (IS_ERR(dev)) {
                status = PTR_ERR(dev);
                goto err_free_data;