Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gpio: wm831x: use gpiochip_dup_line_label()

Use the new gpiochip_dup_line_label() helper to safely retrieve the
descriptor label.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>

+9 -5
+9 -5
drivers/gpio/gpio-wm831x.c
··· 8 8 * 9 9 */ 10 10 11 + #include <linux/cleanup.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/slab.h> 13 14 #include <linux/module.h> ··· 161 160 for (i = 0; i < chip->ngpio; i++) { 162 161 int gpio = i + chip->base; 163 162 int reg; 164 - const char *label, *pull, *powerdomain; 163 + const char *pull, *powerdomain; 165 164 166 165 /* We report the GPIO even if it's not requested since 167 166 * we're also reporting things like alternate 168 167 * functions which apply even when the GPIO is not in 169 168 * use as a GPIO. 170 169 */ 171 - label = gpiochip_is_requested(chip, i); 172 - if (!label) 173 - label = "Unrequested"; 170 + char *label __free(kfree) = gpiochip_dup_line_label(chip, i); 171 + if (IS_ERR(label)) { 172 + dev_err(wm831x->dev, "Failed to duplicate label\n"); 173 + continue; 174 + } 174 175 175 - seq_printf(s, " gpio-%-3d (%-20.20s) ", gpio, label); 176 + seq_printf(s, " gpio-%-3d (%-20.20s) ", 177 + gpio, label ?: "Unrequested"); 176 178 177 179 reg = wm831x_reg_read(wm831x, WM831X_GPIO1_CONTROL + i); 178 180 if (reg < 0) {