linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison
@ 2017-05-08 16:58 Karim Eshapa
  2017-05-08 21:26 ` David Miller
  2017-05-09  0:06 ` Karim Eshapa
  0 siblings, 2 replies; 5+ messages in thread
From: Karim Eshapa @ 2017-05-08 16:58 UTC (permalink / raw)
  To: inaky.perez-gonzalez; +Cc: linux-wimax, netdev, linux-kernel, Karim Eshapa

cast timeframe variable with (unsigned long) then
use time_after() kernel macro for time comparison.

Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>
---
 drivers/net/wimax/i2400m/i2400m-usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wimax/i2400m/i2400m-usb.h b/drivers/net/wimax/i2400m/i2400m-usb.h
index 649ecad..6fc941c 100644
--- a/drivers/net/wimax/i2400m/i2400m-usb.h
+++ b/drivers/net/wimax/i2400m/i2400m-usb.h
@@ -131,7 +131,7 @@ static inline int edc_inc(struct edc *edc, u16 max_err, u16 timeframe)
 	unsigned long now;
 
 	now = jiffies;
-	if (now - edc->timestart > timeframe) {
+	if (time_after(now - edc->timestart, (unsigned long)timeframe)) {
 		edc->errorcount = 1;
 		edc->timestart = now;
 	} else if (++edc->errorcount > max_err) {
-- 
2.7.4

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

* Re: [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison
  2017-05-08 16:58 [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison Karim Eshapa
@ 2017-05-08 21:26 ` David Miller
  2017-05-08 23:27   ` Girish Moodalbail
  2017-05-09  0:06 ` Karim Eshapa
  1 sibling, 1 reply; 5+ messages in thread
From: David Miller @ 2017-05-08 21:26 UTC (permalink / raw)
  To: karim.eshapa; +Cc: inaky.perez-gonzalez, linux-wimax, netdev, linux-kernel

From: Karim Eshapa <karim.eshapa@gmail.com>
Date: Mon,  8 May 2017 18:58:02 +0200

> diff --git a/drivers/net/wimax/i2400m/i2400m-usb.h b/drivers/net/wimax/i2400m/i2400m-usb.h
> index 649ecad..6fc941c 100644
> --- a/drivers/net/wimax/i2400m/i2400m-usb.h
> +++ b/drivers/net/wimax/i2400m/i2400m-usb.h
> @@ -131,7 +131,7 @@ static inline int edc_inc(struct edc *edc, u16 max_err, u16 timeframe)
>  	unsigned long now;
>  
>  	now = jiffies;
> -	if (now - edc->timestart > timeframe) {
> +	if (time_after(now - edc->timestart, (unsigned long)timeframe)) {

This is far from correct.

time_after() compares two "jiffies" timestamp values.  The second
argument here is not a jiffies timestamp value.

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

* Re: [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison
  2017-05-08 21:26 ` David Miller
@ 2017-05-08 23:27   ` Girish Moodalbail
  0 siblings, 0 replies; 5+ messages in thread
From: Girish Moodalbail @ 2017-05-08 23:27 UTC (permalink / raw)
  To: David Miller, karim.eshapa
  Cc: inaky.perez-gonzalez, linux-wimax, netdev, linux-kernel

On 5/8/17 2:26 PM, David Miller wrote:
> From: Karim Eshapa <karim.eshapa@gmail.com>
> Date: Mon,  8 May 2017 18:58:02 +0200
>
>> diff --git a/drivers/net/wimax/i2400m/i2400m-usb.h b/drivers/net/wimax/i2400m/i2400m-usb.h
>> index 649ecad..6fc941c 100644
>> --- a/drivers/net/wimax/i2400m/i2400m-usb.h
>> +++ b/drivers/net/wimax/i2400m/i2400m-usb.h
>> @@ -131,7 +131,7 @@ static inline int edc_inc(struct edc *edc, u16 max_err, u16 timeframe)
>>  	unsigned long now;
>>
>>  	now = jiffies;
>> -	if (now - edc->timestart > timeframe) {
>> +	if (time_after(now - edc->timestart, (unsigned long)timeframe)) {
>
> This is far from correct.
>
> time_after() compares two "jiffies" timestamp values.  The second
> argument here is not a jiffies timestamp value.
>

Perhaps, what is needed here is:

+	if (time_after(jiffies, edc->timestart + timeframe)) {

where in 'timeframe' is set in HZ in all the callers I checked (for the most 
part it is set to EDC_ERROR_TIMEFRAME which is 1HZ).

~Girish

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

* RE: [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison
  2017-05-08 16:58 [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison Karim Eshapa
  2017-05-08 21:26 ` David Miller
@ 2017-05-09  0:06 ` Karim Eshapa
  2017-05-09 13:40   ` David Miller
  1 sibling, 1 reply; 5+ messages in thread
From: Karim Eshapa @ 2017-05-09  0:06 UTC (permalink / raw)
  To: inaky.perez-gonzalez; +Cc: linux-wimax, netdev, linux-kernel, Karim Eshapa

Use time_after() for time comparison with the new fix.

Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>
---
 drivers/net/wimax/i2400m/i2400m-usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/wimax/i2400m/i2400m-usb.h b/drivers/net/wimax/i2400m/i2400m-usb.h
index 649ecad..eff4f464 100644
--- a/drivers/net/wimax/i2400m/i2400m-usb.h
+++ b/drivers/net/wimax/i2400m/i2400m-usb.h
@@ -131,7 +131,7 @@ static inline int edc_inc(struct edc *edc, u16 max_err, u16 timeframe)
 	unsigned long now;
 
 	now = jiffies;
-	if (now - edc->timestart > timeframe) {
+	if (time_after(now, edc->timestart + timeframe)) {
 		edc->errorcount = 1;
 		edc->timestart = now;
 	} else if (++edc->errorcount > max_err) {
-- 
2.7.4

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

* Re: [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison
  2017-05-09  0:06 ` Karim Eshapa
@ 2017-05-09 13:40   ` David Miller
  0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2017-05-09 13:40 UTC (permalink / raw)
  To: karim.eshapa; +Cc: inaky.perez-gonzalez, linux-wimax, netdev, linux-kernel

From: Karim Eshapa <karim.eshapa@gmail.com>
Date: Tue,  9 May 2017 02:06:50 +0200

> Use time_after() for time comparison with the new fix.
> 
> Signed-off-by: Karim Eshapa <karim.eshapa@gmail.com>

This looks a lot better, applied, thanks.

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

end of thread, other threads:[~2017-05-09 13:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 16:58 [PATCH] drivers: net: wimax: i2400m: i2400m-usb: Use time_after for time comparison Karim Eshapa
2017-05-08 21:26 ` David Miller
2017-05-08 23:27   ` Girish Moodalbail
2017-05-09  0:06 ` Karim Eshapa
2017-05-09 13:40   ` 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).