jiffies: Cast to unsigned long for secs_to_jiffies() conversion
PATCH v2 1/1 jiffies: Cast to unsigned long for secs_to_jiffies() conversion
While converting users of msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value of secs_to_jiffies() vs the unsigned long return value of the msecs_to_jiffies() calls it was replacing. Fix this by casting secs_to_jiffies() values as unsigned long.
--- include/linux/jiffies.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/jiffies.h +1 -1
@@ -537,7 +537,7 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)* * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )
Signature · 1 line
2.43.0
Quoted 21 lines · Easwar Hariharan
While converting users of
msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value ofsecs_to_jiffies()vs the unsigned long return value of themsecs_to_jiffies()calls it was replacing. Fix this by castingsecs_to_jiffies()values as unsigned long.Fixes b35108a51cf7ba ("jiffies: Define secs_to_jiffies()")CC [email protected] # 6.13+CC Andrew Morton <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)include/linux/jiffies.h +0
-0
include/linux/jiffies.h static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) · line 540
Quoted 5 lines
include/linux/jiffies.h +1
-1@@ -537,7 +537,7 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)* * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)
Could you just switch the fun to an inline instead?
Signature · 2 lines
js suse labs
Quoted 17 lines · Jiri Slaby
Quoted 16 lines · Easwar Hariharan
While converting users of
msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value ofsecs_to_jiffies()vs the unsigned long return value of themsecs_to_jiffies()calls it was replacing. Fix this by castingsecs_to_jiffies()values as unsigned long.Fixes b35108a51cf7ba ("jiffies: Define secs_to_jiffies()")CC [email protected] # 6.13+CC Andrew Morton <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines
include/linux/jiffies.h static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) · line 540
Quoted 10 lines
include/linux/jiffies.h +1
-1@@ -537,7 +537,7 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)* * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)Could you just switch the fun to an inline instead?
It's a macro so it can be used in static initializers.
Quoted 31 lines · Thomas Gleixner
Quoted 17 lines · Jiri Slaby
Quoted 16 lines · Easwar Hariharan
While converting users of
msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value ofsecs_to_jiffies()vs the unsigned long return value of themsecs_to_jiffies()calls it was replacing. Fix this by castingsecs_to_jiffies()values as unsigned long.Fixes b35108a51cf7ba ("jiffies: Define secs_to_jiffies()")CC [email protected] # 6.13+CC Andrew Morton <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>--- include/linux/jiffies.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 12 lines
include/linux/jiffies.h static __always_inline unsigned long msecs_to_jiffies(const unsigned int m) · line 540
Quoted 10 lines
include/linux/jiffies.h +1
-1@@ -537,7 +537,7 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)* * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)Could you just switch the fun to an inline instead?
Quoted 1 line
It's a macro so it can be used in static initializers.
It's the only one from the *_to_jiffies() family we offer. And I fail to find such a use (by a quick grep, it only might be hidden)? People apparently use "* HZ" in initializers...
So sure, iff there is this intention for this very one, keep it as macro.
Signature · 2 lines
js suse labs
Quoted 34 lines · Jiri Slaby
Quoted 33 lines · Thomas Gleixner
Quoted 31 lines · Jiri Slaby
Quoted 22 lines · Easwar Hariharan
While converting users of
msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value ofsecs_to_jiffies()vs the unsigned long return value of themsecs_to_jiffies()calls it was replacing. Fix this by castingsecs_to_jiffies()values as unsigned long.Fixes b35108a51cf7ba ("jiffies: Define secs_to_jiffies()")CC [email protected] # 6.13+CC Andrew Morton <[email protected]>Reported-by kernel test robot <[email protected]>Signed-off-by Easwar Hariharan <[email protected]>---
include/linux/jiffies.h| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)include/linux/jiffies.h +0
-0include/linux/jiffies.h static __always_inline unsigned long · line 541
Quoted 6 lines
include/linux/jiffies.h +1
-1@@ -537,7 +537,7 @@ static __always_inline unsigned longmsecs_to_jiffies(const unsigned int m) * * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)Could you just switch the fun to an inline instead?
Quoted 8 lines
Quoted 1 line
It's a macro so it can be used in static initializers.
It's the only one from the
*_to_jiffies()family we offer. And I fail to find such a use (by a quick grep, it only might be hidden)? People apparently use "* HZ" in initializers...So sure, iff there is this intention for this very one, keep it as macro.
Yes, the intent is to convert those usages of "* HZ" to use secs_to_jiffies() for better readability.
Thanks,
Easwar
[tip: timers/urgent] jiffies: Cast to unsigned long in secs_to_jiffies() conversion
In reply to Easwar HariharanThe following commit has been merged into the timers/urgent branch of tip:
The following commit has been merged into the timers/urgent branch of tip:
Commit-ID: bb2784d9ab49587ba4fbff37a319fff2924db289 Gitweb: https://git.kernel.org/tip/bb2784d9ab49587ba4fbff37a319fff2924db289 Author: Easwar Hariharan <[email protected]> AuthorDate: Thu, 30 Jan 2025 19:26:58 Committer: Thomas Gleixner <[email protected]> CommitterDate: Fri, 31 Jan 2025 09:30:49 +01:00
jiffies: Cast to unsigned long in secs_to_jiffies() conversion
While converting users of msecs_to_jiffies(), lkp reported that some range checks would always be true because of the mismatch between the implied int value of secs_to_jiffies() vs the unsigned long return value of the msecs_to_jiffies() calls it was replacing.
Fix this by casting the secs_to_jiffies() input value to unsigned long.
--- include/linux/jiffies.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/jiffies.h +1 -1
@@ -537,7 +537,7 @@ static __always_inline unsigned long msecs_to_jiffies(const unsigned int m)* * Return: jiffies value */ -#define secs_to_jiffies (_secs) ((_secs) * HZ) +#define secs_to_jiffies (_secs) (unsigned long)((_secs) * HZ)extern unsigned long __usecs_to_jiffies (const unsigned int u);#if !(USEC_PER_SEC %HZ )