diff mbox series

[RFC,i2c-tools] tools: i2ctransfer: add check for returned length from driver

Message ID 20200806145658.1476-1-wsa+renesas@sang-engineering.com
State Accepted
Headers show
Series [RFC,i2c-tools] tools: i2ctransfer: add check for returned length from driver | expand

Commit Message

Wolfram Sang Aug. 6, 2020, 2:56 p.m. UTC
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@sang-engineering.com>
---

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(-)

Comments

Wolfram Sang Aug. 29, 2020, 3:41 p.m. UTC | #1
On Thu, Aug 06, 2020 at 04:56:58PM +0200, Wolfram Sang wrote:
> 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@sang-engineering.com>

Applied.
diff mbox series

Patch

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 ",