Skip to content

Commit 67434ce

Browse files
kaushlenrafaeljw
authored andcommitted
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 <kaushlendra.kumar@intel.com> Link: https://patch.msgid.link/20250922055231.3523680-1-kaushlendra.kumar@intel.com [ rjw: Subject adjustment ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 3a86608 commit 67434ce

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

drivers/base/power/trace.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,8 @@ int show_trace_dev_match(char *buf, size_t size)
238238
unsigned int hash = hash_string(DEVSEED, dev_name(dev),
239239
DEVHASH);
240240
if (hash == value) {
241-
int len = snprintf(buf, size, "%s\n",
241+
int len = scnprintf(buf, size, "%s\n",
242242
dev_driver_string(dev));
243-
if (len > size)
244-
len = size;
245243
buf += len;
246244
ret += len;
247245
size -= len;

0 commit comments

Comments
 (0)