Emit a warning if the bus master driver in the kernel did not set the message length correctly with I2C_M_RECV_LEN. This can be determined from the returned value in the buffer. Signed-off-by: Wolfram Sang <wsa+renesas@xxxxxxxxxxxxxxxxxxxx> --- I think it is useful, but maybe not the scope of a tool like i2ctransfer. Thoughts? tools/i2ctransfer.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/i2ctransfer.c b/tools/i2ctransfer.c index b0e8d43..f2a4df8 100644 --- a/tools/i2ctransfer.c +++ b/tools/i2ctransfer.c @@ -88,7 +88,12 @@ static void print_msgs(struct i2c_msg *msgs, __u32 nmsgs, unsigned flags) int recv_len = msgs[i].flags & I2C_M_RECV_LEN; int print_buf = (read && (flags & PRINT_READ_BUF)) || (!read && (flags & PRINT_WRITE_BUF)); - __u16 len = recv_len ? msgs[i].buf[0] + 1 : msgs[i].len; + __u16 len = msgs[i].len; + + if (recv_len && print_buf && len != msgs[i].buf[0] + 1) { + fprintf(stderr, "Correcting wrong msg length after recv_len! Please fix the I2C driver and/or report.\n"); + len = msgs[i].buf[0] + 1; + } if (flags & PRINT_HEADER) { fprintf(output, "msg %u: addr 0x%02x, %s, len ", -- 2.27.0