提交 cea443a8 编写于 作者: M Mike Rapoport 提交者: Jean Delvare

i2c: Support i2c_transfer in atomic contexts

Allow i2c_transfer to be called in contexts where sleeping is not allowed.
It is the reponsability of the caller to ensure that the underlying i2c bus
driver will not sleep either.
Signed-off-by: NMike Rapoport <mike@compulab.co.il>
Signed-off-by: NJean Delvare <khali@linux-fr.org>
上级 5271071b
......@@ -33,6 +33,8 @@
#include <linux/platform_device.h>
#include <linux/mutex.h>
#include <linux/completion.h>
#include <linux/hardirq.h>
#include <linux/irqflags.h>
#include <asm/uaccess.h>
#include <asm/semaphore.h>
......@@ -861,7 +863,15 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
}
#endif
mutex_lock_nested(&adap->bus_lock, adap->level);
if (in_atomic() || irqs_disabled()) {
ret = mutex_trylock(&adap->bus_lock);
if (!ret)
/* I2C activity is ongoing. */
return -EAGAIN;
} else {
mutex_lock_nested(&adap->bus_lock, adap->level);
}
ret = adap->algo->master_xfer(adap,msgs,num);
mutex_unlock(&adap->bus_lock);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册