Re: [PATCH v7 2/5] i2c: core: run atomic i2c xfer when !preemptible

From: Benjamin Bara
Date: Mon Nov 13 2023 - 10:48:42 EST


Hi!

Thanks for testing and the feedback!

On Mon, 13 Nov 2023 at 15:54, Chris Morgan <macroalpha82@xxxxxxxxx> wrote:
> I can confirm I no longer get any of the errors with this patch. Tested
> on both an Anbernic RG353P (RK3566 with an RK817 PMIC) and an Odroid
> Go Advance (RK3326 with an RK817 PMIC). The device appears to shut
> down consistently again and I no longer see these messages in my dmesg
> log when I shut down.

Just to make sure: Are you compiling with CONFIG_PREEMPTION (and
therefore CONFIG_PREEMPT_COUNT)?

If yes, could you please also test the following patch? Because I am not
sure yet how polling can be false in a "polling required" situation,
meaning .master_xfer() is called instead of .master_xfer_atomic() (while
your test shows that irq_disabled() is true, which is basically done
with !preemptible()). The patch should test the other way round: if the
situation is found, force an atomic transfer instead.

Thank you!

diff --git a/drivers/i2c/busses/i2c-rk3x.c b/drivers/i2c/busses/i2c-rk3x.c
index a044ca0c35a1..6e3e8433018f 100644
--- a/drivers/i2c/busses/i2c-rk3x.c
+++ b/drivers/i2c/busses/i2c-rk3x.c
@@ -1131,6 +1131,10 @@ static int rk3x_i2c_xfer_common(struct i2c_adapter *adap,
static int rk3x_i2c_xfer(struct i2c_adapter *adap,
struct i2c_msg *msgs, int num)
{
+ if (irqs_disabled()) {
+ WARN_ONCE(1, "Landed in non-atomic handler with disabled IRQs");
+ return rk3x_i2c_xfer_common(adap, msgs, num, true);
+ }
return rk3x_i2c_xfer_common(adap, msgs, num, false);
}