Skip to contentSkip to conversation

misc: ti_fpc202: Fix off by one in probe()

PATCH In review Dan Carpenter 4 participants 4 messages Apr 23, 2025 – Apr 29, 2025

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

PATCH 1/1 misc: ti_fpc202: Fix off by one in probe()

The "port_id" is used as an array index into the struct fpc202_priv priv->addr_caches[] array in fpc202_write_dev_addr(). It's a 2 by 2 array so if "port_id" is FPC202_NUM_PORTS (2) then it's one element out of bounds. Change the > to >= to fix this bug.

Fixes 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")
---
 drivers/misc/ti_fpc202.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/ti_fpc202.c +1 -1
index b9c9ee4bfc4e..4e1871870769 100644
@@ -370,7 +370,7 @@ static int fpc202_probe(struct i2c_client *client)
 			goto unregister_chans;
 		}
 
-		if (port_id > FPC202_NUM_PORTS) {
+		if (port_id >= FPC202_NUM_PORTS) {
 			dev_err(dev, "port ID %d is out of range!\n", port_id);
 			ret = -EINVAL;
 			goto unregister_chans;
Signature · 1 line
2.47.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Dan Carpenter

The "port_id" is used as an array index into the struct fpc202_priv priv->addr_caches[] array in fpc202_write_dev_addr(). It's a 2 by 2 array so if "port_id" is FPC202_NUM_PORTS (2) then it's one element out of bounds. Change the > to >= to fix this bug.

Fixes 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")

---

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Dan Carpenter
Quoted 16 lines · On Wednesday, 23 April 2025 10:22:30 CEST Dan Carpenter wrote:

The "port_id" is used as an array index into the struct fpc202_priv priv->addr_caches[] array in fpc202_write_dev_addr(). It's a 2 by 2 array so if "port_id" is FPC202_NUM_PORTS (2) then it's one element out of bounds. Change the > to >= to fix this bug.

Fixes 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")
---
 drivers/misc/ti_fpc202.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/ti_fpc202.c +0 -0
index b9c9ee4bfc4e..4e1871870769 100644

drivers/misc/ti_fpc202.c static int fpc202_probe(struct i2c_client *client) · line 376

Quoted 8 lines
drivers/misc/ti_fpc202.c +1 -1
@@ -370,7 +370,7 @@ static int fpc202_probe(struct i2c_client *client)
 			goto unregister_chans;
 		}
 
-		if (port_id > FPC202_NUM_PORTS) {
+		if (port_id >= FPC202_NUM_PORTS) {
 			dev_err(dev, "port ID %d is out of range!\n", port_id);
 			ret = -EINVAL;
 			goto unregister_chans;
Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter

Hi Dan,

Quoted 7 lines · Dan Carpenter

The "port_id" is used as an array index into the struct fpc202_priv priv->addr_caches[] array in fpc202_write_dev_addr(). It's a 2 by 2 array so if "port_id" is FPC202_NUM_PORTS (2) then it's one element out of bounds. Change the > to >= to fix this bug.

Fixes 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")

Thanks,
Andi