linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] i2c: avoid sleep in IRQ context
@ 2019-08-07  7:18 Fuqian Huang
  2019-08-14 10:07 ` Wolfram Sang
  0 siblings, 1 reply; 2+ messages in thread
From: Fuqian Huang @ 2019-08-07  7:18 UTC (permalink / raw)
  Cc: Greg Kroah-Hartman, 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.
When in interrupt context, use mdelay instead of msleep.

Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>
---
 drivers/i2c/busses/i2c-pxa.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 2c3c3d6935c0..876e693bafd9 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -456,7 +456,10 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
 			return 1;
 		}
 
-		msleep(1);
+		if (in_interrupt())
+			mdelay(1);
+		else
+			msleep(1);
 	}
 
 	if (i2c_debug > 0)
-- 
2.11.0


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

* Re: [PATCH v2] i2c: avoid sleep in IRQ context
  2019-08-07  7:18 [PATCH v2] i2c: avoid sleep in IRQ context Fuqian Huang
@ 2019-08-14 10:07 ` Wolfram Sang
  0 siblings, 0 replies; 2+ messages in thread
From: Wolfram Sang @ 2019-08-14 10:07 UTC (permalink / raw)
  To: Fuqian Huang, Russell King; +Cc: Greg Kroah-Hartman, linux-i2c, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1105 bytes --]

On Wed, Aug 07, 2019 at 03:18:07PM +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.
> When in interrupt context, use mdelay instead of msleep.
> 
> Signed-off-by: Fuqian Huang <huangfq.daxian@gmail.com>

Adding RMK to CC because he is the PXA I2C slave user I know of.

> ---
>  drivers/i2c/busses/i2c-pxa.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
> index 2c3c3d6935c0..876e693bafd9 100644
> --- a/drivers/i2c/busses/i2c-pxa.c
> +++ b/drivers/i2c/busses/i2c-pxa.c
> @@ -456,7 +456,10 @@ static int i2c_pxa_wait_slave(struct pxa_i2c *i2c)
>  			return 1;
>  		}
>  
> -		msleep(1);
> +		if (in_interrupt())
> +			mdelay(1);
> +		else
> +			msleep(1);
>  	}
>  
>  	if (i2c_debug > 0)
> -- 
> 2.11.0
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2019-08-14 10:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-07  7:18 [PATCH v2] i2c: avoid sleep in IRQ context Fuqian Huang
2019-08-14 10:07 ` Wolfram Sang

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).