perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
Hello Kim Phillips,
This is a semi-automatic email about new static checker warnings.
The patch 9fe8895a27a8: "perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings" from Aug 17, 2021, leads to the following Smatch complaint:
./tools/perf/util/env.c:476 perf_env__nr_pmu_mappings()
error: we previously assumed 'env' could be null (see line 470)
./tools/perf/util/env.c
469
470 if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
^^^
Checks for NULL
471 status = perf_env__read_pmu_mappings(env);
472 if (status)
473 return 0;
474 }
475
476 return env->nr_pmu_mappings;
^^^^Unchecked dereference
477 }
regards,
dan carpenter
Quoted 24 lines · Dan Carpenter
Hello Kim Phillips,
This is a semi-automatic email about new static checker warnings.
The patch
9fe8895a27a8: "perf env: Addperf_env__cpuid, perf_env__{nr_}pmu_mappings" from Aug 17, 2021, leads to the following Smatch complaint:
./tools/perf/util/env.c:476perf_env__nr_pmu_mappings()
error: we previously assumed 'env' could be null (see line 470)
./tools/perf/util/env.c
469
470 if (!env || !env->nr_pmu_mappings) { /* Assume local operation */^^^Checks for NULL
471 status = perf_env__read_pmu_mappings(env); 472 if (status) 473 return 0; 474 } 475 476 return env->nr_pmu_mappings; ^^^^
Quoted 6 lines
Unchecked dereference
477 }regards,
dan carpenter
I think we need to bail out for !env
jirka
---
tools/perf/util/env.c +8 -2
@@ -467,7 +467,10 @@ int perf_env__nr_pmu_mappings(struct perf_env *env) {int status; -if (!env || !env->nr_pmu_mappings) {/* Assume local operation */ +if (!env) +return 0 ; + +if (!env->nr_pmu_mappings) {/* Assume local operation */ status =perf_env__read_pmu_mappings (env);if (status)return 0 ;
@@ -480,7 +483,10 @@ const char *perf_env__pmu_mappings(struct perf_env *env) {int status; -if (!env || !env->pmu_mappings) {/* Assume local operation */ +if (!env) +return NULL ; + +if (!env->pmu_mappings) {/* Assume local operation */ status =perf_env__read_pmu_mappings (env);if (status)return NULL ;