public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1] perf hwmon_pmu: Ensure hwmon key union is zeroed before use
Date: Wed, 20 Nov 2024 21:51:42 -0800	[thread overview]
Message-ID: <Zz7Kbp_XIu9f02Xj@google.com> (raw)
In-Reply-To: <20241119230033.115369-1-irogers@google.com>

On Tue, Nov 19, 2024 at 03:00:33PM -0800, Ian Rogers wrote:
> Non-zero values led to mismatches in testing. This was reproducible
> with -fsanitize=undefined.

It's sad the compiler didn't initialize all the members if it has
members with different size.

> 
> Reported-by: Arnaldo Carvalho de Melo <acme@kernel.org>
> Closes: https://lore.kernel.org/lkml/Zzdtj0PEWEX3ATwL@x1/
> Signed-off-by: Ian Rogers <irogers@google.com>

Acked-by: Namhyung Kim <namhyung@kernel.org>

Thanks,
Namhyung

> ---
>  tools/perf/util/hwmon_pmu.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/perf/util/hwmon_pmu.c b/tools/perf/util/hwmon_pmu.c
> index ac2245acdc6d..4d9d6f405434 100644
> --- a/tools/perf/util/hwmon_pmu.c
> +++ b/tools/perf/util/hwmon_pmu.c
> @@ -274,7 +274,7 @@ static int hwmon_pmu__read_events(struct hwmon_pmu *pmu)
>  		int number;
>  		enum hwmon_item item;
>  		bool alarm;
> -		union hwmon_pmu_event_key key = {};
> +		union hwmon_pmu_event_key key = { .type_and_num = 0 };
>  		struct hwmon_pmu_event_value *value;
>  
>  		if (ent->d_type != DT_REG)
> @@ -560,7 +560,7 @@ bool hwmon_pmu__have_event(struct perf_pmu *pmu, const char *name)
>  	struct hwmon_pmu *hwm = container_of(pmu, struct hwmon_pmu, pmu);
>  	enum hwmon_type type;
>  	int number;
> -	union hwmon_pmu_event_key key = {};
> +	union hwmon_pmu_event_key key = { .type_and_num = 0 };
>  	struct hashmap_entry *cur;
>  	size_t bkt;
>  
> @@ -623,10 +623,11 @@ static int hwmon_pmu__config_term(const struct hwmon_pmu *hwm,
>  					return -EINVAL;
>  			} else {
>  				union hwmon_pmu_event_key key = {
> -					.type = type,
> -					.num = number,
> +					.type_and_num = 0,
>  				};
>  
> +				key.type = type;
> +				key.num = number;
>  				attr->config = key.type_and_num;
>  			}
>  			return 0;
> -- 
> 2.47.0.371.ga323438b13-goog
> 

  parent reply	other threads:[~2024-11-21  5:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-19 23:00 [PATCH v1] perf hwmon_pmu: Ensure hwmon key union is zeroed before use Ian Rogers
2024-11-20 19:46 ` Arnaldo Carvalho de Melo
2024-11-21  5:51 ` Namhyung Kim [this message]
2024-11-22 22:17 ` Namhyung Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Zz7Kbp_XIu9f02Xj@google.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox