Commit 2a14e91b6d76 ("mctp i2c: initialise event handler read bytes")
made reads of an mctp-i2c address return 0xff, but only once a netdev
has been selected. Before that, mctp_i2c_slave_cb() returns early and
leaves *val unset, so the bus driver sends whatever it holds (an
uninitialised stack byte on i2c-aspeed and i2c-npcm7xx).
The slave is registered before any netdev is added. Two in-tree aspeed
device trees set mctp-controller only on mux child busses; there the
netdevs appear only once the mux has probed, and not at all if that
fails.
Set *val to 0xff for read events on that path too.
Fixes: f5b8abf9fc3d ("mctp i2c: MCTP I2C binding driver")
Signed-off-by: Eric Yun Lin Chiang <eric…@gmail.com>
---
I came across this while reading the January read fix. I may be
missing a reason for the no-netdev path to stay as it is; if so, I am
happy to drop this.
Tested: a local KUnit test (UML, KASAN) that calls mctp_i2c_slave_cb()
with no netdev selected and *val preset to 0xa5: without this patch both
read events leave 0xa5, with it both return 0xff; write events are
unchanged. I can send the test if it is useful. Also built for ARM
(aspeed_g5_defconfig + MCTP_TRANSPORT_I2C, W=1 for drivers/net/mctp) and
booted on QEMU ast2600-evb with an mctp-i2c-controller node and no
mctp-controller bus: the device binds to mctp-i2c and no netdev appears,
which is the state this patch covers. Not tested on hardware.
This change was prepared with the help of an AI coding assistant
(Claude); I reviewed it and stand behind it.
drivers/net/mctp/mctp-i2c.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/net/mctp/mctp-i2c.c b/drivers/net/mctp/mctp-i2c.c
index b02476d33..26e8ea7ff 100644
--- a/drivers/net/mctp/mctp-i2c.c
+++ b/drivers/net/mctp/mctp-i2c.c
@@ -238,8 +238,12 @@ static int mctp_i2c_slave_cb(struct i2c_client *client,
dev_hold(midev->ndev);
spin_unlock_irqrestore(&mcli->sel_lock, flags);
- if (!midev)
+ if (!midev) {
+ if (event == I2C_SLAVE_READ_REQUESTED ||
+ event == I2C_SLAVE_READ_PROCESSED)
+ *val = 0xff;
return 0;
+ }
switch (event) {
case I2C_SLAVE_READ_REQUESTED:
--
2.53.0