Skip to content

Commit 6164be0

Browse files
tobluxakpm00
authored andcommitted
watchdog/perf: optimize bytes copied and remove manual NUL-termination
Currently, up to 23 bytes of the source string are copied to the destination buffer (including the comma and anything after it), only to then manually NUL-terminate the destination buffer again at index 'len' (where the comma was found). Fix this by calling strscpy() with 'len' instead of the destination buffer size to copy only as many bytes from the source string as needed. Change the length check to allow 'len' to be less than or equal to the destination buffer size to fill the whole buffer if needed. Remove the if-check for the return value of strscpy(), because calling strscpy() with 'len' always truncates the source string at the comma as expected and NUL-terminates the destination buffer at the corresponding index instead. Remove the manual NUL-termination. No functional changes intended. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Thorsten Blum <[email protected]> Cc: Song Liu <[email protected]> Cc: Thomas Gleinxer <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent ceb08ee commit 6164be0

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

kernel/watchdog_perf.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,10 @@ void __init hardlockup_config_perf_event(const char *str)
294294
} else {
295295
unsigned int len = comma - str;
296296

297-
if (len >= sizeof(buf))
297+
if (len > sizeof(buf))
298298
return;
299299

300-
if (strscpy(buf, str, sizeof(buf)) < 0)
301-
return;
302-
buf[len] = 0;
300+
strscpy(buf, str, len);
303301
if (kstrtoull(buf, 16, &config))
304302
return;
305303
}

0 commit comments

Comments
 (0)