PM: Replace snprintf() with scnprintf() in show_trace_dev_match()
Subsystems (4)
PATCH 1/1 PM: Replace snprintf() with scnprintf() in show_trace_dev_match()
Replace snprintf() with scnprintf() in show_trace_dev_match() to simplify buffer length handling. The scnprintf() function returns the number of characters actually written (excluding the null terminator), which eliminates the need for manual length checking and clamping.
This change removes the redundant size check since scnprintf() guarantees that the return value will never exceed the buffer size, making the code cleaner and less error-prone.
--- drivers/base/power/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/base/power/trace.c +1 -3
@@ -238,10 +238,8 @@ int show_trace_dev_match(char *buf, size_t size)unsigned int hash =hash_string (DEVSEED ,dev_name (dev),DEVHASH );if (hash == value) { -int len =snprintf (buf, size,"%s\n" , +int len =scnprintf (buf, size,"%s\n" ,dev_driver_string (dev)); -if (len > size) - len = size; buf += len; ret += len; size -= len;
Signature · 1 line
2.34.1
Quoted 22 lines · Kaushlendra Kumar
Replace
snprintf()withscnprintf()inshow_trace_dev_match()to simplify buffer length handling. Thescnprintf()function returns the number of characters actually written (excluding the null terminator), which eliminates the need for manual length checking and clamping.This change removes the redundant size check since
scnprintf()guarantees that the return value will never exceed the buffer size, making the code cleaner and less error-prone.Signed-off-by Kaushlendra Kumar <[email protected]>--- drivers/base/power/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/base/power/trace.c +0
-0@@ -238,10 +238,8 @@ int show_trace_dev_match(char *buf, size_t size)unsigned int hash =hash_string (DEVSEED ,dev_name (dev),DEVHASH );
drivers/base/power/trace.c int show_trace_dev_match(char *buf, size_t size)
Quoted 10 lines
drivers/base/power/trace.c +1
-4if (hash == value) { -int len =snprintf (buf, size,"%s\n" , +int len =scnprintf (buf, size,"%s\n" ,dev_driver_string (dev)); -if (len > size) - len = size; buf += len; ret += len; size -= len; --
Applied as 6.19 material, thanks!