Skip to content

Commit

Permalink
Convert intel uncore to struct_size
Browse files Browse the repository at this point in the history
Need to do a bit of rearranging to make this work.

Signed-off-by: Matthew Wilcox <mawilcox@microsoft.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
  • Loading branch information
Matthew Wilcox authored and Kees Cook committed Jun 12, 2018
1 parent a3ac973 commit 6566f90
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions arch/x86/events/intel/uncore.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,6 @@ static void uncore_types_exit(struct intel_uncore_type **types)
static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
{
struct intel_uncore_pmu *pmus;
struct attribute_group *attr_group;
struct attribute **attrs;
size_t size;
int i, j;

Expand All @@ -891,21 +889,24 @@ static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
0, type->num_counters, 0, 0);

if (type->event_descs) {
struct {
struct attribute_group group;
struct attribute *attrs[];
} *attr_group;
for (i = 0; type->event_descs[i].attr.attr.name; i++);

attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
sizeof(*attr_group), GFP_KERNEL);
attr_group = kzalloc(struct_size(attr_group, attrs, i + 1),
GFP_KERNEL);
if (!attr_group)
goto err;

attrs = (struct attribute **)(attr_group + 1);
attr_group->name = "events";
attr_group->attrs = attrs;
attr_group->group.name = "events";
attr_group->group.attrs = attr_group->attrs;

for (j = 0; j < i; j++)
attrs[j] = &type->event_descs[j].attr.attr;
attr_group->attrs[j] = &type->event_descs[j].attr.attr;

type->events_group = attr_group;
type->events_group = &attr_group->group;
}

type->pmu_group = &uncore_pmu_attr_group;
Expand Down

0 comments on commit 6566f90

Please sign in to comment.