@@ -37,8 +37,8 @@ static int pmu_version;
struct amd_uncore_ctx {
int refcnt;
int cpu;
- struct perf_event **events;
struct hlist_node node;
+ struct perf_event *events[];
};
struct amd_uncore_pmu {
@@ -430,10 +430,8 @@ static void amd_uncore_ctx_free(struct amd_uncore *uncore, unsigned int cpu)
if (cpu == ctx->cpu)
cpumask_clear_cpu(cpu, &pmu->active_mask);
- if (!--ctx->refcnt) {
- kfree(ctx->events);
+ if (!--ctx->refcnt)
kfree(ctx);
- }
*per_cpu_ptr(pmu->ctx, cpu) = NULL;
}
@@ -478,19 +476,13 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
/* Allocate context if sibling does not exist */
if (!curr) {
node = cpu_to_node(cpu);
- curr = kzalloc_node(sizeof(*curr), GFP_KERNEL, node);
+ curr = kzalloc_node(struct_size(curr, events,
+ pmu->num_counters),
+ GFP_KERNEL, node);
if (!curr)
goto fail;
curr->cpu = cpu;
- curr->events = kzalloc_node(sizeof(*curr->events) *
- pmu->num_counters,
- GFP_KERNEL, node);
- if (!curr->events) {
- kfree(curr);
- goto fail;
- }
-
cpumask_set_cpu(cpu, &pmu->active_mask);
}