Skip to contentSkip to conversation

pinctrl: nuvoton: wpcm450: off by one in wpcm450_gpio_register()

PATCH In review Dan Carpenter 3 participants 3 messages Mar 18, 2022 – Mar 24, 2022

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

PATCH 1/1 pinctrl: nuvoton: wpcm450: off by one in wpcm450_gpio_register()

The > WPCM450_NUM_BANKS should be >= or it leads to an out of bounds access on the next line.

Fixes a1d1e0e3d80a ("pinctrl: nuvoton: Add driver for WPCM450")
---
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +1 -1
index 661aa963e3fc..164d7a6e7b5b 100644
@@ -1043,7 +1043,7 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		gpio = &pctrl->gpio_bank[reg];
 		gpio->pctrl = pctrl;
 
-		if (reg > WPCM450_NUM_BANKS)
+		if (reg >= WPCM450_NUM_BANKS)
 			return dev_err_probe(dev, -EINVAL,
 					     "GPIO index %d out of range!\n", reg);
 
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Dan Carpenter

The > WPCM450_NUM_BANKS should be >= or it leads to an out of bounds access on the next line.

True.

Quoted 3 lines
Fixes a1d1e0e3d80a ("pinctrl: nuvoton: Add driver for WPCM450")

---

Thanks,
Jonathan

Quoted 19 lines
 drivers/pinctrl/nuvoton/pinctrl-wpcm450.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pinctrl/nuvoton/pinctrl-wpcm450.c +1 -1
index 661aa963e3fc..164d7a6e7b5b 100644
@@ -1043,7 +1043,7 @@ static int wpcm450_gpio_register(struct platform_device *pdev,
 		gpio = &pctrl->gpio_bank[reg];
 		gpio->pctrl = pctrl;
 
-		if (reg > WPCM450_NUM_BANKS)
+		if (reg >= WPCM450_NUM_BANKS)
 			return dev_err_probe(dev, -EINVAL,
 					     "GPIO index %d out of range!\n", reg);
 
Signature · 1 line
2.20.1