Skip to content

Commit

Permalink
i2c: core: Fix atomic xfer check for non-preempt config
Browse files Browse the repository at this point in the history
Since commit aa49c90 ("i2c: core: Run atomic i2c xfer when
!preemptible"), the whole reboot/power off sequence on non-preempt kernels
is using atomic i2c xfer, as !preemptible() always results to 1.

During device_shutdown(), the i2c might be used a lot and not all busses
have implemented an atomic xfer handler. This results in a lot of
avoidable noise, like:

[   12.687169] No atomic I2C transfer handler for 'i2c-0'
[   12.692313] WARNING: CPU: 6 PID: 275 at drivers/i2c/i2c-core.h:40 i2c_smbus_xfer+0x100/0x118
...

Fix this by allowing non-atomic xfer when the interrupts are enabled, as
it was before.

Link: https://lore.kernel.org/r/20231222230106.73f030a5@yea
Link: https://lore.kernel.org/r/[email protected]
Link: https://lore.kernel.org/linux-i2c/[email protected]/
Fixes: aa49c90 ("i2c: core: Run atomic i2c xfer when !preemptible")
Cc: [email protected] # v5.2+
Signed-off-by: Benjamin Bara <[email protected]>
Tested-by: Michael Walle <[email protected]>
Tested-by: Tor Vic <[email protected]>
[wsa: removed a comment which needs more work, code is ok]
Signed-off-by: Wolfram Sang <[email protected]>
  • Loading branch information
babnskidata authored and wsakernel committed Jan 6, 2024
1 parent 5cb23af commit a3368e1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/i2c/i2c-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* i2c-core.h - interfaces internal to the I2C framework
*/

#include <linux/kconfig.h>
#include <linux/rwsem.h>

struct i2c_devinfo {
Expand All @@ -29,7 +30,8 @@ int i2c_dev_irq_from_resources(const struct resource *resources,
*/
static inline bool i2c_in_atomic_xfer_mode(void)
{
return system_state > SYSTEM_RUNNING && !preemptible();
return system_state > SYSTEM_RUNNING &&
(IS_ENABLED(CONFIG_PREEMPT_COUNT) ? !preemptible() : irqs_disabled());
}

static inline int __i2c_lock_bus_helper(struct i2c_adapter *adap)
Expand Down

0 comments on commit a3368e1

Please sign in to comment.