Message ID | 20201215123755.438369-1-linus.walleij@linaro.org |
---|---|
State | New |
Headers | show |
Series | gpio: Skip over NULL and (empty string) line names | expand |
On Tue, Dec 15, 2020 at 2:41 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > The core will warn if we try to assign the name '' > (empty string) to two lines. Actively ignore NULL > and empty string in the name assignment loop. > + if (!gc->names[i] || !strlen(gc->names[i])) > + if (!gc->names[i] || !strlen(gc->names[i])) > + if (!names[i] || !strlen(names[i])) Can we replace strlen() calls by a simple check of the first byte? names[i][0] -- With Best Regards, Andy Shevchenko
On Fri, Dec 18, 2020 at 6:05 PM Andy Shevchenko <andy.shevchenko@gmail.com> wrote: > On Tue, Dec 15, 2020 at 2:41 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > > > The core will warn if we try to assign the name '' > > (empty string) to two lines. Actively ignore NULL > > and empty string in the name assignment loop. > > > + if (!gc->names[i] || !strlen(gc->names[i])) > > > + if (!gc->names[i] || !strlen(gc->names[i])) > > > + if (!names[i] || !strlen(names[i])) > > Can we replace strlen() calls by a simple check of the first byte? > > names[i][0] Unfinished example... if (!names[i] || names[i][0] == '\0') -- With Best Regards, Andy Shevchenko
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 26c75499d549..d07da3ffd140 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -343,6 +343,10 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) for (i = 0; i != gc->ngpio; ++i) { struct gpio_desc *gpiod; + /* Skip NULL or '(empty string)' names */ + if (!gc->names[i] || !strlen(gc->names[i])) + continue; + gpiod = gpio_name_to_desc(gc->names[i]); if (gpiod && (gpiod->gdev == gdev)) { dev_err(&gdev->dev, @@ -352,8 +356,12 @@ static int gpiochip_set_desc_names(struct gpio_chip *gc) } /* Then add all names to the GPIO descriptors */ - for (i = 0; i != gc->ngpio; ++i) + for (i = 0; i != gc->ngpio; ++i) { + /* Skip NULL or '(empty string)' names */ + if (!gc->names[i] || !strlen(gc->names[i])) + continue; gdev->descs[i].name = gc->names[i]; + } return 0; } @@ -404,6 +412,9 @@ static int devprop_gpiochip_set_names(struct gpio_chip *chip) for (i = 0; i < count; i++) { struct gpio_desc *gpiod; + /* Skip NULL or '(empty string)' names */ + if (!names[i] || !strlen(names[i])) + continue; gpiod = gpio_name_to_desc(names[i]); if (gpiod && (gpiod->gdev == gdev)) { dev_err(&gdev->dev,
The core will warn if we try to assign the name '' (empty string) to two lines. Actively ignore NULL and empty string in the name assignment loop. Reported-by: Guillaume Tucker <guillaume.tucker@collabora.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- drivers/gpio/gpiolib.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) -- 2.28.0