All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: dgnc: usleep_range is preferred over udelay
@ 2016-02-11 13:14 Aybuke Ozdemir
  2016-02-11 15:50 ` [Outreachy kernel] " Tejun Heo
  2016-02-12  3:51 ` Greg KH
  0 siblings, 2 replies; 5+ messages in thread
From: Aybuke Ozdemir @ 2016-02-11 13:14 UTC (permalink / raw)
  To: outreachy-kernel; +Cc: Aybuke Ozdemir

This patch fixes the issue:

CHECK: usleep_range is preferred over udelay; see
Documentation/timers/timers-howto.txt

Signed-off-by: Aybuke Ozdemir <aybuke.147@gmail.com>
---
 drivers/staging/dgnc/dgnc_cls.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
index 72f0aaa..ce1471b 100644
--- a/drivers/staging/dgnc/dgnc_cls.c
+++ b/drivers/staging/dgnc/dgnc_cls.c
@@ -956,7 +956,7 @@ static void cls_flush_uart_read(struct channel_t *ch)
 	 * Presumably, this is a bug in this UART.
 	 */
 
-	udelay(10);
+	usleep_range(10, 100);
 }
 
 static void cls_copy_data_from_queue_to_uart(struct channel_t *ch)
@@ -1116,7 +1116,7 @@ static void cls_assert_modem_signals(struct channel_t *ch)
 	writeb(out, &ch->ch_cls_uart->mcr);
 
 	/* Give time for the UART to actually drop the signals */
-	udelay(10);
+	usleep_range(10, 100);
 }
 
 static void cls_send_start_character(struct channel_t *ch)
@@ -1170,7 +1170,7 @@ static void cls_uart_init(struct channel_t *ch)
 
 	writeb((UART_FCR_ENABLE_FIFO|UART_FCR_CLEAR_RCVR|UART_FCR_CLEAR_XMIT),
 	       &ch->ch_cls_uart->isr_fcr);
-	udelay(10);
+	usleep_range(10, 100);
 
 	ch->ch_flags |= (CH_FIFO_ENABLED | CH_TX_FIFO_EMPTY | CH_TX_FIFO_LWM);
 
-- 
2.1.4



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

* Re: [Outreachy kernel] [PATCH] staging: dgnc: usleep_range is preferred over udelay
  2016-02-11 13:14 [PATCH] staging: dgnc: usleep_range is preferred over udelay Aybuke Ozdemir
@ 2016-02-11 15:50 ` Tejun Heo
  2016-02-11 15:53   ` Julia Lawall
  2016-02-12  3:51 ` Greg KH
  1 sibling, 1 reply; 5+ messages in thread
From: Tejun Heo @ 2016-02-11 15:50 UTC (permalink / raw)
  To: Aybuke Ozdemir; +Cc: outreachy-kernel

Hello,

On Thu, Feb 11, 2016 at 03:14:30PM +0200, Aybuke Ozdemir wrote:
> @@ -956,7 +956,7 @@ static void cls_flush_uart_read(struct channel_t *ch)
>  	 * Presumably, this is a bug in this UART.
>  	 */
>  
> -	udelay(10);
> +	usleep_range(10, 100);
>  }

So, one important difference between udelay() and usleep_range() is
that the former can be called from any context while the latter only
from a blockable context as it's asking to be scheduled away.  These
uart functions seem to be accessing hardware directly which usually
indicate that they need to be synchronized somehow.

grepping for flush_uart_ shows that these function are called under a
channel_t->ch_lock spinlock, so this patch will end up triggering a
sanity check in the scheduler and leave the kernel in a buggy state
when the usleep_range()'s are called.

Please don't forget to cc the original author or maintainer of the
code being modified.

Thanks.

-- 
tejun


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

* Re: [Outreachy kernel] [PATCH] staging: dgnc: usleep_range is preferred over udelay
  2016-02-11 15:50 ` [Outreachy kernel] " Tejun Heo
@ 2016-02-11 15:53   ` Julia Lawall
  2016-02-11 15:58     ` Tejun Heo
  0 siblings, 1 reply; 5+ messages in thread
From: Julia Lawall @ 2016-02-11 15:53 UTC (permalink / raw)
  To: Tejun Heo; +Cc: Aybuke Ozdemir, outreachy-kernel



On Thu, 11 Feb 2016, Tejun Heo wrote:

> Hello,
>
> On Thu, Feb 11, 2016 at 03:14:30PM +0200, Aybuke Ozdemir wrote:
> > @@ -956,7 +956,7 @@ static void cls_flush_uart_read(struct channel_t *ch)
> >  	 * Presumably, this is a bug in this UART.
> >  	 */
> >
> > -	udelay(10);
> > +	usleep_range(10, 100);
> >  }
>
> So, one important difference between udelay() and usleep_range() is
> that the former can be called from any context while the latter only
> from a blockable context as it's asking to be scheduled away.  These
> uart functions seem to be accessing hardware directly which usually
> indicate that they need to be synchronized somehow.
>
> grepping for flush_uart_ shows that these function are called under a
> channel_t->ch_lock spinlock, so this patch will end up triggering a
> sanity check in the scheduler and leave the kernel in a buggy state
> when the usleep_range()'s are called.
>
> Please don't forget to cc the original author or maintainer of the
> code being modified.

Actually, no, they should only write to the list.

Thanks for the explanation otherwise.

julia


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

* Re: [Outreachy kernel] [PATCH] staging: dgnc: usleep_range is preferred over udelay
  2016-02-11 15:53   ` Julia Lawall
@ 2016-02-11 15:58     ` Tejun Heo
  0 siblings, 0 replies; 5+ messages in thread
From: Tejun Heo @ 2016-02-11 15:58 UTC (permalink / raw)
  To: Julia Lawall; +Cc: Aybuke Ozdemir, outreachy-kernel

Hello, Julia.

On Thu, Feb 11, 2016 at 04:53:49PM +0100, Julia Lawall wrote:
> > Please don't forget to cc the original author or maintainer of the
> > code being modified.
> 
> Actually, no, they should only write to the list.

OIC, gotta go back and read the introduction more carefully.  Sorry
about the confusion. :)

-- 
tejun


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

* Re: [Outreachy kernel] [PATCH] staging: dgnc: usleep_range is preferred over udelay
  2016-02-11 13:14 [PATCH] staging: dgnc: usleep_range is preferred over udelay Aybuke Ozdemir
  2016-02-11 15:50 ` [Outreachy kernel] " Tejun Heo
@ 2016-02-12  3:51 ` Greg KH
  1 sibling, 0 replies; 5+ messages in thread
From: Greg KH @ 2016-02-12  3:51 UTC (permalink / raw)
  To: Aybuke Ozdemir; +Cc: outreachy-kernel

On Thu, Feb 11, 2016 at 03:14:30PM +0200, Aybuke Ozdemir wrote:
> This patch fixes the issue:
> 
> CHECK: usleep_range is preferred over udelay; see
> Documentation/timers/timers-howto.txt
> 
> Signed-off-by: Aybuke Ozdemir <aybuke.147@gmail.com>
> ---
>  drivers/staging/dgnc/dgnc_cls.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/staging/dgnc/dgnc_cls.c b/drivers/staging/dgnc/dgnc_cls.c
> index 72f0aaa..ce1471b 100644
> --- a/drivers/staging/dgnc/dgnc_cls.c
> +++ b/drivers/staging/dgnc/dgnc_cls.c
> @@ -956,7 +956,7 @@ static void cls_flush_uart_read(struct channel_t *ch)
>  	 * Presumably, this is a bug in this UART.
>  	 */
>  
> -	udelay(10);
> +	usleep_range(10, 100);

As Tejun pointed out, this isn't ok, you can just ignore that checkpatch
warning.  Maybe we don't want to sleep for 100, are you sure about that?
Without the hardware to test with, we don't want to touch stuff like
this, sorry.

greg k-h


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

end of thread, other threads:[~2016-02-12  3:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-11 13:14 [PATCH] staging: dgnc: usleep_range is preferred over udelay Aybuke Ozdemir
2016-02-11 15:50 ` [Outreachy kernel] " Tejun Heo
2016-02-11 15:53   ` Julia Lawall
2016-02-11 15:58     ` Tejun Heo
2016-02-12  3:51 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.