Re: [PATCH RFC v3 00/14] I2C - detailed transfer reporting in case of a fault

From: Jonathan Cameron

Date: Thu Nov 05 2026 - 14:17:19 EST


On Thu, 05 Nov 2026 19:15:21 +0200
Dmitry Guzman <Dmitry.Guzman@xxxxxxxxxxxx> wrote:

> The existing API has function i2c_transfer() that transfers one or more
> messages, and it only returns a single error code if the transfer was
> failed. It doesn't allow to know how many of the messages were
> transferred successfully, neither how many bytes were transferred in the
> message that caused the fault, and also it drops all data received from
> target device before the fault. There is a comment about this in
> drivers/i2c/i2c-core-base.c: "REVISIT the fault reporting model here is
> weak".
>
> This patch series introduces new API function i2c_transfer_v2() that does
> the same as i2c_transfer() but also returns detailed transfer report,
> including number of messages and bytes transferred before the fault. This
> also allows caller to get the bytes read from the target before the fault
> occurred.

Hi Dmitry,

Just for background, could you provide some more information on why this
information is useful? For kernel side drivers it is remarkably rare to
find a real use case of partial transfer information and the
current i2c_transfer() return value approach complicates a lot of
drivers for very limited benefit. Sure it is a small complication
to check for a low message count, but you do get a lot cases of it!

That leads to a mass of AI reports of bugs. It would have been
much better for kernel side if it just returned an error code
on any short transfer.

Given this is effectively going in the opposite direction I'd like to
know more.

Jonathan


>
> For user space clients, new ioctl `I2C_RDWR_V2` is introduced.
>
> Patch for `i2c-tools` user space utility that introduces support of this
> feature:
>
> https://lore.kernel.org/linux-i2c/20260623-i2c_detailed_report-v1-1-b67259a31a9d@xxxxxxxxxxxx/
>
> Below there are several usage examples with modified i2c-tools.
>
> - Unsupported message (max length supported by I2C controller is 2047):
>
> # i2ctransfer -y 0 -r w1@0x19 0 r8000
> Error: Operation not supported at message 1
> 0 out of 2 messages sent
> #
>
> - First two messages transferred successfully, the third one is sent to
> non-existent target address and thus is not ACKed. The data read in the
> second message is available for the caller:
>
> # i2ctransfer -y 0 -r w1@0x19 0 r1 w1@0x1a 0
> Error: No such device or address at message 2
> 2 out of 3 messages sent
> 0x32
> #
>
> - Target ACKs first two bytes but sends NACK on the third byte:
>
> # i2ctransfer -r -y 0 w4@0x09 0x80 0x80 0x55 0x55
> Error: Input/output error at message 0
> 0 out of 1 messages sent
> Message 0: 2 out of 4 bytes sent
> #
>
> - Message reading is not finished due to timeout. The data read before
> timeout is available:
>
> # i2ctransfer -y 0 -r r100@0x19
> Error: Connection timed out at message 0
> 0 out of 1 messages sent
> Message 0: 16 out of 100 bytes sent
> 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> #
>
> - Driver does not support detailed fault reporting:
>
> # i2ctransfer -y 0 -r r1@0x19
> Error: Sending messages failed: Operation not supported
> #