Skip to contentSkip to conversation

gpio: stm32: cosmetic: cleanup gpio_stm32_probe

PATCH New Patrick Delaunay 2 participants 6 messages Sep 9, 2020 – Oct 2, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 gpio: stm32: cosmetic: cleanup gpio_stm32_probe

Move the variables definition at the beggining of the function gpio_stm32_probe().

---

 drivers/gpio/stm32_gpio.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpio/stm32_gpio.c +4 -6
index 5bff27f75b..aa70b1d2a9 100644
@@ -273,9 +273,12 @@ static const struct dm_gpio_ops gpio_stm32_ops = {
 static int gpio_stm32_probe(struct udevice *dev)
 {
 	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct ofnode_phandle_args args;
+	const char *name;
 	struct clk clk;
 	fdt_addr_t addr;
-	int ret;
+	int ret, i;
 
 	addr = dev_read_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
@@ -283,11 +286,6 @@ static int gpio_stm32_probe(struct udevice *dev)
 
 	priv->regs = (struct stm32_gpio_regs *)addr;
 
-	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-	struct ofnode_phandle_args args;
-	const char *name;
-	int i;
-
 	name = dev_read_string(dev, "st,bank-name");
 	if (!name)
 		return -EINVAL;
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 gpio: stm32: cosmetic: cleanup gpio_stm32_probe

Hi,

Quoted 11 lines

From: Patrick DELAUNAY <[email protected]>
Sent: mercredi 9 septembre 2020 18:29

Move the variables definition at the beggining of the function gpio_stm32_probe().

---

 drivers/gpio/stm32_gpio.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Applied to u-boot-stm/next, thanks!

Regards

Patrick

#2 lore raw

PATCH 1/2 gpio: stm32: cosmetic: cleanup gpio_stm32_probe

In reply to Patrick Delaunay

Hi Patrick

Quoted 29 lines · Patrick Delaunay

Move the variables definition at the beggining of the function gpio_stm32_probe().

---

 drivers/gpio/stm32_gpio.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/gpio/stm32_gpio.c +4 -1
index 5bff27f75b..aa70b1d2a9 100644
@@ -273,9 +273,12 @@ static const struct dm_gpio_ops gpio_stm32_ops = {
 static int gpio_stm32_probe(struct udevice *dev)
 {
 	struct stm32_gpio_priv *priv = dev_get_priv(dev);
+	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct ofnode_phandle_args args;
+	const char *name;
 	struct clk clk;
 	fdt_addr_t addr;
-	int ret;
+	int ret, i;
 
 	addr = dev_read_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
@@ -283,11 +286,6 @@ static int gpio_stm32_probe(struct udevice *dev)
 

drivers/gpio/stm32_gpio.c static int gpio_stm32_probe(struct udevice *dev) · line 291

Quoted 10 lines
drivers/gpio/stm32_gpio.c +0 -5
 	priv->regs = (struct stm32_gpio_regs *)addr;
 
-	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
-	struct ofnode_phandle_args args;
-	const char *name;
-	int i;
-
 	name = dev_read_string(dev, "st,bank-name");
 	if (!name)
 		return -EINVAL;

Thanks

#3 lore raw

PATCH 2/2 gpio: stm32: check result of ofnode_phandle_args

In reply to Patrick Delaunay

Add test on the size of ofnode_phandle_args result to avoid access to uninitialized elements in args[] field.

This patch avoids the issue when gpio-ranges cell size is not 3 as expected, for example:

	gpio-ranges = <&pinctrl 0>;
instead of
	gpio-ranges = <&pinctrl 0 112 16>;

---

 drivers/gpio/stm32_gpio.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpio/stm32_gpio.c +5 -0
index aa70b1d2a9..473e364796 100644
@@ -295,6 +295,9 @@ static int gpio_stm32_probe(struct udevice *dev)
 	ret = dev_read_phandle_with_args(dev, "gpio-ranges",
 					 NULL, 3, i, &args);
 
+	if (!ret && args.args_count < 3)
+		return -EINVAL;
+
 	if (ret == -ENOENT) {
 		uc_priv->gpio_count = STM32_GPIOS_PER_BANK;
 		priv->gpio_range = GENMASK(STM32_GPIOS_PER_BANK - 1, 0);
@@ -308,6 +311,8 @@ static int gpio_stm32_probe(struct udevice *dev)
 
 		ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3,
 						 ++i, &args);
+		if (!ret && args.args_count < 3)
+			return -EINVAL;
 	}
 
 	dev_dbg(dev, "addr = 0x%p bank_name = %s gpio_count = %d gpio_range = 0x%x\n",
Signature · 1 line
2.17.1
#4 lore raw

PATCH 2/2 gpio: stm32: check result of ofnode_phandle_args

Hi Patrick

Quoted 30 lines · Patrick Delaunay

Add test on the size of ofnode_phandle_args result to avoid access to uninitialized elements in args[] field.

This patch avoids the issue when gpio-ranges cell size is not 3 as expected, for example:

	gpio-ranges = <&pinctrl 0>;
instead of
	gpio-ranges = <&pinctrl 0 112 16>;

---

 drivers/gpio/stm32_gpio.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/gpio/stm32_gpio.c +3 -0
index aa70b1d2a9..473e364796 100644
@@ -295,6 +295,9 @@ static int gpio_stm32_probe(struct udevice *dev)
 	ret = dev_read_phandle_with_args(dev, "gpio-ranges",
 					 NULL, 3, i, &args);
 
+	if (!ret && args.args_count < 3)
+		return -EINVAL;
+
 	if (ret == -ENOENT) {
 		uc_priv->gpio_count = STM32_GPIOS_PER_BANK;
 		priv->gpio_range = GENMASK(STM32_GPIOS_PER_BANK - 1, 0);

drivers/gpio/stm32_gpio.c static int gpio_stm32_probe(struct udevice *dev) · line 318

Quoted 8 lines
drivers/gpio/stm32_gpio.c +2 -0
@@ -308,6 +311,8 @@ static int gpio_stm32_probe(struct udevice *dev)
 
 		ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3,
 						 ++i, &args);
+		if (!ret && args.args_count < 3)
+			return -EINVAL;
 	}
 
 	dev_dbg(dev, "addr = 0x%p bank_name = %s gpio_count = %d gpio_range = 0x%x\n",

Thanks

#5 lore raw

PATCH 2/2 gpio: stm32: check result of ofnode_phandle_args

In reply to Patrick Delaunay

Hi,

Quoted 11 lines

From: Patrick DELAUNAY <[email protected]>

Add test on the size of ofnode_phandle_args result to avoid access to uninitialized elements in args[] field.

This patch avoids the issue when gpio-ranges cell size is not 3 as expected, for example:

	gpio-ranges = <&pinctrl 0>;
instead of
	gpio-ranges = <&pinctrl 0 112 16>;
Quoted 6 lines

---

 drivers/gpio/stm32_gpio.c | 5 +++++
 1 file changed, 5 insertions(+)

Applied to u-boot-stm/next, thanks!

Regards

Patrick