@@ -957,12 +957,21 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
957
957
if (!pmu )
958
958
return NULL ;
959
959
960
- INIT_LIST_HEAD (& pmu -> format );
961
- INIT_LIST_HEAD (& pmu -> aliases );
962
- INIT_LIST_HEAD (& pmu -> caps );
963
960
pmu -> name = strdup (name );
964
961
if (!pmu -> name )
965
962
goto err ;
963
+
964
+ /*
965
+ * Read type early to fail fast if a lookup name isn't a PMU. Ensure
966
+ * that type value is successfully assigned (return 1).
967
+ */
968
+ if (perf_pmu__scan_file_at (pmu , dirfd , "type" , "%u" , & type ) != 1 )
969
+ goto err ;
970
+
971
+ INIT_LIST_HEAD (& pmu -> format );
972
+ INIT_LIST_HEAD (& pmu -> aliases );
973
+ INIT_LIST_HEAD (& pmu -> caps );
974
+
966
975
/*
967
976
* The pmu data we store & need consists of the pmu
968
977
* type value and format definitions. Load both right
@@ -982,10 +991,6 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const char
982
991
pmu -> is_core = is_pmu_core (name );
983
992
pmu -> cpus = pmu_cpumask (dirfd , name , pmu -> is_core );
984
993
985
- /* Read type, and ensure that type value is successfully assigned (return 1) */
986
- if (perf_pmu__scan_file_at (pmu , dirfd , "type" , "%u" , & type ) != 1 )
987
- goto err ;
988
-
989
994
alias_name = pmu_find_alias_name (name );
990
995
if (alias_name ) {
991
996
pmu -> alias_name = strdup (alias_name );
0 commit comments