From 15c8cbfc7482c07db0ba5307f31ea2423399fba9 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 9 Sep 2020 18:28:33 +0200 Subject: gpio: stm32: cosmetic: cleanup gpio_stm32_probe Move the variables definition at the beggining of the function gpio_stm32_probe(). Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- drivers/gpio/stm32_gpio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'drivers/gpio/stm32_gpio.c') diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c index 5bff27f75b5..aa70b1d2a9d 100644 --- a/drivers/gpio/stm32_gpio.c +++ b/drivers/gpio/stm32_gpio.c @@ -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; -- cgit v1.2.3 From cb08e84d68ca64608fddb1ceec611f520e47b67e Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 9 Sep 2020 18:28:34 +0200 Subject: gpio: stm32: check result of ofnode_phandle_args 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>; Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- drivers/gpio/stm32_gpio.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'drivers/gpio/stm32_gpio.c') diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c index aa70b1d2a9d..473e364796f 100644 --- a/drivers/gpio/stm32_gpio.c +++ b/drivers/gpio/stm32_gpio.c @@ -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", -- cgit v1.2.3