[PATCH RFC v3 03/14] i2c: core: add helper functions for transfer report generation

Dmitry Guzman Dmitry.Guzman at mobileye.com
Thu Nov 5 09:15:24 PST 2026


Add three helper functions for I2C transfer report generation:

- i2c_transfer_report_init() that puts -EOPNOTSUPP in all struct fields
  (this should be used if the defailed reporting is not supported);

- i2c_transfer_report_success() that is used to generate the report in
  success case (all messages are transferred successfully);

- i2c_transfer_report_bad_msg() that is used if one of messages cannot
  be transferred and no data were actually transferred.

Signed-off-by: Dmitry Guzman <Dmitry.Guzman at mobileye.com>
---
 include/linux/i2c.h | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index bf7dc12f7264..9bee726592fc 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -601,6 +601,27 @@ struct i2c_algorithm {
 #endif
 };
 
+static inline void i2c_transfer_report_init(struct i2c_transfer_report *report)
+{
+	report->msgs_cplt = -EOPNOTSUPP;
+	report->fault_msg_idx = -EOPNOTSUPP;
+	report->bytes_cplt = -EOPNOTSUPP;
+}
+
+static inline void i2c_transfer_report_success(struct i2c_transfer_report *report, int num)
+{
+	report->msgs_cplt = num;
+	report->fault_msg_idx = num;
+	report->bytes_cplt = 0;
+}
+
+static inline void i2c_transfer_report_bad_msg(struct i2c_transfer_report *report, int i)
+{
+	report->msgs_cplt = 0;
+	report->bytes_cplt = 0;
+	report->fault_msg_idx = i;
+}
+
 /**
  * struct i2c_lock_operations - represent I2C locking operations
  * @lock_bus: Get exclusive access to an I2C bus segment

-- 
2.43.0




More information about the linux-arm-kernel mailing list