From: Kaushlendra Kumar Date: Mon, 22 Sep 2025 05:52:31 +0000 (+0530) Subject: PM: sleep: Replace snprintf() with scnprintf() in show_trace_dev_match() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=67434ce57c7eb9a250125e159cb7ef8a3f764d3f;p=thirdparty%2Flinux.git PM: sleep: 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. Signed-off-by: Kaushlendra Kumar Link: https://patch.msgid.link/20250922055231.3523680-1-kaushlendra.kumar@intel.com [ rjw: Subject adjustment ] Signed-off-by: Rafael J. Wysocki --- diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c index cd6e559648b21..d8da7195bb006 100644 --- a/drivers/base/power/trace.c +++ b/drivers/base/power/trace.c @@ -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;