linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cosa: use msecs_to_jiffies for conversions
@ 2015-06-06  7:51 Nicholas Mc Guire
  2015-06-07  7:18 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Mc Guire @ 2015-06-06  7:51 UTC (permalink / raw)
  To: Jan Yenya Kasprzak; +Cc: netdev, linux-kernel, Nicholas Mc Guire

API compliance scanning with coccinelle flagged:
./drivers/net/wan/cosa.c:520:2-18: WARNING: 
	timeout (30) seems HZ dependent

Numeric constants passed to schedule_timeout() make the effective
timeout HZ dependent which makes little sense in a device probe.
Fixed up by converting the constant to jiffies with msecs_to_jiffies()

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

As the actually intended timeout is not documented and msecs_to_jiffies
timeouts can be a factor 10 different from the current effective timeout
As the original driver predates variable HZ (2.2.26 drivers/net/cosa.c
also is using schedule_timeout(30)) this is probably assuming HZ=100 
and thus the timeout would need to be 300, this needs to be checked by 
someone who knows the details of this driver.
In any case it should be passed in a HZ independent manner.

Patch was compile tested with i386_defconfig + CONFIG_WAN=y
CONFIG_ISA=y, CONFIG_HDLC=m, CONFIG_COSA=m

Patch is against 4.1-rc6 (localversion-next is -next-20150605)

 drivers/net/wan/cosa.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index bcfa01a..4cce63c 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -517,7 +517,7 @@ static int cosa_probe(int base, int irq, int dma)
 		 */
 		set_current_state(TASK_INTERRUPTIBLE);
 		cosa_putstatus(cosa, SR_TX_INT_ENA);
-		schedule_timeout(30);
+		schedule_timeout(msecs_to_jiffies(300));
 		irq = probe_irq_off(irqs);
 		/* Disable all IRQs from the card */
 		cosa_putstatus(cosa, 0);
-- 
1.7.10.4


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

* Re: [PATCH] cosa: use msecs_to_jiffies for conversions
  2015-06-06  7:51 [PATCH] cosa: use msecs_to_jiffies for conversions Nicholas Mc Guire
@ 2015-06-07  7:18 ` David Miller
  2015-06-07  8:25   ` Nicholas Mc Guire
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2015-06-07  7:18 UTC (permalink / raw)
  To: hofrat; +Cc: kas, netdev, linux-kernel

From: Nicholas Mc Guire <hofrat@osadl.org>
Date: Sat,  6 Jun 2015 09:51:51 +0200

> @@ -517,7 +517,7 @@ static int cosa_probe(int base, int irq, int dma)
>  		 */
>  		set_current_state(TASK_INTERRUPTIBLE);
>  		cosa_putstatus(cosa, SR_TX_INT_ENA);
> -		schedule_timeout(30);
> +		schedule_timeout(msecs_to_jiffies(300));
>  		irq = probe_irq_off(irqs);
>  		/* Disable all IRQs from the card */
>  		cosa_putstatus(cosa, 0);

You are making these transformations completely inconsistently.

You're converting it to msecs in some patches and here you are doing
something else.

Please do _all_ of these transformations consistently and in a way
that minimizes the chances of breaking things.

And the only way to do that is to strictly convert these cases to
whatever it works out to when HZ=100 since that is strictly the
environment all of this old code was written in.

Thank you.

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

* Re: [PATCH] cosa: use msecs_to_jiffies for conversions
  2015-06-07  7:18 ` David Miller
@ 2015-06-07  8:25   ` Nicholas Mc Guire
  2015-06-08  6:46     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Nicholas Mc Guire @ 2015-06-07  8:25 UTC (permalink / raw)
  To: David Miller; +Cc: hofrat, kas, netdev, linux-kernel

On Sun, 07 Jun 2015, David Miller wrote:

> From: Nicholas Mc Guire <hofrat@osadl.org>
> Date: Sat,  6 Jun 2015 09:51:51 +0200
> 
> > @@ -517,7 +517,7 @@ static int cosa_probe(int base, int irq, int dma)
> >  		 */
> >  		set_current_state(TASK_INTERRUPTIBLE);
> >  		cosa_putstatus(cosa, SR_TX_INT_ENA);
> > -		schedule_timeout(30);
> > +		schedule_timeout(msecs_to_jiffies(300));
> >  		irq = probe_irq_off(irqs);
> >  		/* Disable all IRQs from the card */
> >  		cosa_putstatus(cosa, 0);
> 
> You are making these transformations completely inconsistently.
> 
> You're converting it to msecs in some patches and here you are doing
> something else.
>

As noted in the cosa case the code predated configurable HZ so the
30 was definitely assuming HZ=100 and therefor it should probably be 300
now - I do not think that is inconsisten and it was explained in the
patch. I only can make the HZ=100 assumption if the code predates 
configurable HZ otherwise I leave it at the nominal value and put a note
in that it may be a significant change and needs review.

What alternative would you suggest ?
 
> Please do _all_ of these transformations consistently and in a way
> that minimizes the chances of breaking things.
> 
> And the only way to do that is to strictly convert these cases to
> whatever it works out to when HZ=100 since that is strictly the
> environment all of this old code was written in.
>
for the dscc4 case Im not sure - that seems to have gone in in 2.4
and that had HZ configurable. The cosa case was checked 
again 2.2.26 (no config HZ) and the timeout there was 30 -> 300ms.

I think that this is consistent with respect to the limited available
information of the timeout unit in the code.

thx!
hofrat

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

* Re: [PATCH] cosa: use msecs_to_jiffies for conversions
  2015-06-07  8:25   ` Nicholas Mc Guire
@ 2015-06-08  6:46     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2015-06-08  6:46 UTC (permalink / raw)
  To: der.herr; +Cc: hofrat, kas, netdev, linux-kernel

From: Nicholas Mc Guire <der.herr@hofr.at>
Date: Sun, 7 Jun 2015 10:25:58 +0200

> for the dscc4 case Im not sure - that seems to have gone in in 2.4
> and that had HZ configurable. The cosa case was checked 
> again 2.2.26 (no config HZ) and the timeout there was 30 -> 300ms.
> 
> I think that this is consistent with respect to the limited available
> information of the timeout unit in the code.

Ok, applied.

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

end of thread, other threads:[~2015-06-08  6:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-06  7:51 [PATCH] cosa: use msecs_to_jiffies for conversions Nicholas Mc Guire
2015-06-07  7:18 ` David Miller
2015-06-07  8:25   ` Nicholas Mc Guire
2015-06-08  6:46     ` David Miller

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