* [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0"
@ 2022-07-27 2:46 Yu Zhe
2022-07-28 13:11 ` Paolo Abeni
2022-07-29 6:17 ` [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now" Yu Zhe
0 siblings, 2 replies; 5+ messages in thread
From: Yu Zhe @ 2022-07-27 2:46 UTC (permalink / raw)
To: davem, kuba, pabeni
Cc: linux-decnet-user, netdev, linux-kernel, kernel-janitors,
liqiong, Yu Zhe
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))
break;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0"
2022-07-27 2:46 [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0" Yu Zhe
@ 2022-07-28 13:11 ` Paolo Abeni
2022-07-29 5:49 ` Yu Zhe
2022-07-29 6:17 ` [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now" Yu Zhe
1 sibling, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2022-07-28 13:11 UTC (permalink / raw)
To: Yu Zhe, davem, kuba
Cc: linux-decnet-user, netdev, linux-kernel, kernel-janitors, liqiong
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?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0"
2022-07-28 13:11 ` Paolo Abeni
@ 2022-07-29 5:49 ` Yu Zhe
0 siblings, 0 replies; 5+ messages in thread
From: Yu Zhe @ 2022-07-29 5:49 UTC (permalink / raw)
To: Paolo Abeni, davem, kuba
Cc: linux-decnet-user, netdev, linux-kernel, kernel-janitors, liqiong
在 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now"
2022-07-27 2:46 [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0" Yu Zhe
2022-07-28 13:11 ` Paolo Abeni
@ 2022-07-29 6:17 ` Yu Zhe
2022-07-30 3:20 ` patchwork-bot+netdevbpf
1 sibling, 1 reply; 5+ messages in thread
From: Yu Zhe @ 2022-07-29 6:17 UTC (permalink / raw)
To: davem, edumazet, kuba, pabeni
Cc: linux-decnet-user, netdev, linux-kernel, kernel-janitors,
liqiong, Yu Zhe
Use "jiffies != now" to replace "jiffies - now > 0" to make
code more readable.
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..ac2ee1689111 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 (jiffies != now)
break;
}
--
2.11.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now"
2022-07-29 6:17 ` [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now" Yu Zhe
@ 2022-07-30 3:20 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-30 3:20 UTC (permalink / raw)
To: Yu Zhe
Cc: davem, edumazet, kuba, pabeni, linux-decnet-user, netdev,
linux-kernel, kernel-janitors, liqiong
Hello:
This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Fri, 29 Jul 2022 14:17:12 +0800 you wrote:
> Use "jiffies != now" to replace "jiffies - now > 0" to make
> code more readable.
>
> Signed-off-by: Yu Zhe <yuzhe@nfschina.com>
> ---
> net/decnet/dn_route.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Here is the summary with links:
- [v2] dn_route: replace "jiffies-now>0" with "jiffies!=now"
https://git.kernel.org/netdev/net-next/c/0f14a8351abd
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-07-30 3:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 2:46 [PATCH] dn_route: use time_is_before_jiffies(a) to replace "jiffies - a > 0" Yu Zhe
2022-07-28 13:11 ` Paolo Abeni
2022-07-29 5:49 ` Yu Zhe
2022-07-29 6:17 ` [PATCH v2] dn_route: replace "jiffies-now>0" with "jiffies!=now" Yu Zhe
2022-07-30 3:20 ` patchwork-bot+netdevbpf
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).