i2c: core-smbus: don't trace smbus_reply data on errors
authorJohn Sperbeck <jsperbeck@google.com>
Wed, 13 Feb 2019 03:40:57 +0000 (19:40 -0800)
committerWolfram Sang <wsa@the-dreams.de>
Thu, 14 Feb 2019 17:01:33 +0000 (18:01 +0100)
If an smbus transfer fails, there's no guarantee that the output
buffer was written.  So, avoid trying to show the output buffer when
tracing after an error.  This was 'mostly harmless', but would trip
up kasan checking if left-over cruft in byte 0 is a large length,
causing us to read from unwritten memory.

Signed-off-by: John Sperbeck <jsperbeck@google.com>
Reviewed-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/i2c-core-smbus.c
include/trace/events/smbus.h

index 9cd66cabb84fd3fc298a93fed6be50bddd330eb4..1321191125965a9f5ef6c1b684ff29641a24496a 100644 (file)
@@ -585,7 +585,7 @@ s32 __i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
 trace:
        /* If enabled, the reply tracepoint is conditional on read_write. */
        trace_smbus_reply(adapter, addr, flags, read_write,
-                         command, protocol, data);
+                         command, protocol, data, res);
        trace_smbus_result(adapter, addr, flags, read_write,
                           command, protocol, res);
 
index d2fb6e1d3e10a2efcbb832019b174e98cc0f64e5..a4892a18784249bc42e1733e21dace5643176e71 100644 (file)
@@ -138,9 +138,9 @@ TRACE_EVENT_CONDITION(smbus_reply,
        TP_PROTO(const struct i2c_adapter *adap,
                 u16 addr, unsigned short flags,
                 char read_write, u8 command, int protocol,
-                const union i2c_smbus_data *data),
-       TP_ARGS(adap, addr, flags, read_write, command, protocol, data),
-       TP_CONDITION(read_write == I2C_SMBUS_READ),
+                const union i2c_smbus_data *data, int res),
+       TP_ARGS(adap, addr, flags, read_write, command, protocol, data, res),
+       TP_CONDITION(res >= 0 && read_write == I2C_SMBUS_READ),
        TP_STRUCT__entry(
                __field(int,    adapter_nr              )
                __field(__u16,  addr                    )