public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] staging: panel: use schedule_timeout_interruptible()
@ 2015-05-29 17:02 Nicholas Mc Guire
  2015-05-30  6:00 ` Willy Tarreau
  0 siblings, 1 reply; 2+ messages in thread
From: Nicholas Mc Guire @ 2015-05-29 17:02 UTC (permalink / raw)
  To: Willy Tarreau
  Cc: Greg Kroah-Hartman, Mariusz Gorski, Sudip Mukherjee, devel,
	linux-kernel, Nicholas Mc Guire

API consolidation with coccinelle found:
./drivers/staging/panel/panel.c:782:2-18:
        consolidation with schedule_timeout_*() recommended

This is a 1:1 conversion with respect to schedule_timeout() to the
schedule_timeout_interruptible() helper only - so only an API
consolidation to improve readability. The timeout was being passed
as (ms * HZ + 999) / 1000 but that simply looks wrong - rather than
"manual" converting to jiffies, msecs_to_jiffies which handles all 
corner-cases correctly, was used.

Patch was compile tested with x86_64_defconfig + CONFIG_STAGING=y,
CONFIG_PARPORT=m, CONFIG_PANEL=m

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---
Patch is against 4.1-rc5 (localversion-next is -next-20150529)

not really clear what the intent of (ms * HZ + 999) / 1000 was - this 
is HZ dependent and does not really make sense - the comment states
"sleeps that many milliseconds" so it probably simply should be
msecs_to_jiffies(ms) - but someone that knows the intention of this code
needs to check this.

 drivers/staging/panel/panel.c |    8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/staging/panel/panel.c b/drivers/staging/panel/panel.c
index 0046ee0..d670494 100644
--- a/drivers/staging/panel/panel.c
+++ b/drivers/staging/panel/panel.c
@@ -775,12 +775,10 @@ static void pin_to_bits(int pin, unsigned char *d_val, unsigned char *c_val)
 /* sleeps that many milliseconds with a reschedule */
 static void long_sleep(int ms)
 {
-	if (in_interrupt()) {
+	if (in_interrupt())
 		mdelay(ms);
-	} else {
-		__set_current_state(TASK_INTERRUPTIBLE);
-		schedule_timeout((ms * HZ + 999) / 1000);
-	}
+	else
+		schedule_timeout_interruptible(msecs_to_jiffies(ms));
 }
 
 /* send a serial byte to the LCD panel. The caller is responsible for locking
-- 
1.7.10.4


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

* Re: [PATCH] staging: panel: use schedule_timeout_interruptible()
  2015-05-29 17:02 [PATCH] staging: panel: use schedule_timeout_interruptible() Nicholas Mc Guire
@ 2015-05-30  6:00 ` Willy Tarreau
  0 siblings, 0 replies; 2+ messages in thread
From: Willy Tarreau @ 2015-05-30  6:00 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Willy Tarreau, Greg Kroah-Hartman, Mariusz Gorski,
	Sudip Mukherjee, devel, linux-kernel

Hi Nicholas,

On Fri, May 29, 2015 at 07:02:32PM +0200, Nicholas Mc Guire wrote:
> API consolidation with coccinelle found:
> ./drivers/staging/panel/panel.c:782:2-18:
>         consolidation with schedule_timeout_*() recommended
> 
> This is a 1:1 conversion with respect to schedule_timeout() to the
> schedule_timeout_interruptible() helper only - so only an API
> consolidation to improve readability. The timeout was being passed
> as (ms * HZ + 999) / 1000 but that simply looks wrong - rather than
> "manual" converting to jiffies, msecs_to_jiffies which handles all 
> corner-cases correctly, was used.
> 
> Patch was compile tested with x86_64_defconfig + CONFIG_STAGING=y,
> CONFIG_PARPORT=m, CONFIG_PANEL=m
> 
> Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>

Acked-by: Willy Tarreau <w@1wt.eu>

> ---
> Patch is against 4.1-rc5 (localversion-next is -next-20150529)
> 
> not really clear what the intent of (ms * HZ + 999) / 1000 was - this 
> is HZ dependent and does not really make sense - the comment states
> "sleeps that many milliseconds" so it probably simply should be
> msecs_to_jiffies(ms) - but someone that knows the intention of this code
> needs to check this.

Oh it's very simple, we call this a bug :-)
The code was written for kernel 2.2 and by then there was no
msecs_to_jiffies(). I did a mistake with this +999, the purpose was
to round up, but it's not 999 that should have been used, but HZ-1
since the result is supposed to be in units of HZ.

Thanks for fixing this one!

Willy


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

end of thread, other threads:[~2015-05-30  6:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-29 17:02 [PATCH] staging: panel: use schedule_timeout_interruptible() Nicholas Mc Guire
2015-05-30  6:00 ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox