Skip to content

Commit 45b49d7

Browse files
nehebThomas Gleixner
authored andcommitted
timers/migration: Turn tmigr_hierarchy level_list into a flexible array
The level_list array is allocated separately right after the parent struct. The size of the array is already known. Move level_list to the struct tail as a flexible array member and fold the two allocations into a single kzalloc_flex(). Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Assisted-by: Claude:Opus-4.7 Link: https://patch.msgid.link/20260522231618.41622-1-rosenp@gmail.com
1 parent d4f198c commit 45b49d7

2 files changed

Lines changed: 7 additions & 14 deletions

File tree

kernel/time/timer_migration.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,17 +1963,15 @@ static struct tmigr_hierarchy *tmigr_get_hierarchy(int cpu)
19631963
if (hier)
19641964
return hier;
19651965

1966-
hier = kzalloc(sizeof(*hier), GFP_KERNEL);
1966+
hier = kzalloc_flex(*hier, level_list, tmigr_hierarchy_levels);
19671967
if (!hier)
19681968
return ERR_PTR(-ENOMEM);
19691969

19701970
hier->cpumask = kzalloc(cpumask_size(), GFP_KERNEL);
1971-
if (!hier->cpumask)
1972-
goto err;
1973-
1974-
hier->level_list = kzalloc_objs(struct list_head, tmigr_hierarchy_levels);
1975-
if (!hier->level_list)
1976-
goto err;
1971+
if (!hier->cpumask) {
1972+
kfree(hier);
1973+
return ERR_PTR(-ENOMEM);
1974+
}
19771975

19781976
for (int i = 0; i < tmigr_hierarchy_levels; i++)
19791977
INIT_LIST_HEAD(&hier->level_list[i]);
@@ -1982,10 +1980,6 @@ static struct tmigr_hierarchy *tmigr_get_hierarchy(int cpu)
19821980
list_add_tail(&hier->node, &tmigr_hierarchy_list);
19831981

19841982
return hier;
1985-
err:
1986-
kfree(hier->cpumask);
1987-
kfree(hier);
1988-
return ERR_PTR(-ENOMEM);
19891983
}
19901984

19911985
static int tmigr_connect_old_root(struct tmigr_hierarchy *hier, int cpu,

kernel/time/timer_migration.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,18 @@
99
* struct tmigr_hierarchy - a hierarchy associated to a given CPU capacity.
1010
* Homogeneous systems have only one hierarchy.
1111
* Heterogenous have one hierarchy per CPU capacity.
12-
* @level_list: Per level lists of tmigr groups
1312
* @cpumask: CPUs belonging to this hierarchy
1413
* @root: The current root of the hierarchy
1514
* @capacity: CPU capacity associated to this hierarchy
1615
* @node: Node in the global hierarchy list
16+
* @level_list: Per level lists of tmigr groups
1717
*/
1818
struct tmigr_hierarchy {
19-
struct list_head *level_list;
2019
struct cpumask *cpumask;
2120
struct tmigr_group *root;
2221
unsigned long capacity;
2322
struct list_head node;
24-
23+
struct list_head level_list[];
2524
};
2625

2726
/**

0 commit comments

Comments
 (0)