linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1
@ 2023-09-23  7:15 Christophe JAILLET
  2023-09-28 13:09 ` (subset) " Lee Jones
  2023-09-28 13:09 ` Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2023-09-23  7:15 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, Bryan Wu, Linus Walleij, Jamie Iles
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-leds

In order to teach the compiler that 'trig->name' will never be truncated,
we need to tell it that 'cpu' is not negative.

When building with W=1, this fixes the following warnings:

  drivers/leds/trigger/ledtrig-cpu.c: In function ‘ledtrig_cpu_init’:
  drivers/leds/trigger/ledtrig-cpu.c:155:56: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]
    155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
        |                                                        ^~
  drivers/leds/trigger/ledtrig-cpu.c:155:52: note: directive argument in the range [-2147483648, 7]
    155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
        |                                                    ^~~~~~~
  drivers/leds/trigger/ledtrig-cpu.c:155:17: note: ‘snprintf’ output between 5 and 15 bytes into a destination of size 8
    155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
        |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fixes: 8f88731d052d ("led-triggers: create a trigger for CPU activity")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/leds/trigger/ledtrig-cpu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/leds/trigger/ledtrig-cpu.c b/drivers/leds/trigger/ledtrig-cpu.c
index 8af4f9bb9cde..05848a2fecff 100644
--- a/drivers/leds/trigger/ledtrig-cpu.c
+++ b/drivers/leds/trigger/ledtrig-cpu.c
@@ -130,7 +130,7 @@ static int ledtrig_prepare_down_cpu(unsigned int cpu)
 
 static int __init ledtrig_cpu_init(void)
 {
-	int cpu;
+	unsigned int cpu;
 	int ret;
 
 	/* Supports up to 9999 cpu cores */
@@ -152,7 +152,7 @@ static int __init ledtrig_cpu_init(void)
 		if (cpu >= 8)
 			continue;
 
-		snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
+		snprintf(trig->name, MAX_NAME_LEN, "cpu%u", cpu);
 
 		led_trigger_register_simple(trig->name, &trig->_trig);
 	}
-- 
2.34.1


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

* Re: (subset) [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1
  2023-09-23  7:15 [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1 Christophe JAILLET
@ 2023-09-28 13:09 ` Lee Jones
  2023-09-28 13:09 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2023-09-28 13:09 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, Bryan Wu, Linus Walleij, Jamie Iles,
	Christophe JAILLET
  Cc: linux-kernel, kernel-janitors, linux-leds

On Sat, 23 Sep 2023 09:15:38 +0200, Christophe JAILLET wrote:
> In order to teach the compiler that 'trig->name' will never be truncated,
> we need to tell it that 'cpu' is not negative.
> 
> When building with W=1, this fixes the following warnings:
> 
>   drivers/leds/trigger/ledtrig-cpu.c: In function ‘ledtrig_cpu_init’:
>   drivers/leds/trigger/ledtrig-cpu.c:155:56: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                                                        ^~
>   drivers/leds/trigger/ledtrig-cpu.c:155:52: note: directive argument in the range [-2147483648, 7]
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                                                    ^~~~~~~
>   drivers/leds/trigger/ledtrig-cpu.c:155:17: note: ‘snprintf’ output between 5 and 15 bytes into a destination of size 8
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> [...]

Applied, thanks!

[1/1] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1
      commit: 5272d74b29929c8395720a7e35971a4f0fb6783d

--
Lee Jones [李琼斯]


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

* Re: [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1
  2023-09-23  7:15 [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1 Christophe JAILLET
  2023-09-28 13:09 ` (subset) " Lee Jones
@ 2023-09-28 13:09 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2023-09-28 13:09 UTC (permalink / raw)
  To: Christophe JAILLET
  Cc: Pavel Machek, Bryan Wu, Linus Walleij, Jamie Iles, linux-kernel,
	kernel-janitors, linux-leds

On Sat, 23 Sep 2023, Christophe JAILLET wrote:

> In order to teach the compiler that 'trig->name' will never be truncated,
> we need to tell it that 'cpu' is not negative.
> 
> When building with W=1, this fixes the following warnings:
> 
>   drivers/leds/trigger/ledtrig-cpu.c: In function ‘ledtrig_cpu_init’:
>   drivers/leds/trigger/ledtrig-cpu.c:155:56: error: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 5 [-Werror=format-truncation=]
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                                                        ^~
>   drivers/leds/trigger/ledtrig-cpu.c:155:52: note: directive argument in the range [-2147483648, 7]
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                                                    ^~~~~~~
>   drivers/leds/trigger/ledtrig-cpu.c:155:17: note: ‘snprintf’ output between 5 and 15 bytes into a destination of size 8
>     155 |                 snprintf(trig->name, MAX_NAME_LEN, "cpu%d", cpu);
>         |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> Fixes: 8f88731d052d ("led-triggers: create a trigger for CPU activity")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>  drivers/leds/trigger/ledtrig-cpu.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

I made the subject line less generic and applied it, thanks.

-- 
Lee Jones [李琼斯]

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

end of thread, other threads:[~2023-09-28 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-23  7:15 [PATCH] leds: trigger: ledtrig-cpu:: Fix a warning when compiling with W=1 Christophe JAILLET
2023-09-28 13:09 ` (subset) " Lee Jones
2023-09-28 13:09 ` Lee Jones

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).