提交 fd6a6d4e 编写于 作者: K Kan Liang 提交者: Yunying Sun

perf/x86/uncore: Fix potential NULL pointer in uncore_get_alias_name

mainline inclusion
from mainline-v6.3-rc1
commit 3af548f2
category: bugfix
bugzilla: https://gitee.com/openeuler/intel-kernel/issues/I7H29Y
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3af548f2361077cd53762c88d62343d4e8ea1efb

Intel-SIG: commit 3af548f2 perf/x86/uncore: Fix potential NULL pointer in uncore_get_alias_name
Backport SPR MCC UPI uncore discovery warning fixes to OLK-5.10.

-------------------------------------

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: NKan Liang <kan.liang@linux.intel.com>
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Tested-by: NMichael Petlan <mpetlan@redhat.com>
Link: https://lore.kernel.org/r/20230112200105.733466-3-kan.liang@linux.intel.comSigned-off-by: NYunying Sun <yunying.sun@intel.com>
上级 1a5e6039
...@@ -849,6 +849,12 @@ static const struct attribute_group uncore_pmu_attr_group = { ...@@ -849,6 +849,12 @@ static const struct attribute_group uncore_pmu_attr_group = {
.attrs = uncore_pmu_attrs, .attrs = uncore_pmu_attrs,
}; };
static inline int uncore_get_box_id(struct intel_uncore_type *type,
struct intel_uncore_pmu *pmu)
{
return type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx;
}
void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu) void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu)
{ {
struct intel_uncore_type *type = pmu->type; struct intel_uncore_type *type = pmu->type;
...@@ -857,7 +863,7 @@ void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu) ...@@ -857,7 +863,7 @@ void uncore_get_alias_name(char *pmu_name, struct intel_uncore_pmu *pmu)
sprintf(pmu_name, "uncore_type_%u", type->type_id); sprintf(pmu_name, "uncore_type_%u", type->type_id);
else { else {
sprintf(pmu_name, "uncore_type_%u_%d", sprintf(pmu_name, "uncore_type_%u_%d",
type->type_id, type->box_ids[pmu->pmu_idx]); type->type_id, uncore_get_box_id(type, pmu));
} }
} }
...@@ -884,7 +890,7 @@ static void uncore_get_pmu_name(struct intel_uncore_pmu *pmu) ...@@ -884,7 +890,7 @@ static void uncore_get_pmu_name(struct intel_uncore_pmu *pmu)
* Use the box ID from the discovery table if applicable. * Use the box ID from the discovery table if applicable.
*/ */
sprintf(pmu->name, "uncore_%s_%d", type->name, sprintf(pmu->name, "uncore_%s_%d", type->name,
type->box_ids ? type->box_ids[pmu->pmu_idx] : pmu->pmu_idx); uncore_get_box_id(type, pmu));
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册