Re: [PATCH 1/2] perf evsel: Make evsel__env always return a valid env

From: kajoljain
Date: Tue Nov 23 2021 - 03:27:02 EST




On 10/5/21 3:11 AM, Kim Phillips wrote:
> It's possible to have an evsel and evsel->evlist populated without
> an evsel->evlist->env, when, e.g., cmd_record is in its error path.
>
> Future patches will add support for evsel__open_strerror to be able
> to customize error messaging based on perf_env__{arch,cpuid}, so
> let's have evsel__env return &perf_env instead of NULL in that case.
>

Patch looks good to me.

Reviewed-by: Kajol Jain<kjain@xxxxxxxxxxxxx>

Thanks,
Kajol Jain

> Signed-off-by: Kim Phillips <kim.phillips@xxxxxxx>
> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
> Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
> Cc: Ian Rogers <irogers@xxxxxxxxxx>
> Cc: Ingo Molnar <mingo@xxxxxxxxxx>
> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> Cc: Joao Martins <joao.m.martins@xxxxxxxxxx>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>
> Cc: Mark Rutland <mark.rutland@xxxxxxx>
> Cc: Michael Petlan <mpetlan@xxxxxxxxxx>
> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> Cc: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
> Cc: Robert Richter <robert.richter@xxxxxxx>
> Cc: Stephane Eranian <eranian@xxxxxxxxxx>
> ---
> tools/perf/util/evsel.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
> index dbfeceb2546c..b915840690d4 100644
> --- a/tools/perf/util/evsel.c
> +++ b/tools/perf/util/evsel.c
> @@ -2857,7 +2857,7 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
>
> struct perf_env *evsel__env(struct evsel *evsel)
> {
> - if (evsel && evsel->evlist)
> + if (evsel && evsel->evlist && evsel->evlist->env)
> return evsel->evlist->env;
> return &perf_env;
> }
>