linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
@ 2025-10-22 10:38 Michal Suchanek
  2025-10-23 21:50 ` Namhyung Kim
  2025-10-30  3:46 ` Namhyung Kim
  0 siblings, 2 replies; 5+ messages in thread
From: Michal Suchanek @ 2025-10-22 10:38 UTC (permalink / raw)
  To: linux-perf-users
  Cc: Michal Suchanek, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland,
	Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter,
	Thomas Richter, linux-kernel, Tony Jones

The line_len is only set on success. Check the return value instead.

Fixes: 53cc0b351ec9 ("perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
 tools/perf/util/hwmon_pmu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
index 416dfea9ffff..5c27256a220a 100644
--- a/tools/perf/util/hwmon_pmu.c
+++ b/tools/perf/util/hwmon_pmu.c
@@ -742,8 +742,7 @@ int perf_pmus__read_hwmon_pmus(struct list_head *pmus)
 			continue;
 		}
 		io__init(&io, name_fd, buf2, sizeof(buf2));
-		io__getline(&io, &line, &line_len);
-		if (line_len > 0 && line[line_len - 1] == '\n')
+		if (io__getline(&io, &line, &line_len) > 0 && line[line_len - 1] == '\n')
 			line[line_len - 1] = '\0';
 		hwmon_pmu__new(pmus, buf, class_hwmon_ent->d_name, line);
 		close(name_fd);
-- 
2.51.0


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

* Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
  2025-10-22 10:38 [PATCH] perf hwmon_pmu: Fix uninitialized variable warning Michal Suchanek
@ 2025-10-23 21:50 ` Namhyung Kim
  2025-10-23 22:11   ` Tony Jones
  2025-10-30  3:46 ` Namhyung Kim
  1 sibling, 1 reply; 5+ messages in thread
From: Namhyung Kim @ 2025-10-23 21:50 UTC (permalink / raw)
  To: Michal Suchanek
  Cc: linux-perf-users, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Ian Rogers, Adrian Hunter, Thomas Richter,
	linux-kernel, Tony Jones

Hello,

On Wed, Oct 22, 2025 at 12:38:35PM +0200, Michal Suchanek wrote:
> The line_len is only set on success. Check the return value instead.

Can you please share the actual warning messages from the compiler?

Thanks,
Namhyung

> 
> Fixes: 53cc0b351ec9 ("perf hwmon_pmu: Add a tool PMU exposing events from hwmon in sysfs")
> Signed-off-by: Michal Suchanek <msuchanek@suse.de>
> ---
>  tools/perf/util/hwmon_pmu.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
> index 416dfea9ffff..5c27256a220a 100644
> --- a/tools/perf/util/hwmon_pmu.c
> +++ b/tools/perf/util/hwmon_pmu.c
> @@ -742,8 +742,7 @@ int perf_pmus__read_hwmon_pmus(struct list_head *pmus)
>  			continue;
>  		}
>  		io__init(&io, name_fd, buf2, sizeof(buf2));
> -		io__getline(&io, &line, &line_len);
> -		if (line_len > 0 && line[line_len - 1] == '\n')
> +		if (io__getline(&io, &line, &line_len) > 0 && line[line_len - 1] == '\n')
>  			line[line_len - 1] = '\0';
>  		hwmon_pmu__new(pmus, buf, class_hwmon_ent->d_name, line);
>  		close(name_fd);
> -- 
> 2.51.0
> 

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

* Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
  2025-10-23 21:50 ` Namhyung Kim
@ 2025-10-23 22:11   ` Tony Jones
  2025-10-24  2:10     ` Namhyung Kim
  0 siblings, 1 reply; 5+ messages in thread
From: Tony Jones @ 2025-10-23 22:11 UTC (permalink / raw)
  To: Namhyung Kim; +Cc: Michal Suchanek, linux-perf-users

On Thu, Oct 23, 2025 at 02:50:43PM -0700, Namhyung Kim wrote:
> Hello,
> 
> On Wed, Oct 22, 2025 at 12:38:35PM +0200, Michal Suchanek wrote:
> > The line_len is only set on success. Check the return value instead.
> 
> Can you please share the actual warning messages from the compiler?
> 
> Thanks,
> Namhyung

[snipped CC]

I believe it was the following (gcc13):

[   38s] util/hwmon_pmu.c: In function ‘perf_pmus__read_hwmon_pmus’:
[   38s] util/hwmon_pmu.c:742:20: warning: ‘line_len’ may be used uninitialized [-Wmaybe-uninitialized]
[   38s]   742 |                 if (line_len > 0 && line[line_len - 1] == '\n')
[   38s]       |                    ^
[   38s] util/hwmon_pmu.c:719:24: note: ‘line_len’ was declared here
[   38s]   719 |                 size_t line_len;
[   38s]  


Tony

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

* Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
  2025-10-23 22:11   ` Tony Jones
@ 2025-10-24  2:10     ` Namhyung Kim
  0 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-10-24  2:10 UTC (permalink / raw)
  To: Tony Jones; +Cc: Michal Suchanek, linux-perf-users

On Thu, Oct 23, 2025 at 03:11:37PM -0700, Tony Jones wrote:
> On Thu, Oct 23, 2025 at 02:50:43PM -0700, Namhyung Kim wrote:
> > Hello,
> > 
> > On Wed, Oct 22, 2025 at 12:38:35PM +0200, Michal Suchanek wrote:
> > > The line_len is only set on success. Check the return value instead.
> > 
> > Can you please share the actual warning messages from the compiler?
> > 
> > Thanks,
> > Namhyung
> 
> [snipped CC]
> 
> I believe it was the following (gcc13):
> 
> [   38s] util/hwmon_pmu.c: In function ‘perf_pmus__read_hwmon_pmus’:
> [   38s] util/hwmon_pmu.c:742:20: warning: ‘line_len’ may be used uninitialized [-Wmaybe-uninitialized]
> [   38s]   742 |                 if (line_len > 0 && line[line_len - 1] == '\n')
> [   38s]       |                    ^
> [   38s] util/hwmon_pmu.c:719:24: note: ‘line_len’ was declared here
> [   38s]   719 |                 size_t line_len;
> [   38s]  

Great, I'll add this to the commit log.

Thanks,
Namhyung


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

* Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
  2025-10-22 10:38 [PATCH] perf hwmon_pmu: Fix uninitialized variable warning Michal Suchanek
  2025-10-23 21:50 ` Namhyung Kim
@ 2025-10-30  3:46 ` Namhyung Kim
  1 sibling, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2025-10-30  3:46 UTC (permalink / raw)
  To: linux-perf-users, Michal Suchanek
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers,
	Adrian Hunter, Thomas Richter, linux-kernel, Tony Jones

On Wed, 22 Oct 2025 12:38:35 +0200, Michal Suchanek wrote:
> The line_len is only set on success. Check the return value instead.
> 
> 
Applied to perf-tools-next, thanks!

Best regards,
Namhyung



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

end of thread, other threads:[~2025-10-30  3:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-22 10:38 [PATCH] perf hwmon_pmu: Fix uninitialized variable warning Michal Suchanek
2025-10-23 21:50 ` Namhyung Kim
2025-10-23 22:11   ` Tony Jones
2025-10-24  2:10     ` Namhyung Kim
2025-10-30  3:46 ` Namhyung Kim

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