[PATCH] riscv: kexec: use min to simplify riscv_kexec_elf_load
Thorsten Blum
thorsten.blum at linux.dev
Fri May 15 09:49:40 PDT 2026
Use min() to replace the open-coded version and assign the result
directly to kbuf.bufsz. Drop the now-unused local size variable.
Signed-off-by: Thorsten Blum <thorsten.blum at linux.dev>
---
arch/riscv/kernel/kexec_elf.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/arch/riscv/kernel/kexec_elf.c b/arch/riscv/kernel/kexec_elf.c
index 531d348db84d..528141df90ba 100644
--- a/arch/riscv/kernel/kexec_elf.c
+++ b/arch/riscv/kernel/kexec_elf.c
@@ -19,6 +19,7 @@
#include <linux/libfdt.h>
#include <linux/types.h>
#include <linux/memblock.h>
+#include <linux/minmax.h>
#include <asm/setup.h>
static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
@@ -27,7 +28,6 @@ static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
{
int i;
int ret = 0;
- size_t size;
struct kexec_buf kbuf = {};
const struct elf_phdr *phdr;
@@ -38,12 +38,8 @@ static int riscv_kexec_elf_load(struct kimage *image, struct elfhdr *ehdr,
if (phdr->p_type != PT_LOAD)
continue;
- size = phdr->p_filesz;
- if (size > phdr->p_memsz)
- size = phdr->p_memsz;
-
kbuf.buffer = (void *) elf_info->buffer + phdr->p_offset;
- kbuf.bufsz = size;
+ kbuf.bufsz = min(phdr->p_filesz, phdr->p_memsz);
kbuf.buf_align = phdr->p_align;
kbuf.mem = phdr->p_paddr - old_pbase + new_pbase;
kbuf.memsz = phdr->p_memsz;
More information about the linux-riscv
mailing list