From: sashiko-bot@kernel.org
To: "Dmitry Guzman" <Dmitry.Guzman@mobileye.com>
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH v2 07/12] i2c: nomadik: add support for I2C_XFER_V2 - detailed fault reporting
Date: Thu, 03 Sep 2026 05:56:02 +0000 [thread overview]
Message-ID: <20260903055602.B5F311F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260903-i2c-fault-reporting-v2-7-fedeb91792e6@mobileye.com>
Thank you for your contribution! Sashiko AI review found 8 potential issue(s) to consider:
New issues:
- [High] The migration to the I2C_XFER_V2 API silently removed the hardcoded 3-attempt retry loop for transfers, breaking the driver's resilience against transient bus errors.
- [High] Removing `.xfer` from `i2c_algorithm` breaks downstream subsystems (like I2C multiplexers) that strictly check `.master_xfer`.
- [High] Heap out-of-bounds write in `i2cdev_ioctl_rdwr_v2` when updating the length of a partially transferred message.
- [High] Unconditional memory leak of I2C message buffers upon transfer failure in `i2cdev_ioctl_rdwr_v2`.
- [Medium] Unprotected lockless read of `priv->cli.xfer_bytes` in process context races with the hardirq handler.
- [Medium] Interrupt handler resets controller state before process context can read it, defeating the new byte-level reporting.
Pre-existing issues:
- [High] Missing return value check for pm_runtime_get_sync(), which can lead to a kernel crash if resume fails.
- [High] Missing synchronize_irq() in the timeout path leads to a Use-After-Free of message buffers by the interrupt handler.
--
commit 6e00e021c9abe420f0965de298c6d92c4d01241e
Author: Dmitry Guzman <Dmitry.Guzman@mobileye.com>
i2c: nomadik: add support for I2C_XFER_V2 - detailed fault reporting
I2C_XFER_V2 is a new API that allows I2C clients to get the detailed
report in case of transmission failure. Previously, the only information
returned by I2C bus controller was the error code, without exposing
how many messages or bytes had been sent. This commit introduces support
of this feature in the i2c-nomadik driver.
> diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
> index c36e9961e0a39..8b0ab191f7c1f 100644
> --- a/drivers/i2c/busses/i2c-nomadik.c
> +++ b/drivers/i2c/busses/i2c-nomadik.c
[ ... ]
> @@ -678,6 +683,16 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *priv, u16 flags)
> status = priv->result;
> }
>
> + if (flags & I2C_M_RD) {
> + /* For READ messages, return the number of bytes read from FIFO */
> + priv->bytes_cplt = priv->cli.xfer_bytes;
[Severity: Medium]
Is it safe to perform an unprotected lockless read of priv->cli.xfer_bytes
here? If the interrupt handler updates priv->cli.xfer_bytes concurrently on
an error or timeout path, could this regression cause the process context to
read a stale or inconsistent value?
> + } else {
> + /* For WRITE messages, return the number of bytes sent on bus */
> + priv->bytes_cplt = FIELD_GET(I2C_SR_LENGTH, i2c_sr);
[Severity: Medium]
When an I2C abort error occurs, the interrupt handler calls init_hw(),
which resets the I2C_SR register before process context can read it.
Does this race condition cause the newly introduced byte-level error
reporting to silently fail by returning 0 for bytes_cplt and missing
the abort cause printout?
> + /* LENGTH value includes the last byte that has not been sent or ACKed */
> + if (priv->bytes_cplt > 0)
> + priv->bytes_cplt--;
> + }
> init_hw(priv);
[Severity: High]
This is a pre-existing issue and was not introduced by the patch under
review, but missing synchronize_irq() in the timeout path leads to a
use-after-free. If a timeout occurs during an I2C transfer, this code path
frees the message buffer, but the interrupt handler could fire concurrently
on another CPU:
i2c_irq_handler()
*priv->cli.buffer = nmk_i2c_readb(priv, I2C_RFR);
Since init_hw() calls disable_all_interrupts() which only masks the IP block
but does not wait for running handlers, can this cause memory corruption by
writing to the concurrently freed buffer?
>
> status = status ? status : priv->result;
[ ... ]
> @@ -733,14 +749,16 @@ static int nmk_i2c_xfer_one(struct nmk_i2c_dev *priv, u16 flags)
> * please use the i2c_smbus_read_i2c_block_data()
> * or i2c_smbus_write_i2c_block_data() API
> */
> -static int nmk_i2c_xfer(struct i2c_adapter *i2c_adap,
> - struct i2c_msg msgs[], int num_msgs)
> +static int nmk_i2c_xfer_v2(struct i2c_adapter *i2c_adap,
> + struct i2c_msg msgs[], int num_msgs,
> + struct i2c_transfer_report *report)
> {
[Severity: High]
The migration to the I2C_XFER_V2 API silently removed the hardcoded 3-attempt
retry loop for transfers. Does this regression break the driver's resilience
against transient bus errors like lost arbitration or NACKs, causing failed
I2C transfers for device drivers?
> int status = 0;
> int i;
> struct nmk_i2c_dev *priv = i2c_get_adapdata(i2c_adap);
>
> pm_runtime_get_sync(&priv->adev->dev);
[Severity: High]
This is a pre-existing issue and was not introduced by the patch under
review, but the return value of pm_runtime_get_sync() is unchecked here. If
the power domain fails to resume and returns an error, execution continues
to setup_i2c_controller(), which could lead to a kernel panic from accessing
unclocked or unpowered registers. Should we check the return value before
proceeding?
> + priv->bytes_cplt = 0;
>
> /* setup the i2c controller */
[ ... ]
> @@ -1014,7 +1039,7 @@ static unsigned int nmk_i2c_functionality(struct i2c_adapter *adap)
> }
>
> static const struct i2c_algorithm nmk_i2c_algo = {
> - .xfer = nmk_i2c_xfer,
> + .xfer_v2 = nmk_i2c_xfer_v2,
[Severity: High]
Does removing .xfer from i2c_algorithm break downstream subsystems like I2C
multiplexers? When a multiplexer attached to this bus attempts to register
its transfer methods, it strictly checks parent->algo->master_xfer. Since
.xfer is removed, the .master_xfer field (which is aliased via a union)
evaluates to NULL, causing multiplexed I2C transfers to consistently fail
with -EOPNOTSUPP.
> .functionality = nmk_i2c_functionality
> };
Looking at i2cdev_ioctl_rdwr_v2() in drivers/i2c/i2c-dev.c introduced earlier
in this series:
drivers/i2c/i2c-dev.c:i2cdev_ioctl_rdwr_v2() {
...
if (user_report) {
res = i2c_transfer_v2(client->adapter, msgs, nmsgs, &report);
i = report.msgs_cplt;
} else {
res = i2c_transfer(client->adapter, msgs, nmsgs);
if (res < 0)
i = 0;
else
i = nmsgs;
}
...
while (i-- > 0) {
if (msgs[i].flags & I2C_M_RD) {
if (copy_to_user(data_ptrs[i], msgs[i].buf,
msgs[i].len))
res = -EFAULT;
}
kfree(msgs[i].buf);
}
...
}
[Severity: High]
Does this regression leak the un-transferred message buffers? When an I2C
transfer involving multiple messages fails partway through, the loop index i
is reassigned to the number of completed messages. This truncates the cleanup
loop, skipping the kfree(msgs[i].buf) for all subsequent allocated message
buffers.
Further down in i2cdev_ioctl_rdwr_v2():
drivers/i2c/i2c-dev.c:i2cdev_ioctl_rdwr_v2() {
...
/* Number of messages transferred completely or partially */
if (report.bytes_cplt > 0) {
i++;
msgs[i].len = report.bytes_cplt;
}
...
}
[Severity: High]
Can this regression corrupt memory with an out-of-bounds write? The code
incorrectly increments i before writing report.bytes_cplt to msgs[i].len.
If nmsgs == 1 and the only message faults, this writes entirely outside the
msgs array, or otherwise corrupts the length of the next message.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260903-i2c-fault-reporting-v2-0-fedeb91792e6@mobileye.com?part=7
next prev parent reply other threads:[~2026-09-03 5:56 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-03 5:38 [PATCH v2 00/12] I2C - detailed transfer reporting in case of a fault Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 01/12] i2c: core: add I2C_XFER_V2 - support for detailed transfer reporting Dmitry Guzman
2026-09-03 5:52 ` sashiko-bot
2026-09-03 7:21 ` Andy Shevchenko
2026-09-04 10:53 ` Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 02/12] i2c: nomadik: optimize struct layout, change unsigned char into u8 Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 03/12] i2c: nomadik: do not try to retransmit I2C message series on errors Dmitry Guzman
2026-09-03 5:53 ` sashiko-bot
2026-09-03 5:38 ` [PATCH v2 04/12] i2c: nomadik: return proper fault codes Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 05/12] i2c: nomadik: change print level for fault messages to debug Dmitry Guzman
2026-09-03 5:50 ` sashiko-bot
2026-09-03 5:38 ` [PATCH v2 06/12] i2c: nomadik: add quirks max_len=2047 and no_zero_len_read Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 07/12] i2c: nomadik: add support for I2C_XFER_V2 - detailed fault reporting Dmitry Guzman
2026-09-03 5:56 ` sashiko-bot [this message]
2026-09-03 5:38 ` [PATCH v2 08/12] i2c: designware: return proper fault codes Dmitry Guzman
2026-09-03 5:38 ` [PATCH v2 09/12] i2c: designware: no SMBUS_READ_BLOCK_DATA without EMPTYFIFO_HOLD_MASTER Dmitry Guzman
2026-09-03 7:39 ` Andy Shevchenko
2026-09-03 5:38 ` [PATCH v2 10/12] i2c: designware: stop transfer if spurious STOP is detected Dmitry Guzman
2026-09-03 5:49 ` sashiko-bot
2026-09-03 5:38 ` [PATCH v2 11/12] i2c: designware: use separate `i2c_algorithm` for AMD_NAVI_GPU Dmitry Guzman
2026-09-03 5:56 ` sashiko-bot
2026-09-03 5:38 ` [PATCH v2 12/12] i2c: designware: add support for I2C_XFER_V2 - detailed fault reporting Dmitry Guzman
2026-09-03 5:59 ` sashiko-bot
2026-09-03 7:47 ` Andy Shevchenko
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=20260903055602.B5F311F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Dmitry.Guzman@mobileye.com \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.