From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796362198; b=vLeEDFl8mF6/Nu3jFbDk7fFDPsWT/lFVyLnp6rFcJq8lEV/7iYMOFmOWigsZab3t7UyD pQdEovVTDS6QVwWd1GOJ28xFc0sxTwBKwUiltcbbklOjG90pMDZayJyVJw/zHrjlDfz5y Q2EOLaISJ3z7GX0Rr88FJ3u2e1DHfTwcegUgdCviD5jTOmlqH2N2ZRbnJTG0ZYumFgBmu NgrPF3f4craWj6Ab08FCjbmJHKqBcDr47hr2rNRS7sfbn9sLQ5YvYxMp7maL0pG5UqLKY Y0OAJpKN+sfj5Lrl/O+skh1gKFT5eT+W4uTtyuuz/OnORemeqQPKXHTKTLGs/rpls0g== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796362198; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=40TCHYh/IWtwyluGOdEALQIAXath1hlNzarxrBhpQ/s=; b=DkWd+b0imjRUHHmomWAjlL0wa2Gn+nIRgBvoJWaL9h8GFOBE2HgVQUkGKKIYJNaeZo+3 d8RxA9e/uB3p8iFEbr8CnVPKBBMbnod8+INyZDE86Fv9bSpcB1GW06HfbqPyXu2aQiPQ3 NZVO3Id8m1F2sIuOYpOFYNV0e3C6YMjmBACBu6j+6bvskoGnTuk7s9EEzrWVOTVpKDGbo TeY48cXqsn0T7Lz8G/qw8lZX1IMJvdHav3TWJVLCIKGMVfe449euoC+E8H7+RpEru9Vx7 E1I0Ea8Bhc3C+zr34UY+IA5dVAhzjACqJiP/rux7jBU+J3zKfLEWSZDSWLKSREazo9w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cwHdozDX; arc=none smtp.remote-ip=209.85.214.169 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7F28A606A322 for ; Fri, 4 Dec 2026 05:29:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F28A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cwHdozDX Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2f1a4443407so4018245ad.3 for ; Thu, 03 Dec 2026 21:29:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796362198; x=1796966998; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=40TCHYh/IWtwyluGOdEALQIAXath1hlNzarxrBhpQ/s=; b=cwHdozDX8jsmi/x5mYyuWUidnO9rCadhByVQge2kFEJ7Cvy2vw/ZcGt/N68xqOAABk LGLek1MB0QymXDWZgAG3E9Pal0+X6m6HmoZcG6EvoIFW/JIfKyW16KUambecHKCaakyV 9AmtvXvSXPYCuFE8UyQI/KVh2fjR9xrpJ0L6b9qwB2jxMqq8Ru8Of4l/hJ12SpCbEtpy ic6K9P8TESffSxmt0vXQ/Qz3DtN5fW4EjK0SNgVQJPtQTT0OUios72R5I3WKplM6UP+U 5QRtoxVDfrdEuBKdn6eW56DtxjfSzz4m4uxDOlMwb1LtASVByqJa30B3QjtHODDRoiPi MHIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796362198; x=1796966998; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=40TCHYh/IWtwyluGOdEALQIAXath1hlNzarxrBhpQ/s=; b=V/cui+FR6V42b2BKRTK9eQeht+9s7Bi48bSgB4gqfTo3aVAmeZL9XSyzsh+kvNuRXw 1vyHTVGd0mWxM9SRfU5yez7PkxwDgziUzSmZ6cwGMzrwVBzpFS9a4DwbATlBU4x23VE+ m11b2gsshNRNkOX1waM9baiKhrz5tEGAq4e9uSVsCBq5j4DA8flFarXbIxkB694da9GR jlnvuE3XyH6yPJ06LBk1K+m4Oea5KwPyqO+mz5Xu76mR3P8P7IAm4jDfUKUhoUJTvMA6 v8FElrsUiA3L9s1tRVkvou3HcHgIcGtq1MxUFql04J1ADbfVff0amR5+8h2ZwpWbzPK2 62FQ== X-Forwarded-Encrypted: i=1; AL+hErFTW9+iokStwh15CeI/voTFHtexBl7gAxqRLiagJ1v9DOJug60UMCP35jR2rm83W/Z+0M/xfBXm6jpoAEI=@vger.kernel.org X-Gm-Message-State: APuU4Z+XvV/pM2S61yuDAtnOP6eLvLh/GJu6VsRjH4IHQx9Z5q4tqjyo JzVgn5pKwQlGQ+DY1aF5zvZoVw4iAbbknL6P/p1L3pdFHNX855PkbbVI X-Gm-Gg: AZFdTZfMWaQQX2vr0RkCQNl95QvJOe8If9y8mTYX6D0IhLePK2V/ryK0JOLPghG5EbV cBLBF4v13QWdOOlvPZf4tagLjDn2X3NEU2JMIsGh+0Pc93zjVf8zx3aIDLJPmn7gRMo9fwZMR3D /VXKrITePawBP08RWmQmcdqnEBcB7boaTvXNcsY2WV+0Dz29qEzvzInDKojIRgOF060eC8yGwm+ pr/GdfM6uSiRGt62NI6ZRO6FiMRkgf4PIXjoEG0DAcPdalPbFgFt7/H4g4a+dU0awzenxdQBNt3 jSsbOf3dWne55VER2yXrvjPjLoqb1TwqV/1IF2dki/Qn5WzJ58nbiyvIfkr95F9TQ+V9M5s7q7q c0mHEJBYbe8Wh+uThvaHqpzENcpIOPbvxHpDX5a/jrWsXlURwqTZUmfSZ3zIW8yK5qq3jmiNMy2 nFnRh+R3ojOsL7dbWwKbouSOmAfIZMzz0Z8dM0bA+RBItNOtrTpV0rvc+Rfa2CKu2q6QLWhuWkp mqy/T34EaPqd0xSlP7puxWRJlrgPIrPJx1/dVijiWWxIFxUPPQ6yHO8eEvxXyKFRXRdCX4I9Ckw vSDsRMneMJSfdpLHRxASGeylcq1Cu8grBqrKcpfu8SQTzxRxzwSt6GmgGR5kRiCJbt4gDg== X-Received: by 2002:a17:902:e847:b0:2ef:e0f6:b8f2 with SMTP id d9443c01a7336-2f1ba2323c5mr9013625ad.51.1796362197310; Thu, 03 Dec 2026 21:29:57 -0800 (PST) Received: from eric-N-A (61-220-246-151.hinet-ip.hinet.net. [61.220.246.151]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f1b784e830sm4965845ad.3.2026.12.03.21.29.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 21:29:56 -0800 (PST) From: Eric Yun Lin Chiang To: Andi Shyti Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] i2c: core: default read events to 0xff in i2c_slave_event() Date: Fri, 4 Dec 2026 13:29:16 +0800 Message-ID: <20261204052916.2712613-1-ericyunlinchiang@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit After I2C_SLAVE_READ_REQUESTED and I2C_SLAVE_READ_PROCESSED the bus driver sends whatever *val holds. If the backend does not set it, that is whatever the bus driver had there: for i2c-aspeed and i2c-npcm7xx an uninitialised stack byte. Backends have missed this more than once. 2a14e91b6d76 ("mctp i2c: initialise event handler read bytes") fixed it for mctp-i2c, but an early return in the same callback still skips it, and ipmb_dev_int has no read case at all. Each needs its own fix, and the next backend can make the same mistake. Set *val to 0xff, the idle level of the bus, before the callback for the two read events, so a backend that leaves it unchanged sends 0xff. A backend that sets a value is unaffected, and write events are not touched. Update slave-interface.rst to say so. Signed-off-by: Eric Yun Lin Chiang --- Sending this as RFC because I am not sure the core is the right place: it hides the mistake rather than flagging it, and some may prefer to keep fixing backends one by one. The two backend fixes are on the list and are useful for stable either way: https://lore.kernel.org/all/20261203063440.3753378-1-ericyunlinchiang@gmail.com/ https://lore.kernel.org/all/20261204024210.3013397-1-ericyunlinchiang@gmail.com/ Tested: a local KUnit test (UML, KASAN) on i2c_slave_event() with a backend that ignores read events: *val preset to 0xa5 stays 0xa5 without this patch and becomes 0xff with it; a backend that sets 0x5a still gets 0x5a sent, and WRITE_RECEIVED data reaches the backend unchanged. Also built for ARM (aspeed_g5_defconfig with I2C_SLAVE and MCTP_TRANSPORT_I2C) and booted on QEMU ast2600-evb with an mctp-i2c target bound, with no new warnings. Not tested on hardware. This change was prepared with the help of an AI coding assistant (Claude); I reviewed it and stand behind it. Documentation/i2c/slave-interface.rst | 7 +++++-- drivers/i2c/i2c-core-slave.c | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Documentation/i2c/slave-interface.rst b/Documentation/i2c/slave-interface.rst index 3f0d320bc..0d38f82e4 100644 --- a/Documentation/i2c/slave-interface.rst +++ b/Documentation/i2c/slave-interface.rst @@ -84,7 +84,9 @@ a retry of the transmission. * I2C_SLAVE_READ_REQUESTED (mandatory) - 'val': backend returns first byte to be sent + 'val': backend returns first byte to be sent. The core sets it to 0xff + before calling the backend, so 0xff is sent if the backend leaves it + unchanged. 'ret': always 0 @@ -104,7 +106,8 @@ should be nacked. * I2C_SLAVE_READ_PROCESSED (mandatory) - 'val': backend returns next byte to be sent + 'val': backend returns next byte to be sent. As for + I2C_SLAVE_READ_REQUESTED, the core sets it to 0xff first. 'ret': always 0 diff --git a/drivers/i2c/i2c-core-slave.c b/drivers/i2c/i2c-core-slave.c index bebb7ba67..6fb34e388 100644 --- a/drivers/i2c/i2c-core-slave.c +++ b/drivers/i2c/i2c-core-slave.c @@ -86,7 +86,17 @@ EXPORT_SYMBOL_GPL(i2c_slave_unregister); int i2c_slave_event(struct i2c_client *client, enum i2c_slave_event event, u8 *val) { - int ret = client->slave_cb(client, event, val); + int ret; + + /* + * The bus driver sends whatever *val holds after a read event. Give it a + * defined value, the idle level of the bus, in case the backend does not + * set one. + */ + if (event == I2C_SLAVE_READ_REQUESTED || event == I2C_SLAVE_READ_PROCESSED) + *val = 0xff; + + ret = client->slave_cb(client, event, val); if (trace_i2c_slave_enabled()) trace_call__i2c_slave(client, event, val, ret); -- 2.53.0