linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] gpiolib: allow line names from device props to override driver names
@ 2021-12-14 21:59 Peter Rosin
  2021-12-16  9:02 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Rosin @ 2021-12-14 21:59 UTC (permalink / raw)
  To: linux-kernel
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, Andy Shevchenko,
	Alexander Dahl

Some GPIO providers set names for GPIO lines that match the names of
the pins on the SoC, or variations on that theme. These names are
generic more often that not, such as pioC12 in the at91 case. These
generic names block the possibility to set more useful GPIO line
names with device properties (i.e. gpio-line-names).

Allow overriding a generic name given by the GPIO driver if there is
a name given to the GPIO line using device properties, but leave the
generic name alone if no better name is available.

However, there is a risk. If user space is depending on the above
mentioned fixed GPIO names, AND there are device properties that
previously did not reach the surface, the name change might cause
regressions. But hopefully this stays below the radar...

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Tested-by: Alexander Dahl <ada@thorsis.com>
Signed-off-by: Peter Rosin <peda@axentia.se>
---
 drivers/gpio/gpiolib.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

Changes since v1: language fixes and gpio->GPIO as suggested by Andy.
(However, I disagree that "generally generic" is invalid or a tautology,
as it is exactly what I meany to say. But I changed it anyway...)

The tested-by tag is from a backport, zap it if that's not good
enough.

Cheers,
Peter

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index abfbf546d159..817342ef26d0 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -422,8 +422,16 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip)
 	if (count > chip->ngpio)
 		count = chip->ngpio;
 
-	for (i = 0; i < count; i++)
-		gdev->descs[i].name = names[chip->offset + i];
+	for (i = 0; i < count; i++) {
+		/*
+		 * Allow overriding "fixed" names provided by the GPIO
+		 * provider. The "fixed" names are more often than not
+		 * generic and less informative than the names given in
+		 * device properties.
+		 */
+		if (names[chip->offset + i] && names[chip->offset + i][0])
+			gdev->descs[i].name = names[chip->offset + i];
+	}
 
 	kfree(names);
 
@@ -708,10 +716,12 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 	INIT_LIST_HEAD(&gdev->pin_ranges);
 #endif
 
-	if (gc->names)
+	if (gc->names) {
 		ret = gpiochip_set_desc_names(gc);
-	else
-		ret = devprop_gpiochip_set_names(gc);
+		if (ret)
+			goto err_remove_from_list;
+	}
+	ret = devprop_gpiochip_set_names(gc);
 	if (ret)
 		goto err_remove_from_list;
 
-- 
2.20.1



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

* Re: [PATCH v2] gpiolib: allow line names from device props to override driver names
  2021-12-14 21:59 [PATCH v2] gpiolib: allow line names from device props to override driver names Peter Rosin
@ 2021-12-16  9:02 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2021-12-16  9:02 UTC (permalink / raw)
  To: Peter Rosin
  Cc: linux-kernel, Linus Walleij, linux-gpio, Andy Shevchenko, Alexander Dahl

On Tue, Dec 14, 2021 at 11:00 PM Peter Rosin <peda@axentia.se> wrote:
>
> Some GPIO providers set names for GPIO lines that match the names of
> the pins on the SoC, or variations on that theme. These names are
> generic more often that not, such as pioC12 in the at91 case. These
> generic names block the possibility to set more useful GPIO line
> names with device properties (i.e. gpio-line-names).
>
> Allow overriding a generic name given by the GPIO driver if there is
> a name given to the GPIO line using device properties, but leave the
> generic name alone if no better name is available.
>
> However, there is a risk. If user space is depending on the above
> mentioned fixed GPIO names, AND there are device properties that
> previously did not reach the surface, the name change might cause
> regressions. But hopefully this stays below the radar...
>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Tested-by: Alexander Dahl <ada@thorsis.com>
> Signed-off-by: Peter Rosin <peda@axentia.se>
> ---

Applied, thanks!

Bart

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

end of thread, other threads:[~2021-12-16  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 21:59 [PATCH v2] gpiolib: allow line names from device props to override driver names Peter Rosin
2021-12-16  9:02 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).