perf trace-event-info: Avoid passing NULL value to closedir
authorIan Rogers <irogers@google.com>
Mon, 9 Oct 2023 18:39:18 +0000 (11:39 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Thu, 12 Oct 2023 17:01:57 +0000 (10:01 -0700)
If opendir failed then closedir was passed NULL which is
erroneous. Caught by 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-18-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/trace-event-info.c

index 319ccf09a4351efd30d3959545ab10b791463290..c8755679281eb334c8cf0e98ffc3d9bf99cc72b9 100644 (file)
@@ -313,7 +313,8 @@ static int record_event_files(struct tracepoint_path *tps)
        }
        err = 0;
 out:
-       closedir(dir);
+       if (dir)
+               closedir(dir);
        put_tracing_file(path);
 
        return err;