diff mbox series

dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0"

Message ID 20220727024600.18413-1-yuzhe@nfschina.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0" | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 4 maintainers not CCed: keescook@chromium.org lucien.xin@gmail.com yajun.deng@linux.dev edumazet@google.com
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Yu Zhe July 27, 2022, 2:46 a.m. UTC
time_is_before_jiffies deals with timer wrapping correctly.

Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
---
 net/decnet/dn_route.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Paolo Abeni July 28, 2022, 1:11 p.m. UTC | #1
On Wed, 2022-07-27 at 10:46 +0800, Yu Zhe wrote:
> time_is_before_jiffies deals with timer wrapping correctly.
> 
> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> ---
>  net/decnet/dn_route.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
> index 552a53f1d5d0..0a4bed0bc2e3 100644
> --- a/net/decnet/dn_route.c
> +++ b/net/decnet/dn_route.c
> @@ -201,7 +201,7 @@ static void dn_dst_check_expire(struct timer_list *unused)
>  		}
>  		spin_unlock(&dn_rt_hash_table[i].lock);
>  
> -		if ((jiffies - now) > 0)
> +		if (time_is_before_jiffies(now))

Uhmm... it looks like the wrap-around condition can happen only in
theory: 'now' is initialized just before entering this loop, and we
will break as soon as jiffies increment. The wrap-around could happen
only if a single iteration of the loop takes more than LONG_MAX
jiffies.

If that happens, we have a completely different kind of much more
serious problem, I think ;)

So this change is mostly for core readability's sake. I personally find
more readable:

		if (jiffies != now)

Cheers,

Paolo

p.s. given the above I guess this is for the net-next tree, right?
Yu Zhe July 29, 2022, 5:49 a.m. UTC | #2
在 2022年07月28日 21:11, Paolo Abeni 写道:

> On Wed, 2022-07-27 at 10:46 +0800, Yu Zhe wrote:
>> time_is_before_jiffies deals with timer wrapping correctly.
>>
>> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
>> ---
>>   net/decnet/dn_route.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
>> index 552a53f1d5d0..0a4bed0bc2e3 100644
>> --- a/net/decnet/dn_route.c
>> +++ b/net/decnet/dn_route.c
>> @@ -201,7 +201,7 @@ static void dn_dst_check_expire(struct timer_list *unused)
>>   		}
>>   		spin_unlock(&dn_rt_hash_table[i].lock);
>>   
>> -		if ((jiffies - now) > 0)
>> +		if (time_is_before_jiffies(now))
> Uhmm... it looks like the wrap-around condition can happen only in
> theory: 'now' is initialized just before entering this loop, and we
> will break as soon as jiffies increment. The wrap-around could happen
> only if a single iteration of the loop takes more than LONG_MAX
> jiffies.
>
> If that happens, we have a completely different kind of much more
> serious problem, I think ;)
>
> So this change is mostly for core readability's sake. I personally find
> more readable:
>
> 		if (jiffies != now)

I agree and I will send a v2 patch later.

>
> Cheers,
>
> Paolo
>
> p.s. given the above I guess this is for the net-next tree, right?
>
yes

>
diff mbox series

Patch

diff --git a/net/decnet/dn_route.c b/net/decnet/dn_route.c
index 552a53f1d5d0..0a4bed0bc2e3 100644
--- a/net/decnet/dn_route.c
+++ b/net/decnet/dn_route.c
@@ -201,7 +201,7 @@  static void dn_dst_check_expire(struct timer_list *unused)
 		}
 		spin_unlock(&dn_rt_hash_table[i].lock);
 
-		if ((jiffies - now) > 0)
+		if (time_is_before_jiffies(now))
 			break;
 	}