[Intel-gfx] [PATCH 3/5] drm/i915/pmu: change attr_group allocation and initialization

Jani Nikula jani.nikula at intel.com
Thu Nov 2 15:42:28 UTC 2023


Prepare for dynamically allocating struct i915_pmu by changing the
allocation and initialization of the attr_group. With pmu allocated
dynamically, pmu->events_attr_group can't be used for local attr_group
array initialization.

Signed-off-by: Jani Nikula <jani.nikula at intel.com>
---
 drivers/gpu/drm/i915/i915_pmu.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c
index 21ef76a11ed7..3c6191b7fc82 100644
--- a/drivers/gpu/drm/i915/i915_pmu.c
+++ b/drivers/gpu/drm/i915/i915_pmu.c
@@ -1242,13 +1242,7 @@ static bool is_igp(struct drm_i915_private *i915)
 void i915_pmu_register(struct drm_i915_private *i915)
 {
 	struct i915_pmu *pmu = &i915->pmu;
-	const struct attribute_group *attr_groups[] = {
-		&i915_pmu_format_attr_group,
-		&pmu->events_attr_group,
-		&i915_pmu_cpumask_attr_group,
-		NULL
-	};
-
+	const struct attribute_group **attr_groups;
 	int ret = -ENOMEM;
 
 	if (GRAPHICS_VER(i915) <= 2) {
@@ -1281,11 +1275,17 @@ void i915_pmu_register(struct drm_i915_private *i915)
 	if (!pmu->events_attr_group.attrs)
 		goto err_name;
 
-	pmu->base.attr_groups = kmemdup(attr_groups, sizeof(attr_groups),
-					GFP_KERNEL);
-	if (!pmu->base.attr_groups)
+	attr_groups = kcalloc(4, sizeof(struct attribute_group *), GFP_KERNEL);
+	if (!attr_groups)
 		goto err_attr;
 
+	attr_groups[0] = &i915_pmu_format_attr_group;
+	attr_groups[1] = &pmu->events_attr_group;
+	attr_groups[2] = &i915_pmu_cpumask_attr_group;
+	attr_groups[3] = NULL; /* sentinel */
+
+	pmu->base.attr_groups = attr_groups;
+
 	pmu->base.module	= THIS_MODULE;
 	pmu->base.task_ctx_nr	= perf_invalid_context;
 	pmu->base.event_init	= i915_pmu_event_init;
-- 
2.39.2



More information about the Intel-gfx mailing list