]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
timers/migration: Turn tmigr_hierarchy level_list into a flexible array
authorRosen Penev <rosenp@gmail.com>
Fri, 22 May 2026 23:16:18 +0000 (16:16 -0700)
committerThomas Gleixner <tglx@kernel.org>
Tue, 2 Jun 2026 19:34:03 +0000 (21:34 +0200)
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
kernel/time/timer_migration.c
kernel/time/timer_migration.h

index 8ba53ad49173351c5e4ee1898735adecf4533a22..548d84955f4cef52cedcb020bca18b094789f587 100644 (file)
@@ -1963,17 +1963,15 @@ static struct tmigr_hierarchy *tmigr_get_hierarchy(int cpu)
        if (hier)
                return hier;
 
-       hier = kzalloc(sizeof(*hier), GFP_KERNEL);
+       hier = kzalloc_flex(*hier, level_list, tmigr_hierarchy_levels);
        if (!hier)
                return ERR_PTR(-ENOMEM);
 
        hier->cpumask = kzalloc(cpumask_size(), GFP_KERNEL);
-       if (!hier->cpumask)
-               goto err;
-
-       hier->level_list = kzalloc_objs(struct list_head, tmigr_hierarchy_levels);
-       if (!hier->level_list)
-               goto err;
+       if (!hier->cpumask) {
+               kfree(hier);
+               return ERR_PTR(-ENOMEM);
+       }
 
        for (int i = 0; i < tmigr_hierarchy_levels; i++)
                INIT_LIST_HEAD(&hier->level_list[i]);
@@ -1982,10 +1980,6 @@ static struct tmigr_hierarchy *tmigr_get_hierarchy(int cpu)
        list_add_tail(&hier->node, &tmigr_hierarchy_list);
 
        return hier;
-err:
-       kfree(hier->cpumask);
-       kfree(hier);
-       return ERR_PTR(-ENOMEM);
 }
 
 static int tmigr_connect_old_root(struct tmigr_hierarchy *hier, int cpu,
index ea8db95fc63ea1cd38802893af6acb1a5e5e1621..31735dd523278530292ce0154fb5ba4d9a60cda3 100644 (file)
@@ -9,19 +9,18 @@
  * struct tmigr_hierarchy - a hierarchy associated to a given CPU capacity.
  *                          Homogeneous systems have only one hierarchy.
  *                          Heterogenous have one hierarchy per CPU capacity.
- * @level_list:        Per level lists of tmigr groups
  * @cpumask:   CPUs belonging to this hierarchy
  * @root:      The current root of the hierarchy
  * @capacity:  CPU capacity associated to this hierarchy
  * @node:      Node in the global hierarchy list
+ * @level_list:        Per level lists of tmigr groups
  */
 struct tmigr_hierarchy {
-       struct list_head        *level_list;
        struct cpumask          *cpumask;
        struct tmigr_group      *root;
        unsigned long           capacity;
        struct list_head        node;
-
+       struct list_head        level_list[];
 };
 
 /**