I2C concurrent access on Linux, mutex I2C concurrent access on Linux, mutex linux linux

I2C concurrent access on Linux, mutex


I2C is a shared bus with multiple devices, which could be accessed from multiple processes as well as threads. So the Linux I2C driver code uses a mutex to manage access to each I2C bus.

For SMBus functions, see the Linux kernel function i2c_smbus_xfer() in i2c-core-smbus.c. It gets a lock for the I2C adapter before beginning a transfer (look at the source code, and see the call to __i2c_lock_bus_helper()). All SMBus transactions are based on that function.

For I2C functions, see the Linux kernel function i2c_transfer() in i2c-core-base.c. It gets a lock for the I2C adapter before beginning a transfer. All I2C transaction are based on that function.

So yes, there is protection from concurrent access built-in.

(links are for Linux kernel 5.13)


Use a mutex in your program. The driver has no way to know the operations that each thread is going to do.