linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] PM: Replace snprintf() with scnprintf() in show_trace_dev_match()
@ 2025-09-22  5:52 Kaushlendra Kumar
  2025-10-13 19:20 ` Rafael J. Wysocki
  0 siblings, 1 reply; 2+ messages in thread
From: Kaushlendra Kumar @ 2025-09-22  5:52 UTC (permalink / raw)
  To: rafael, pavel, gregkh, dakr; +Cc: linux-pm, Kaushlendra Kumar

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>
---
 drivers/base/power/trace.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
index cd6e559648b2..d8da7195bb00 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;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] PM: Replace snprintf() with scnprintf() in show_trace_dev_match()
  2025-09-22  5:52 [PATCH] PM: Replace snprintf() with scnprintf() in show_trace_dev_match() Kaushlendra Kumar
@ 2025-10-13 19:20 ` Rafael J. Wysocki
  0 siblings, 0 replies; 2+ messages in thread
From: Rafael J. Wysocki @ 2025-10-13 19:20 UTC (permalink / raw)
  To: Kaushlendra Kumar; +Cc: rafael, pavel, gregkh, dakr, linux-pm

On Mon, Sep 22, 2025 at 7:54 AM Kaushlendra Kumar
<kaushlendra.kumar@intel.com> wrote:
>
> 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>
> ---
>  drivers/base/power/trace.c | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/base/power/trace.c b/drivers/base/power/trace.c
> index cd6e559648b2..d8da7195bb00 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;
> --

Applied as 6.19 material, thanks!

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-10-13 19:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-22  5:52 [PATCH] PM: Replace snprintf() with scnprintf() in show_trace_dev_match() Kaushlendra Kumar
2025-10-13 19:20 ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).