@@ -2068,6 +2068,11 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
{
int ret;
+ if (adap->blocked) {
+ dev_info(&adap->dev, "No more i2c communication is allowed! pid = %d\n", current->pid);
+ return -EPERM;
+ }
+
/* REVISIT the fault reporting model here is weak:
*
* - When we get an error after receiving N bytes from a slave,
@@ -519,6 +519,7 @@ struct i2c_adapter {
struct i2c_bus_recovery_info *bus_recovery_info;
const struct i2c_adapter_quirks *quirks;
+ bool blocked;
};
#define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev)
TODO use mutex and mutex_try_lock instead of boolean flag. Avoid that multiple consumers can block the adapter at the same time. This flag is only intended to be used in the shutdown process in which no cleanup is required. Signed-off-by: Stefan Christ <s.christ@phytec.de> --- drivers/i2c/i2c-core.c | 5 +++++ include/linux/i2c.h | 1 + 2 files changed, 6 insertions(+)