Skip to content

Commit

Permalink
i2c: Support i2c_transfer in atomic contexts
Browse files Browse the repository at this point in the history
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: Mike Rapoport <mike@compulab.co.il>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
  • Loading branch information
Mike Rapoport authored and Jean Delvare committed Jan 27, 2008
1 parent 5271071 commit cea443a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion drivers/i2c/i2c-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit cea443a

Please sign in to comment.