All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: u-boot@lists.denx.de
Cc: Samuel Holland <samuel@sholland.org>,
	Dario Binacchi <dariobin@libero.it>,
	Jean-Jacques Hiblot <jjhiblot@ti.com>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Pratyush Yadav <p.yadav@ti.com>, Simon Glass <sjg@chromium.org>
Subject: [PATCH 2/3] gpio: Verify validity of pin offsets from device trees
Date: Sat, 11 Sep 2021 17:05:52 -0500	[thread overview]
Message-ID: <20210911220553.9427-3-samuel@sholland.org> (raw)
In-Reply-To: <20210911220553.9427-1-samuel@sholland.org>

Translation of an OF GPIO specifier should fail if the pin offset is
larger than the number of pins in the GPIO bank.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/gpio/gpio-uclass.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 57e87960ee4..6f2b1adfdec 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -188,10 +188,14 @@ int gpio_lookup_name(const char *name, struct udevice **devp,
 int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,
 			  struct ofnode_phandle_args *args)
 {
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+
 	if (args->args_count < 1)
 		return -EINVAL;
 
 	desc->offset = args->args[0];
+	if (desc->offset >= uc_priv->gpio_count)
+		return -EINVAL;
 
 	if (args->args_count < 2)
 		return 0;
-- 
2.31.1


  parent reply	other threads:[~2021-09-11 22:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 22:05 [PATCH 0/3] gpio: uclass enhancements for DM_GPIO drivers Samuel Holland
2021-09-11 22:05 ` [PATCH 1/3] gpio: Verify validity of pin offsets when looking up names Samuel Holland
2021-09-30  4:08   ` Simon Glass
2021-10-05 22:02   ` Tom Rini
2021-09-11 22:05 ` Samuel Holland [this message]
2021-09-30  4:08   ` [PATCH 2/3] gpio: Verify validity of pin offsets from device trees Simon Glass
2021-10-05 22:02   ` Tom Rini
2021-10-05 22:02   ` Tom Rini
2021-09-11 22:05 ` [PATCH 3/3] gpio: Factor out DT flag translation Samuel Holland
2021-09-30  4:08   ` Simon Glass
2021-10-05 22:02   ` Tom Rini

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=20210911220553.9427-3-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=dariobin@libero.it \
    --cc=jjhiblot@ti.com \
    --cc=p.yadav@ti.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 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.