linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
To: linux-gpio@vger.kernel.org
Cc: linus.walleij@linaro.org, broonie@kernel.org,
	Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Subject: [PATCH V2 2/2] gpiolib: do not allow to insert an empty gpiochip
Date: Mon, 16 Nov 2015 13:02:47 +0800	[thread overview]
Message-ID: <1447650167-29070-3-git-send-email-bamvor.zhangjian@linaro.org> (raw)
In-Reply-To: <1447650167-29070-1-git-send-email-bamvor.zhangjian@linaro.org>

We need to check if number of gpio is positive if there is no
such check in devicetree or acpi or whatever called before
gpiochip_add.

I suppose that devicetree and acpi do not allow insert gpiochip
with zero number but I do not know if it is enough to ignore
this check in gpiochip_add.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
---
 drivers/gpio/gpiolib.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 270d60b..150af91 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -329,6 +329,11 @@ int gpiochip_add(struct gpio_chip *chip)
 	if (!descs)
 		return -ENOMEM;
 
+	if (chip->ngpio == 0) {
+		chip_err(chip, "tried to insert a GPIO chip with zero lines\n");
+		return -EINVAL;
+	}
+
 	spin_lock_irqsave(&gpio_lock, flags);
 
 	if (base < 0) {
-- 
2.1.4


  parent reply	other threads:[~2015-11-16  5:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16  5:02 [PATCH V2 0/2] Fix bugs in the insertion of gpiochip Bamvor Jian Zhang
2015-11-16  5:02 ` [PATCH V2 1/2] gpiolib: improve overlap check of range of gpio Bamvor Jian Zhang
2015-11-17 14:14   ` Linus Walleij
2015-11-17 14:47     ` Bamvor Zhang Jian
2015-11-16  5:02 ` Bamvor Jian Zhang [this message]
2015-11-17 14:16   ` [PATCH V2 2/2] gpiolib: do not allow to insert an empty gpiochip Linus Walleij

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=1447650167-29070-3-git-send-email-bamvor.zhangjian@linaro.org \
    --to=bamvor.zhangjian@linaro.org \
    --cc=broonie@kernel.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@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).