linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Andy Shevchenko <andy.shevchenko@gmail.com>
Subject: [PATCH v4 04/13] gpiolib: use gpiochip_get_desc() in linehandle_create()
Date: Tue, 24 Dec 2019 13:07:00 +0100	[thread overview]
Message-ID: <20191224120709.18247-5-brgl@bgdev.pl> (raw)
In-Reply-To: <20191224120709.18247-1-brgl@bgdev.pl>

From: Bartosz Golaszewski <bgolaszewski@baylibre.com>

Unduplicate the ngpio check by simply calling gpiochip_get_desc() and
checking its return value.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
---
 drivers/gpio/gpiolib.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 68adbd2179a0..fcec8b090677 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -678,14 +678,13 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip)
 	/* Request each GPIO */
 	for (i = 0; i < handlereq.lines; i++) {
 		u32 offset = handlereq.lineoffsets[i];
-		struct gpio_desc *desc;
+		struct gpio_desc *desc = gpiochip_get_desc(gdev->chip, offset);
 
-		if (offset >= gdev->ngpio) {
-			ret = -EINVAL;
+		if (IS_ERR(desc)) {
+			ret = PTR_ERR(desc);
 			goto out_free_descs;
 		}
 
-		desc = &gdev->descs[offset];
 		ret = gpiod_request(desc, lh->label);
 		if (ret)
 			goto out_free_descs;
-- 
2.23.0


  parent reply	other threads:[~2019-12-24 12:08 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-24 12:06 [PATCH v4 00/13] gpiolib: add an ioctl() for monitoring line status changes Bartosz Golaszewski
2019-12-24 12:06 ` [PATCH v4 01/13] gpiolib: use 'unsigned int' instead of 'unsigned' in gpio_set_config() Bartosz Golaszewski
2020-01-07 10:02   ` Linus Walleij
2019-12-24 12:06 ` [PATCH v4 02/13] gpiolib: have a single place of calling set_config() Bartosz Golaszewski
2020-01-07 10:02   ` Linus Walleij
2020-01-20  8:44   ` Geert Uytterhoeven
2020-01-20  9:54     ` Andy Shevchenko
2020-01-23 10:16     ` Bartosz Golaszewski
2020-02-01 19:52   ` Guenter Roeck
2020-02-03 11:04     ` Bartosz Golaszewski
2019-12-24 12:06 ` [PATCH v4 03/13] gpiolib: convert the type of hwnum to unsigned int in gpiochip_get_desc() Bartosz Golaszewski
2020-01-07 10:03   ` Linus Walleij
2019-12-24 12:07 ` Bartosz Golaszewski [this message]
2020-01-07 10:04   ` [PATCH v4 04/13] gpiolib: use gpiochip_get_desc() in linehandle_create() Linus Walleij
2019-12-24 12:07 ` [PATCH v4 05/13] gpiolib: use gpiochip_get_desc() in lineevent_create() Bartosz Golaszewski
2020-01-07 10:04   ` Linus Walleij
2019-12-24 12:07 ` [PATCH v4 06/13] gpiolib: use gpiochip_get_desc() in gpio_ioctl() Bartosz Golaszewski
2020-01-07 10:04   ` Linus Walleij
2019-12-24 12:07 ` [PATCH v4 07/13] kfifo: provide noirqsave variants of spinlocked in and out helpers Bartosz Golaszewski
2019-12-24 12:07 ` [PATCH v4 08/13] kfifo: provide kfifo_is_empty_spinlocked() Bartosz Golaszewski
2019-12-24 12:07 ` [PATCH v4 09/13] gpiolib: rework the locking mechanism for lineevent kfifo Bartosz Golaszewski
2020-01-08 11:06   ` Andy Shevchenko
2019-12-24 12:07 ` [PATCH v4 10/13] gpiolib: emit a debug message when adding events to a full kfifo Bartosz Golaszewski
2019-12-24 12:07 ` [PATCH v4 11/13] gpiolib: provide a dedicated function for setting lineinfo Bartosz Golaszewski
2020-01-08 12:41   ` Andy Shevchenko
2019-12-24 12:07 ` [PATCH v4 12/13] gpiolib: add new ioctl() for monitoring changes in line info Bartosz Golaszewski
2020-01-08 12:46   ` Andy Shevchenko
2020-01-08 16:55     ` Bartosz Golaszewski
2020-06-09  0:23   ` Kent Gibson
2020-06-09  7:58     ` Bartosz Golaszewski
2019-12-24 12:07 ` [PATCH v4 13/13] tools: gpio: implement gpio-watch Bartosz Golaszewski
2020-01-08 12:47   ` Andy Shevchenko
2020-01-07 10:07 ` [PATCH v4 00/13] gpiolib: add an ioctl() for monitoring line status changes Linus Walleij
2020-01-07 10:38   ` Bartosz Golaszewski
2020-01-07 12:50     ` Linus Walleij
2020-01-07 13:15       ` Stefani Seibold
2020-01-07 14:44       ` Andy Shevchenko
2020-01-07 14:45         ` Andy Shevchenko
2020-01-07 15:19           ` Bartosz Golaszewski
2020-01-07 15:58             ` Andy Shevchenko
2020-01-07 16:51               ` Bartosz Golaszewski

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=20191224120709.18247-5-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=warthog618@gmail.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;
as well as URLs for NNTP newsgroup(s).