Re: [PATCH] i2c: avoid sleep in IRQ context

From: Fuqian Huang
Date: Wed Aug 07 2019 - 03:05:05 EST


Adamski, Krzysztof (Nokia - PL/Wroclaw) <krzysztof.adamski@xxxxxxxxx>
æ 2019å8æ7æéä äå2:51åéï
>
> On Mon, Aug 05, 2019 at 08:31:34PM +0800, Fuqian Huang wrote:
> >i2c_pxa_handler -> i2c_pxa_irq_txempty ->
> >i2c_pxa_reset -> i2c_pxa_set_slave -> i2c_pxa_wait_slave
> >
> >As i2c_pxa_handler is an interrupt handler, it will finally
> >calls i2c_pxa_wait_slave which calls msleep.
> >
> >Add in_interrupt check before msleep to avoid sleep
> >in IRQ context.
> >
> >Signed-off-by: Fuqian Huang <huangfq.daxian@xxxxxxxxx>
> >---
> > drivers/i2c/busses/i2c-pxa.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> >diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> >index 2c3c3d6935c0..b35a0e8efcb2 100644
> >--- a/drivers/i2c/busses/i2c-pxa.c
> >+++ b/drivers/i2c/busses/i2c-pxa.c
> >@@ -443,6 +443,8 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
> >
> > show_state(i2c);
> >
> >+ if (in_interrupt())
> >+ return 0;
>
> Sleeping in irq context is not good indeed but if you just return here,
> an error will be printed from i2c_pxa_set_slave() and cleanup of ICR
> will be skipped. Is that ok?
Sorry for this mistake.
Maybe it should be changed to mdelay.
And the new patch is like this:
if (in_interrupt()) {
mdelay(1);
} else {
msleep(1);
}
>
> > while (time_before(jiffies, timeout)) {
> > if (i2c_debug > 1)
> > dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
>