linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/2] gpiolib: check the 'ngpios' property in core gpiolib code
Date: Thu, 18 Nov 2021 19:05:54 +0200	[thread overview]
Message-ID: <YZaH8rsMyUztOX/r@smile.fi.intel.com> (raw)
In-Reply-To: <20211118132317.15898-2-brgl@bgdev.pl>

On Thu, Nov 18, 2021 at 02:23:17PM +0100, Bartosz Golaszewski wrote:
> Several drivers read the 'ngpios' device property on their own, but
> since it's defined as a standard GPIO property in the device tree bindings
> anyway, it's a good candidate for generalization. If the driver didn't
> set its gc->ngpio, try to read the 'ngpios' property from the GPIO
> device's firmware node before bailing out.

...

>  	if (gc->ngpio == 0) {
> -		chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
> -		ret = -EINVAL;
> -		goto err_free_descs;
> +		ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios);
> +		if (ret) {
> +			chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
> +			ret = -EINVAL;
> +			goto err_free_descs;
> +		}
> +
> +		gc->ngpio = ngpios;
>  	}

This should be

	if (gc->ngpio == 0) {
		ret = device_property_read_u32(&gdev->dev, "ngpios", &ngpios);
		if (ret)
			return ret;

		gc->ngpio = ngpios;
	}

	if (gc->ngpio == 0) {
		chip_err(gc, "tried to insert a GPIO chip with zero lines\n");
		ret = -EINVAL;
		goto err_free_descs;
	}

-- 
With Best Regards,
Andy Shevchenko



  parent reply	other threads:[~2021-11-18 17:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 13:23 [PATCH v2 1/2] gpiolib: improve coding style for local variables Bartosz Golaszewski
2021-11-18 13:23 ` [PATCH v2 2/2] gpiolib: check the 'ngpios' property in core gpiolib code Bartosz Golaszewski
2021-11-18 15:44   ` Andy Shevchenko
2021-11-18 16:38     ` Bartosz Golaszewski
2021-11-18 17:01       ` Andy Shevchenko
2021-11-18 17:06         ` Andy Shevchenko
2021-11-18 17:05   ` Andy Shevchenko [this message]
2021-11-18 20:12     ` Bartosz Golaszewski
2021-11-18 21:16       ` Andy Shevchenko
2021-11-19 19:35         ` Bartosz Golaszewski
2021-11-22 11:20           ` Andy Shevchenko
2021-11-18 15:44 ` [PATCH v2 1/2] gpiolib: improve coding style for local variables Andy Shevchenko
2021-11-19  7:57 ` Johan Hovold

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=YZaH8rsMyUztOX/r@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).