mirror of
https://github.com/u-boot/u-boot.git
synced 2025-05-06 11:43:45 +00:00
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 <patrick.delaunay@st.com> Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
This commit is contained in:
parent
15c8cbfc74
commit
cb08e84d68
1 changed files with 5 additions and 0 deletions
|
@ -295,6 +295,9 @@ static int gpio_stm32_probe(struct udevice *dev)
|
||||||
ret = dev_read_phandle_with_args(dev, "gpio-ranges",
|
ret = dev_read_phandle_with_args(dev, "gpio-ranges",
|
||||||
NULL, 3, i, &args);
|
NULL, 3, i, &args);
|
||||||
|
|
||||||
|
if (!ret && args.args_count < 3)
|
||||||
|
return -EINVAL;
|
||||||
|
|
||||||
if (ret == -ENOENT) {
|
if (ret == -ENOENT) {
|
||||||
uc_priv->gpio_count = STM32_GPIOS_PER_BANK;
|
uc_priv->gpio_count = STM32_GPIOS_PER_BANK;
|
||||||
priv->gpio_range = GENMASK(STM32_GPIOS_PER_BANK - 1, 0);
|
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,
|
ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3,
|
||||||
++i, &args);
|
++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",
|
dev_dbg(dev, "addr = 0x%p bank_name = %s gpio_count = %d gpio_range = 0x%x\n",
|
||||||
|
|
Loading…
Add table
Reference in a new issue