Message ID | 20231204093509.19225-3-brgl@bgdev.pl |
---|---|
State | New |
Headers | show |
Series | gpio/pinctrl: replace gpiochip_is_requested() with a safer interface | expand |
On Mon, Dec 04, 2023 at 10:35:01AM +0100, Bartosz Golaszewski wrote: > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > Use the new gpiochip_dup_line_label() helper to safely retrieve the > descriptor label. ... > for (i = 0; i < chip->ngpio; i++) { > int gpio = i + chip->base; > int reg; > - const char *label, *pull, *powerdomain; > + const char *pull, *powerdomain; Make it reversed xmas tree?
On Mon, Dec 4, 2023 at 2:16 PM Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote: > > On Mon, Dec 04, 2023 at 10:35:01AM +0100, Bartosz Golaszewski wrote: > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > Use the new gpiochip_dup_line_label() helper to safely retrieve the > > descriptor label. > > ... > > > for (i = 0; i < chip->ngpio; i++) { > > int gpio = i + chip->base; > > int reg; > > - const char *label, *pull, *powerdomain; > > + const char *pull, *powerdomain; > > Make it reversed xmas tree? > Bikeshedding again. :) But I plan on making all local variables across the core GPIOLIB code consistent (no tabs and reverse xmas tree) closer to the end of the release cycle. Bart
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c index 7eaf8a28638c..f7d5120ff8f1 100644 --- a/drivers/gpio/gpio-wm831x.c +++ b/drivers/gpio/gpio-wm831x.c @@ -8,6 +8,7 @@ * */ +#include <linux/cleanup.h> #include <linux/kernel.h> #include <linux/slab.h> #include <linux/module.h> @@ -160,18 +161,21 @@ static void wm831x_gpio_dbg_show(struct seq_file *s, struct gpio_chip *chip) for (i = 0; i < chip->ngpio; i++) { int gpio = i + chip->base; int reg; - const char *label, *pull, *powerdomain; + const char *pull, *powerdomain; /* We report the GPIO even if it's not requested since * we're also reporting things like alternate * functions which apply even when the GPIO is not in * use as a GPIO. */ - label = gpiochip_is_requested(chip, i); - if (!label) - label = "Unrequested"; + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); + if (IS_ERR(label)) { + dev_err(wm831x->dev, "Failed to duplicate label\n"); + continue; + } - seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label); + seq_printf(s, " gpio-%-3d (%-20.20s) ", + gpio, label ?: "Unrequested"); reg = wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL + i); if (reg < 0) {