Skip to contentSkip to conversation

powerpc/kexec: Simplify kdump_extra_elfcorehdr_size()

PATCH Applied Thorsten Blum 3 participants 5 messages Jul 30 – Sep 9 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 powerpc/kexec: Simplify kdump_extra_elfcorehdr_size()

Return the size directly and drop the extra_sz variable to simplify kdump_extra_elfcorehdr_size(). The two warning paths now fall through to the existing return 0 at the end of the function.

---
 arch/powerpc/kexec/file_load_64.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/kexec/file_load_64.c +1 -5
index c3503d698428..d0c544079e03 100644
@@ -377,16 +377,12 @@ static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf)
 static unsigned int kdump_extra_elfcorehdr_size(struct crash_mem *cmem)
 {
 #if defined(CONFIG_CRASH_HOTPLUG) && defined(CONFIG_MEMORY_HOTPLUG)
-	unsigned int extra_sz = 0;
-
 	if (CONFIG_CRASH_MAX_MEMORY_RANGES > (unsigned int)PN_XNUM)
 		pr_warn("Number of Phdrs %u exceeds max\n", CONFIG_CRASH_MAX_MEMORY_RANGES);
 	else if (cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES)
 		pr_warn("Configured crash mem ranges may not be enough\n");
 	else
-		extra_sz = (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);
-
-	return extra_sz;
+		return (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);
 #endif
 	return 0;
 }
#1 lore raw

Le 30/07/2026 à 15:19, Thorsten Blum a écrit :

Quoted 18 lines

Return the size directly and drop the extra_sz variable to simplify kdump_extra_elfcorehdr_size(). The two warning paths now fall through to the existing return 0 at the end of the function.

---
  arch/powerpc/kexec/file_load_64.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/kexec/file_load_64.c +0 -1
index c3503d698428..d0c544079e03 100644
@@ -377,16 +377,12 @@ static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf)
  static unsigned int kdump_extra_elfcorehdr_size(struct crash_mem *cmem)
  {
  #if defined(CONFIG_CRASH_HOTPLUG) && defined(CONFIG_MEMORY_HOTPLUG)
-	unsigned int extra_sz = 0;

arch/powerpc/kexec/file_load_64.c static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf) · line 385

Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +1 -4
-
  	if (CONFIG_CRASH_MAX_MEMORY_RANGES > (unsigned int)PN_XNUM)
  		pr_warn("Number of Phdrs %u exceeds max\n", CONFIG_CRASH_MAX_MEMORY_RANGES);
  	else if (cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES)
  		pr_warn("Configured crash mem ranges may not be enough\n");
  	else
-		extra_sz = (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);
-
-	return extra_sz;
+		return (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);

I don't understand.

Previously, when cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES you would return 0. Now you will return something different. For instance if cmem->nr_ranges is (CONFIG_CRASH_MAX_MEMORY_RANGES + 1) you will return (unsigned int)(-1 * sizeof(Elf64_Phdr))

Quoted 3 lines
arch/powerpc/kexec/file_load_64.c +0 -0
  #endif
  	return 0;
  }
#2 lore raw
Quoted 32 lines · Christophe Leroy (CS GROUP)

Le 30/07/2026 à 15:19, Thorsten Blum a écrit :

Quoted 18 lines

Return the size directly and drop the extra_sz variable to simplify kdump_extra_elfcorehdr_size(). The two warning paths now fall through to the existing return 0 at the end of the function.

---
  arch/powerpc/kexec/file_load_64.c | 6 +-----
  1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/kexec/file_load_64.c +0 -1
index c3503d698428..d0c544079e03 100644
@@ -377,16 +377,12 @@ static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf)
  static unsigned int kdump_extra_elfcorehdr_size(struct crash_mem *cmem)
  {
  #if defined(CONFIG_CRASH_HOTPLUG) && defined(CONFIG_MEMORY_HOTPLUG)
-	unsigned int extra_sz = 0;

arch/powerpc/kexec/file_load_64.c static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf) · line 385

Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +1 -4
-
  	if (CONFIG_CRASH_MAX_MEMORY_RANGES > (unsigned int)PN_XNUM)
  		pr_warn("Number of Phdrs %u exceeds max\n", CONFIG_CRASH_MAX_MEMORY_RANGES);
  	else if (cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES)
  		pr_warn("Configured crash mem ranges may not be enough\n");
  	else
-		extra_sz = (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);
-
-	return extra_sz;
+		return (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);

I don't understand.

Quoted 4 lines

Previously, when cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES you would return 0. Now you will return something different. For instance if cmem->nr_ranges is (CONFIG_CRASH_MAX_MEMORY_RANGES + 1) you will return (unsigned int)(-1 * sizeof(Elf64_Phdr))

It still returns 0.

When cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES, the else if branch prints the warning and then falls through to the return 0 at the end of the function. The final else branch is not entered in that case.

No functional changes are intended.

Quoted 4 lines
Quoted 3 lines
arch/powerpc/kexec/file_load_64.c +0 -0
  #endif
  	return 0;
  }
reviewer Reviewed-by
#3 lore raw

Le 30/07/2026 à 16:45, Thorsten Blum a écrit :

Quoted 38 lines · Christophe Leroy (CS GROUP)
Quoted 32 lines

Le 30/07/2026 à 15:19, Thorsten Blum a écrit :

Quoted 18 lines

Return the size directly and drop the extra_sz variable to simplify kdump_extra_elfcorehdr_size(). The two warning paths now fall through to the existing return 0 at the end of the function.

---
   arch/powerpc/kexec/file_load_64.c | 6 +-----
   1 file changed, 1 insertion(+), 5 deletions(-)
arch/powerpc/kexec/file_load_64.c +0 -1
index c3503d698428..d0c544079e03 100644
@@ -377,16 +377,12 @@ static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf)
   static unsigned int kdump_extra_elfcorehdr_size(struct crash_mem *cmem)
   {
   #if defined(CONFIG_CRASH_HOTPLUG) && defined(CONFIG_MEMORY_HOTPLUG)
-	unsigned int extra_sz = 0;

arch/powerpc/kexec/file_load_64.c static int load_backup_segment(struct kimage *image, struct kexec_buf *kbuf) · line 385

Quoted 10 lines
arch/powerpc/kexec/file_load_64.c +1 -4
-
   	if (CONFIG_CRASH_MAX_MEMORY_RANGES > (unsigned int)PN_XNUM)
   		pr_warn("Number of Phdrs %u exceeds max\n", CONFIG_CRASH_MAX_MEMORY_RANGES);
   	else if (cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES)
   		pr_warn("Configured crash mem ranges may not be enough\n");
   	else
-		extra_sz = (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);
-
-	return extra_sz;
+		return (CONFIG_CRASH_MAX_MEMORY_RANGES - cmem->nr_ranges) * sizeof(Elf64_Phdr);

I don't understand.

Quoted 4 lines

Previously, when cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES you would return 0. Now you will return something different. For instance if cmem->nr_ranges is (CONFIG_CRASH_MAX_MEMORY_RANGES + 1) you will return (unsigned int)(-1 * sizeof(Elf64_Phdr))

Quoted 5 lines

It still returns 0.

When cmem->nr_ranges >= CONFIG_CRASH_MAX_MEMORY_RANGES, the else if branch prints the warning and then falls through to the return 0 at the end of the function. The final else branch is not entered in that case.

Hum ... Yes sorry I missed that.

Quoted 7 lines

No functional changes are intended.

Quoted 4 lines
Quoted 3 lines
arch/powerpc/kexec/file_load_64.c +0 -0
   #endif
   	return 0;
   }