[PATCH RFC v3 03/14] i2c: core: add helper functions for transfer report generation
From: Dmitry Guzman
Date: Thu Nov 05 2026 - 12:25:46 EST
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@xxxxxxxxxxxx>
---
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