perf env: Remove unnecessary NULL tests
authorIan Rogers <irogers@google.com>
Mon, 9 Oct 2023 18:39:08 +0000 (11:39 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 17:01:56 +0000 (10:01 -0700)
clang-tidy was warning:
```
util/env.c:334:23: warning: Access to field 'nr_pmu_mappings' results in a dereference of a null pointer (loaded from variable 'env') [clang-analyzer-core.NullDereference]
        env->nr_pmu_mappings = pmu_num;
```

As functions are called potentially when !env was true. This condition
could never be true as it would produce a segv, so remove the
unnecessary NULL tests and silence clang-tidy.

Signed-off-by: Ian Rogers <irogers@google.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Nick Desaulniers <ndesaulniers@google.com>
Cc: Yang Jihong <yangjihong1@huawei.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: llvm@lists.linux.dev
Cc: Ming Wang <wangming01@loongson.cn>
Cc: Tom Rix <trix@redhat.com>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20231009183920.200859-8-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/env.c

index a164164..44140b7 100644 (file)
@@ -457,7 +457,7 @@ const char *perf_env__cpuid(struct perf_env *env)
 {
        int status;
 
-       if (!env || !env->cpuid) { /* Assume local operation */
+       if (!env->cpuid) { /* Assume local operation */
                status = perf_env__read_cpuid(env);
                if (status)
                        return NULL;
@@ -470,7 +470,7 @@ int perf_env__nr_pmu_mappings(struct perf_env *env)
 {
        int status;
 
-       if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
+       if (!env->nr_pmu_mappings) { /* Assume local operation */
                status = perf_env__read_pmu_mappings(env);
                if (status)
                        return 0;
@@ -483,7 +483,7 @@ const char *perf_env__pmu_mappings(struct perf_env *env)
 {
        int status;
 
-       if (!env || !env->pmu_mappings) { /* Assume local operation */
+       if (!env->pmu_mappings) { /* Assume local operation */
                status = perf_env__read_pmu_mappings(env);
                if (status)
                        return NULL;