sparc: Replace one-element array with flexible array member
authorThorsten Blum <thorsten.blum@linux.dev>
Mon, 11 Nov 2024 20:47:21 +0000 (21:47 +0100)
committerAndreas Larsson <andreas@gaisler.com>
Sat, 16 Nov 2024 08:54:12 +0000 (09:54 +0100)
Replace the deprecated one-element array with a modern flexible array
member in the struct hvtramp_descr.

Additionally, 15 unnecessary bytes were allocated for hdesc, but instead
of fixing the parentheses in the open-coded version, use struct_size()
to calculate the correct number of bytes.

Link: https://github.com/KSPP/linux/issues/79
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Fixes: 64658743fdd4 ("[SPARC64]: Remove most limitations to kernel image size.")
Reviewed-by: Andreas Larsson <andreas@gaisler.com>
Link: https://lore.kernel.org/r/20241111204724.165263-2-thorsten.blum@linux.dev
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
arch/sparc/include/asm/hvtramp.h
arch/sparc/kernel/smp_64.c

index 688ea43..ce2453e 100644 (file)
@@ -17,7 +17,7 @@ struct hvtramp_descr {
        __u64                   fault_info_va;
        __u64                   fault_info_pa;
        __u64                   thread_reg;
-       struct hvtramp_mapping  maps[1];
+       struct hvtramp_mapping  maps[];
 };
 
 void hv_cpu_startup(unsigned long hvdescr_pa);
index e40c395..5cbd6ed 100644 (file)
@@ -297,9 +297,7 @@ static void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg,
        unsigned long hv_err;
        int i;
 
-       hdesc = kzalloc(sizeof(*hdesc) +
-                       (sizeof(struct hvtramp_mapping) *
-                        num_kernel_image_mappings - 1),
+       hdesc = kzalloc(struct_size(hdesc, maps, num_kernel_image_mappings),
                        GFP_KERNEL);
        if (!hdesc) {
                printk(KERN_ERR "ldom_startcpu_cpuid: Cannot allocate "