Netdev List
 help / color / mirror / Atom feed
From: Eric Yun Lin Chiang <ericyunlinchiang@gmail.com>
To: Jeremy Kerr <jk@codeconstruct.com.au>,
	Matt Johnston <matt@codeconstruct.com.au>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net] mctp i2c: initialise read bytes when no netdev is selected
Date: Fri,  4 Dec 2026 10:42:10 +0800	[thread overview]
Message-ID: <20261204024210.3013397-1-ericyunlinchiang@gmail.com> (raw)

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 <ericyunlinchiang@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


                 reply	other threads:[~2026-12-04  2:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204024210.3013397-1-ericyunlinchiang@gmail.com \
    --to=ericyunlinchiang@gmail.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=jk@codeconstruct.com.au \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeconstruct.com.au \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox