* [RFC PATCH i2c-tools] tools: i2ctransfer: add check for returned length from driver
@ 2020-08-06 14:56 Wolfram Sang
2020-08-29 15:41 ` Wolfram Sang
0 siblings, 1 reply; 2+ messages in thread
From: Wolfram Sang @ 2020-08-06 14:56 UTC (permalink / raw)
To: linux-i2c; +Cc: Daniel Stodden, Jean Delvare, Wolfram Sang
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(-)
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-08-29 15:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06 14:56 [RFC PATCH i2c-tools] tools: i2ctransfer: add check for returned length from driver Wolfram Sang
2020-08-29 15:41 ` Wolfram Sang
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.