clocksource: Remove unnecessary size argument when calling strscpy()
PATCH 1/1 clocksource: Remove unnecessary size argument when calling strscpy()
The size parameter is optional and strscpy() automatically determines the length of the destination buffer using sizeof() if the argument is omitted. This makes the explicit sizeof() unnecessary. Remove it to simplify the code.
--- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/clocksource.c +1 -1
@@ -1510,7 +1510,7 @@ static int __init boot_override_clocksource(char* str) {mutex_lock (&clocksource_mutex);if (str) -strscpy (override_name, str,sizeof (override_name)); +strscpy (override_name, str);mutex_unlock (&clocksource_mutex);return 1 ; }
Signature · 1 line
2.48.1
Quoted 3 lines · Thorsten Blum
The size parameter is optional and
strscpy()automatically determines the length of the destination buffer usingsizeof()if the argument is omitted.
If, and _only_ if the destination argument is a fixed length array.
That's the case here, but without that distinction the above sentence is misleading at best.
Thanks,
tglx
[tip: timers/core] clocksource: Remove unnecessary strscpy() size argument
In reply to Thorsten BlumThe following commit has been merged into the timers/core branch of tip:
The following commit has been merged into the timers/core branch of tip:
Commit-ID: fc661d0a78673f23a3fd78d0bb20900ee64d1839 Gitweb: https://git.kernel.org/tip/fc661d0a78673f23a3fd78d0bb20900ee64d1839 Author: Thorsten Blum <[email protected]> AuthorDate: Tue, 11 Mar 2025 12:06:24 +01:00 Committer: Thomas Gleixner <[email protected]> CommitterDate: Thu, 13 Mar 2025 11:37:44 +01:00
clocksource: Remove unnecessary strscpy() size argument
The size argument of strscpy() is only required when the destination pointer is not a fixed sized array or when the copy needs to be smaller than the size of the fixed sized destination array.
For fixed sized destination arrays and full copies, strscpy() automatically determines the length of the destination buffer if the size argument is omitted.
This makes the explicit sizeof() unnecessary. Remove it.
[ tglx: Massaged change log ]
--- kernel/time/clocksource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/clocksource.c +1 -1
@@ -1510,7 +1510,7 @@ static int __init boot_override_clocksource(char* str) {mutex_lock (&clocksource_mutex);if (str) -strscpy (override_name, str,sizeof (override_name)); +strscpy (override_name, str);mutex_unlock (&clocksource_mutex);return 1 ; }