linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c: avoid sleep in IRQ context
@ 2019-08-05 12:31 Fuqian Huang
       [not found] ` <20190807065111.GA17104@localhost.localdomain>
  0 siblings, 1 reply; 2+ messages in thread
From: Fuqian Huang @ 2019-08-05 12:31 UTC (permalink / raw)
  Cc: linux-i2c, linux-kernel, Fuqian Huang

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@gmail.com>
---
 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;
 	while (time_before(jiffies, timeout)) {
 		if (i2c_debug > 1)
 			dev_dbg(&i2c->adap.dev, "%s: %ld: ISR=%08x, ICR=%08x, IBMR=%02x\n",
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] i2c: avoid sleep in IRQ context
       [not found] ` <20190807065111.GA17104@localhost.localdomain>
@ 2019-08-07  7:04   ` Fuqian Huang
  0 siblings, 0 replies; 2+ messages in thread
From: Fuqian Huang @ 2019-08-07  7:04 UTC (permalink / raw)
  To: Adamski, Krzysztof (Nokia - PL/Wroclaw),
	linux-i2c, Linux Kernel Mailing List

Adamski, Krzysztof (Nokia - PL/Wroclaw) <krzysztof.adamski@nokia.com>
於 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@gmail.com>
> >---
> > 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",
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-07  7:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-05 12:31 [PATCH] i2c: avoid sleep in IRQ context Fuqian Huang
     [not found] ` <20190807065111.GA17104@localhost.localdomain>
2019-08-07  7:04   ` Fuqian Huang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).