mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thorsten Blum <blum@kernel.org>
To: Madhavan Srinivasan <maddy@linux.ibm.com>,
	Michael Ellerman <mpe@ellerman.id.au>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	"Ritesh Harjani (IBM)" <ritesh.list@gmail.com>,
	Shrikanth Hegde <sshegde@linux.ibm.com>,
	Sourabh Jain <sourabhjain@linux.ibm.com>,
	Thorsten Blum <blum@kernel.org>,
	Aditya Gupta <adityag@linux.ibm.com>,
	Hari Bathini <hbathini@linux.ibm.com>,
	Jinjie Ruan <ruanjinjie@huawei.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: [PATCH] powerpc/kexec_file: Simplify add_usable_mem()
Date: Wed, 16 Sep 2026 17:31:49 +0200	[thread overview]
Message-ID: <20260916153149.127278-3-blum@kernel.org> (raw)

Use max() and min() to calculate loc_base and loc_end, respectively.
Skip to the next range if loc_base > loc_end and drop the now-obsolete
boolean add variable.

Signed-off-by: Thorsten Blum <blum@kernel.org>
---
 arch/powerpc/kexec/file_load_64.c | 29 +++++++++--------------------
 1 file changed, 9 insertions(+), 20 deletions(-)

diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c
index bd80c5fb1b1f..6162afbe919a 100644
--- a/arch/powerpc/kexec/file_load_64.c
+++ b/arch/powerpc/kexec/file_load_64.c
@@ -20,6 +20,7 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 #include <linux/memblock.h>
+#include <linux/minmax.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <asm/setup.h>
@@ -104,31 +105,19 @@ static __be64 *check_realloc_usable_mem(struct umem_info *um_info, int cnt)
 static int add_usable_mem(struct umem_info *um_info, u64 base, u64 end)
 {
 	u64 loc_base, loc_end;
-	bool add;
 	int i;
 
 	for (i = 0; i < um_info->nr_ranges; i++) {
-		add = false;
-		loc_base = um_info->ranges[i].start;
-		loc_end = um_info->ranges[i].end;
-		if (loc_base >= base && loc_end <= end)
-			add = true;
-		else if (base <= loc_end && end >= loc_base) {
-			if (loc_base < base)
-				loc_base = base;
-			if (loc_end > end)
-				loc_end = end;
-			add = true;
-		}
+		loc_base = max(base, um_info->ranges[i].start);
+		loc_end = min(end, um_info->ranges[i].end);
+		if (loc_base > loc_end)
+			continue;
 
-		if (add) {
-			if (!check_realloc_usable_mem(um_info, 2))
-				return -ENOMEM;
+		if (!check_realloc_usable_mem(um_info, 2))
+			return -ENOMEM;
 
-			um_info->buf[um_info->idx++] = cpu_to_be64(loc_base);
-			um_info->buf[um_info->idx++] =
-					cpu_to_be64(loc_end - loc_base + 1);
-		}
+		um_info->buf[um_info->idx++] = cpu_to_be64(loc_base);
+		um_info->buf[um_info->idx++] = cpu_to_be64(loc_end - loc_base + 1);
 	}
 
 	return 0;

                 reply	other threads:[~2026-09-16 15:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260916153149.127278-3-blum@kernel.org \
    --to=blum@kernel.org \
    --cc=adityag@linux.ibm.com \
    --cc=chleroy@kernel.org \
    --cc=hbathini@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.ibm.com \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=ritesh.list@gmail.com \
    --cc=ruanjinjie@huawei.com \
    --cc=sourabhjain@linux.ibm.com \
    --cc=sshegde@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®