[PATCH v5 02/11] i2c: rtl9300: fix channel number bound check

From: Jonas Jelonek
Date: Sat Aug 09 2025 - 18:07:46 EST


Fix the current check for number of channels (child nodes in the device
tree). Before, this was:

if (device_get_child_node_count(dev) >= drv_data->max_nchan)

drv_data->max_nchan gives the maximum number of channels so checking
with '>=' isn't correct because it doesn't allow the last channel
number. Thus, fix it to:

if (device_get_child_node_count(dev) > drv_data->max_nchan)

Issue occured on a TP-Link TL-ST1008F v2.0 device (8 SFP+ ports) and fix
is tested there.

Signed-off-by: Jonas Jelonek <jelonek.jonas@xxxxxxxxx>
---
drivers/i2c/busses/i2c-rtl9300.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c
index e6eb6a32fde2..68acbb6cc5a4 100644
--- a/drivers/i2c/busses/i2c-rtl9300.c
+++ b/drivers/i2c/busses/i2c-rtl9300.c
@@ -402,7 +402,7 @@ static int rtl9300_i2c_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, i2c);

drv_data = (struct rtl9300_i2c_drv_data *)device_get_match_data(i2c->dev);
- if (device_get_child_node_count(dev) >= drv_data->max_nchan)
+ if (device_get_child_node_count(dev) > drv_data->max_nchan)
return dev_err_probe(dev, -EINVAL, "Too many channels\n");

i2c->data_reg = i2c->reg_base + drv_data->data_reg;
--
2.48.1