sparc: Replace one-element array with flexible array member
PATCH 1/1 sparc: Replace one-element array with flexible array member
Replace the deprecated one-element array with a modern flexible array member in the struct hvtramp_descr.
Additionally, 15 unnecessary bytes are allocated for hdesc, but instead of fixing the parentheses in the open-coded version, use struct_size() to calculate the correct number of bytes.
--- arch/sparc/include/asm/hvtramp.h | 2 +- arch/sparc/kernel/smp_64.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)
arch/sparc/include/asm/hvtramp.h +1 -1
@@ -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);
arch/sparc/kernel/smp_64.c +1 -3
@@ -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 -1 ),GFP_KERNEL );if (!hdesc) { printk(KERN_ERR "ldom_startcpu_cpuid: Cannot allocate "
Signature · 1 line
2.47.0
Quoted 4 lines · Thorsten Blum
Replace the deprecated one-element array with a modern flexible array member in the struct
hvtramp_descr.Additionally, 15 unnecessary bytes are allocated for hdesc, but instead
15? unnecessary?
Quoted 15 lines
of fixing the parentheses in the open-coded version, use
struct_size()to calculate the correct number of bytes.Signed-off-by Thorsten Blum <[email protected]>--- arch/sparc/include/asm/hvtramp.h | 2 +- arch/sparc/kernel/smp_64.c | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-)arch/sparc/include/asm/hvtramp.h +0
-0
arch/sparc/include/asm/hvtramp.h struct hvtramp_descr { · line 21
Quoted 6 lines
arch/sparc/include/asm/hvtramp.h +1
-1@@ -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[]; };
It seems this struct is a candidate for __counted_by()
Quoted 7 lines
arch/sparc/include/asm/hvtramp.h +0
-0void hv_cpu_startup (unsigned long hvdescr_pa);arch/sparc/kernel/smp_64.c +0
-0
arch/sparc/kernel/smp_64.c static void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg, · line 301
Quoted 8 lines
arch/sparc/kernel/smp_64.c +1
-3@@ -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 -1 ),GFP_KERNEL );
Now the code is broken because it's allocating num_kernel_image_mappings - 1 elements instead of num_kernel_image_mappings.
--
Gustavo
Quoted 6 lines · Gustavo A. R. Silva
Quoted 3 lines · Thorsten Blum
Replace the deprecated one-element array with a modern flexible array member in the struct
hvtramp_descr.
Additionally, 15 unnecessary bytes are allocated for hdesc, but instead15? unnecessary?
hvtramp_mapping is 16 bytes and the size is calculated as follows:
(16 * num_kernel_image_mappings - 1)
which is 15 bytes too many for any number of mappings because hdesc includes the first map. It probably should have been:
16 * (num_kernel_image_mappings - 1)
unless I'm missing something.
Quoted 1 line
It seems this struct is a candidate for
__counted_by()
Yes, but sparc doesn't seem to support it?
Quoted 2 lines
Now the code is broken because it's allocating
num_kernel_image_mappings - 1elements instead ofnum_kernel_image_mappings.
Ah sorry, missed that and will fix in v2 shortly.
Thanks,
Thorsten
Quoted 8 lines · Thorsten Blum
Quoted 6 lines · Gustavo A. R. Silva
Quoted 3 lines · Thorsten Blum
Replace the deprecated one-element array with a modern flexible array member in the struct
hvtramp_descr.
Additionally, 15 unnecessary bytes are allocated for hdesc, but instead15? unnecessary?
Quoted 8 lines
hvtramp_mappingis 16 bytes and the size is calculated as follows:(16 * num_kernel_image_mappings - 1)which is 15 bytes too many for any number of mappings because hdesc includes the first map. It probably should have been:
16 * (num_kernel_image_mappings - 1)
Ah yes, that opening parenthesis before sizeof(struct hvtramp_mapping) was misplaced.
Quoted 11 lines
unless I'm missing something.
Quoted 1 line
It seems this struct is a candidate for
__counted_by()Yes, but sparc doesn't seem to support it?
Quoted 2 lines
Now the code is broken because it's allocating
num_kernel_image_mappings - 1elements instead ofnum_kernel_image_mappings.Ah sorry, missed that and will fix in v2 shortly.
Thanks
--
Gustavo