Skip to content

Commit 6566f90

Browse files
Matthew Wilcoxkees
authored andcommitted
Convert intel uncore to struct_size
Need to do a bit of rearranging to make this work. Signed-off-by: Matthew Wilcox <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent a3ac973 commit 6566f90

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

arch/x86/events/intel/uncore.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -865,8 +865,6 @@ static void uncore_types_exit(struct intel_uncore_type **types)
865865
static int __init uncore_type_init(struct intel_uncore_type *type, bool setid)
866866
{
867867
struct intel_uncore_pmu *pmus;
868-
struct attribute_group *attr_group;
869-
struct attribute **attrs;
870868
size_t size;
871869
int i, j;
872870

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

893891
if (type->event_descs) {
892+
struct {
893+
struct attribute_group group;
894+
struct attribute *attrs[];
895+
} *attr_group;
894896
for (i = 0; type->event_descs[i].attr.attr.name; i++);
895897

896-
attr_group = kzalloc(sizeof(struct attribute *) * (i + 1) +
897-
sizeof(*attr_group), GFP_KERNEL);
898+
attr_group = kzalloc(struct_size(attr_group, attrs, i + 1),
899+
GFP_KERNEL);
898900
if (!attr_group)
899901
goto err;
900902

901-
attrs = (struct attribute **)(attr_group + 1);
902-
attr_group->name = "events";
903-
attr_group->attrs = attrs;
903+
attr_group->group.name = "events";
904+
attr_group->group.attrs = attr_group->attrs;
904905

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

908-
type->events_group = attr_group;
909+
type->events_group = &attr_group->group;
909910
}
910911

911912
type->pmu_group = &uncore_pmu_attr_group;

0 commit comments

Comments
 (0)