mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: xkernel.wang@foxmail.com
Cc: andy@kernel.org, linus.walleij@linaro.org, brgl@bgdev.pl,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] gpio: merrifield: check the return value of devm_kstrdup()
Date: Mon, 24 Jan 2022 16:25:19 +0200	[thread overview]
Message-ID: <Ye62z5jB+25ocAeT@smile.fi.intel.com> (raw)
In-Reply-To: <tencent_A3850F2901FD5B80E831ABE7C27144509C0A@qq.com>

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



      reply	other threads:[~2022-01-24 14:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17  7:06 xkernel.wang
2022-01-24 14:25 ` Andy Shevchenko [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Ye62z5jB+25ocAeT@smile.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xkernel.wang@foxmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®