[PATCH 2/3] gpio: Verify validity of pin offsets from device trees

Samuel Holland samuel at sholland.org
Sun Sep 12 00:05:52 CEST 2021


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 at 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



More information about the U-Boot mailing list