Skip to content

Commit 3af548f

Browse files
Kan LiangPeter Zijlstra
authored andcommitted
perf/x86/uncore: Fix potential NULL pointer in uncore_get_alias_name
The current code assumes that the discovery table provides valid box_ids for the normal units. It's not the case anymore since some units in the discovery table are broken on some SPR variants. Factor out uncore_get_box_id(). Check the existence of the type->box_ids before using it. If it's not available, use pmu_idx. Signed-off-by: Kan Liang <kan.liang@linux.intel.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Tested-by: Michael Petlan <mpetlan@redhat.com> Link: https://lore.kernel.org/r/20230112200105.733466-3-kan.liang@linux.intel.com
1 parent dbf061b commit 3af548f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,12 @@ static const struct attribute_group uncore_pmu_attr_group = {
857857
.attrs = uncore_pmu_attrs,
858858
};
859859

860+
static inline int uncore_get_box_id(struct intel_uncore_type *type,
861+
struct intel_uncore_pmu *pmu)
862+
{
863+
return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx;
864+
}
865+
860866
void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu)
861867
{
862868
struct intel_uncore_type *type = pmu->type;
@@ -865,7 +871,7 @@ void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu)
865871
sprintf(pmu_name, "uncore_type_%u", type->type_id);
866872
else {
867873
sprintf(pmu_name, "uncore_type_%u_%d",
868-
type->type_id, type->box_ids[pmu->pmu_idx]);
874+
type->type_id, uncore_get_box_id(type, pmu));
869875
}
870876
}
871877

@@ -892,7 +898,7 @@ static void uncore_get_pmu_name(struct intel_uncore_pmu *pmu)
892898
* Use the box ID from the discovery table if applicable.
893899
*/
894900
sprintf(pmu->name, "uncore_%s_%d", type->name,
895-
type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx);
901+
uncore_get_box_id(type, pmu));
896902
}
897903
}
898904

0 commit comments

Comments
 (0)