[PATCH 1/2] misc: ti_fpc202: fix off-by-one error in port ID bounds check

Felix Gu posted 2 patches 1 month, 1 week ago
[PATCH 1/2] misc: ti_fpc202: fix off-by-one error in port ID bounds check
Posted by Felix Gu 1 month, 1 week ago
FPC202_NUM_PORTS is 2, valid port IDs should be 0 and 1. A port_id of 2
would incorrectly pass the check, potentially causing out-of-bounds
access to the port-related arrays.

Found by code review, compile pass.

Fixes: 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
 drivers/misc/ti_fpc202.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/ti_fpc202.c b/drivers/misc/ti_fpc202.c
index 8eb2b5ac9850..578feefb77f1 100644
--- a/drivers/misc/ti_fpc202.c
+++ b/drivers/misc/ti_fpc202.c
@@ -366,7 +366,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;

-- 
2.43.0
Re: [PATCH 1/2] misc: ti_fpc202: fix off-by-one error in port ID bounds check
Posted by Romain Gantois 1 month ago
On Friday, 20 February 2026 18:20:31 CET Felix Gu wrote:
> FPC202_NUM_PORTS is 2, valid port IDs should be 0 and 1. A port_id of 2
> would incorrectly pass the check, potentially causing out-of-bounds
> access to the port-related arrays.
> 
> Found by code review, compile pass.
> 
> Fixes: 1e5c9b1efa1c ("misc: add FPC202 dual port controller driver")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> 
>  drivers/misc/ti_fpc202.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/misc/ti_fpc202.c b/drivers/misc/ti_fpc202.c
> index 8eb2b5ac9850..578feefb77f1 100644
> --- a/drivers/misc/ti_fpc202.c
> +++ b/drivers/misc/ti_fpc202.c
> @@ -366,7 +366,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: Romain Gantois <romain.gantois@bootlin.com>