[PATCH] perf hwmon_pmu: Fix uninitialized variable warning

Michal Suchanek posted 1 patch 3 months, 2 weeks ago
tools/perf/util/hwmon_pmu.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH] perf hwmon_pmu: Fix uninitialized variable warning
Posted by Michal Suchanek 3 months, 2 weeks ago
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
Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
Posted by Namhyung Kim 3 months, 1 week ago
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
Re: [PATCH] perf hwmon_pmu: Fix uninitialized variable warning
Posted by Namhyung Kim 3 months, 2 weeks ago
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
>