]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
perf tests pmu: Initialize all fields of test_pmu variable
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 Aug 2024 12:57:20 +0000 (09:57 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 12 Aug 2024 16:42:56 +0000 (13:42 -0300)
Instead of explicitely initializing just the .name and .alias_name,
use struct member named initialization of just the non-null -name field,
the compiler will initialize all the other non-explicitely initialized
fields to NULL.

This makes the code more robust, avoiding the error recently fixed when
the .alias_name was used and contained a random value.

Reviewed-by: Veronika Molnarova <vmolnaro@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Radostin Stoyanov <rstoyano@redhat.com>
Link: https://lore.kernel.org/lkml/e26941f9-f86c-4f2e-b812-20c49fb2c0d3@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/tests/pmu.c

index a4730b5dc0d9259d9b3c71497ecda62346919a89..be18506f6a242546c3c085622d8e3cf7e7a53c69 100644 (file)
@@ -458,10 +458,10 @@ static int test__name_cmp(struct test_suite *test __maybe_unused, int subtest __
  */
 static int test__pmu_match(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
-       struct perf_pmu test_pmu;
-       test_pmu.alias_name = NULL;
+       struct perf_pmu test_pmu = {
+               .name = "pmuname",
+       };
 
-       test_pmu.name = "pmuname";
        TEST_ASSERT_EQUAL("Exact match", perf_pmu__match(&test_pmu, "pmuname"),      true);
        TEST_ASSERT_EQUAL("Longer token", perf_pmu__match(&test_pmu, "longertoken"), false);
        TEST_ASSERT_EQUAL("Shorter token", perf_pmu__match(&test_pmu, "pmu"),        false);