* [PATCH v2] gpio: merrifield: check the return value of devm_kstrdup()
@ 2022-01-17 7:06 xkernel.wang
2022-01-24 14:25 ` Andy Shevchenko
0 siblings, 1 reply; 2+ messages in thread
From: xkernel.wang @ 2022-01-17 7:06 UTC (permalink / raw)
To: andy; +Cc: linus.walleij, brgl, linux-gpio, linux-kernel, Xiaoke Wang
From: Xiaoke Wang <xkernel.wang@foxmail.com>
devm_kstrdup() returns pointer to allocated string on success, NULL on
failure. So it is better to check the return value of it.
Before, if devm_kstrdup() fails, pinctrl_dev_name will be NULL, then the
retval below will be a negative error-code(inside gpiochip_add_pin_range(),
pinctrl_find_and_add_gpio_range()->get_pinctrl_dev_from_devname() will
finally check pinctrl_dev_name and return error), so the failure of
devm_kstrdup() can be only implicitly caught after a long call chain.
While this patch is to explicitly catch the failure in time.
> retval = gpiochip_add_pin_range(&priv->chip, pinctrl_dev_name,
> range->gpio_base,
> range->pin_base,
> range->npins);
> if (retval) {
> dev_err(priv->dev, "failed to add GPIO pin range\n");
> return retval;
> }
Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
---
Changelogs:
v1 -> v2: update the commit message.
drivers/gpio/gpio-merrifield.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
index 42c4d9d..f3d1bae 100644
--- a/drivers/gpio/gpio-merrifield.c
+++ b/drivers/gpio/gpio-merrifield.c
@@ -409,6 +409,9 @@ static int mrfld_gpio_add_pin_ranges(struct gpio_chip *chip)
int retval;
pinctrl_dev_name = mrfld_gpio_get_pinctrl_dev_name(priv);
+ if (!pinctrl_dev_name)
+ return -ENOMEM;
+
for (i = 0; i < ARRAY_SIZE(mrfld_gpio_ranges); i++) {
range = &mrfld_gpio_ranges[i];
retval = gpiochip_add_pin_range(&priv->chip, pinctrl_dev_name,
--
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gpio: merrifield: check the return value of devm_kstrdup()
2022-01-17 7:06 [PATCH v2] gpio: merrifield: check the return value of devm_kstrdup() xkernel.wang
@ 2022-01-24 14:25 ` Andy Shevchenko
0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2022-01-24 14:25 UTC (permalink / raw)
To: xkernel.wang; +Cc: andy, linus.walleij, brgl, linux-gpio, linux-kernel
On Mon, Jan 17, 2022 at 03:06:06PM +0800, xkernel.wang@foxmail.com wrote:
> From: Xiaoke Wang <xkernel.wang@foxmail.com>
>
> devm_kstrdup() returns pointer to allocated string on success, NULL on
> failure. So it is better to check the return value of it.
>
> Before, if devm_kstrdup() fails, pinctrl_dev_name will be NULL, then the
> retval below will be a negative error-code(inside gpiochip_add_pin_range(),
> pinctrl_find_and_add_gpio_range()->get_pinctrl_dev_from_devname() will
> finally check pinctrl_dev_name and return error), so the failure of
> devm_kstrdup() can be only implicitly caught after a long call chain.
> While this patch is to explicitly catch the failure in time.
> > retval = gpiochip_add_pin_range(&priv->chip, pinctrl_dev_name,
> > range->gpio_base,
> > range->pin_base,
> > range->npins);
> > if (retval) {
> > dev_err(priv->dev, "failed to add GPIO pin range\n");
> > return retval;
> > }
Pushed to my review and testing queue, thanks!
> Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
> ---
> Changelogs:
> v1 -> v2: update the commit message.
> drivers/gpio/gpio-merrifield.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/gpio/gpio-merrifield.c b/drivers/gpio/gpio-merrifield.c
> index 42c4d9d..f3d1bae 100644
> --- a/drivers/gpio/gpio-merrifield.c
> +++ b/drivers/gpio/gpio-merrifield.c
> @@ -409,6 +409,9 @@ static int mrfld_gpio_add_pin_ranges(struct gpio_chip *chip)
> int retval;
>
> pinctrl_dev_name = mrfld_gpio_get_pinctrl_dev_name(priv);
> + if (!pinctrl_dev_name)
> + return -ENOMEM;
> +
> for (i = 0; i < ARRAY_SIZE(mrfld_gpio_ranges); i++) {
> range = &mrfld_gpio_ranges[i];
> retval = gpiochip_add_pin_range(&priv->chip, pinctrl_dev_name,
> --
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-24 14:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-17 7:06 [PATCH v2] gpio: merrifield: check the return value of devm_kstrdup() xkernel.wang
2022-01-24 14:25 ` Andy Shevchenko
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.