Skip to contentSkip to conversation

sparc: Replace one-element array with flexible array member

PATCH In review Thorsten Blum 2 participants 3 messages Nov 11, 2024 – Nov 16, 2024 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 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.

---
Changes in v2:
- Fix the number of mappings after feedback from Gustavo A. R. Silva
- Link to v1: https://lore.kernel.org/r/[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 +1 -1
index 688ea43af0f5..ce2453ea4f2b 100644
@@ -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
index e40c395db202..24d980220bf1 100644
@@ -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 "
Signature · 1 line
2.47.0
#1 lore raw
Quoted 10 lines · Thorsten Blum

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.

---

If this justifies a Fixes: tag, it should probably be:

Fixes 64658743fdd4 ("[SPARC64]: Remove most limitations to kernel image size.")

Thanks,
Thorsten

maintainer Reviewed-by
#2 lore raw
Quoted 8 lines · Thorsten Blum
Quoted 7 lines · Thorsten Blum

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.

Quoted 7 lines
Quoted 3 lines

---

If this justifies a Fixes: tag, it should probably be:

Fixes 64658743fdd4 ("[SPARC64]: Remove most limitations to kernel image size.")

Picking this up to my for-next.

Thanks,
Andreas