diff mbox series

of: fdt: add size 0 check after page align

Message ID 20240302140335.117769-1-skseofh@gmail.com
State Changes Requested, archived
Headers show
Series of: fdt: add size 0 check after page align | expand

Checks

Context Check Description
robh/checkpatch success
robh/patch-applied fail build log

Commit Message

DaeRo Lee March 2, 2024, 2:03 p.m. UTC
From: Daero Lee <skseofh@gmail.com>

After page aligning, the size may become zero. So I added exception
handling code for size 0.

example : 4K page size
    [before page align]
        base = 0x1800
        size = 0x1100

    [after page align]
        size = 0x900
        base = 0x2000

        size &= PAGE_MASK(~0x7FFF) = 0

Signed-off-by: Daero Lee <skseofh@gmail.com>
---
 drivers/of/fdt.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Rob Herring March 4, 2024, 1:26 p.m. UTC | #1
On Sat, Mar 2, 2024 at 8:03 AM <skseofh@gmail.com> wrote:
>
> From: Daero Lee <skseofh@gmail.com>
>
> After page aligning, the size may become zero. So I added exception
> handling code for size 0.

That may be true, but when would anyone only have memory regions of
less than 2 pages. In any case memblock_add will just do nothing. What
is the actual problem you are having?

Rob
DaeRo Lee March 4, 2024, 2:51 p.m. UTC | #2
From: skseofh@gmail.com
Reply-To: 
Subject: 
In-Reply-To: CAL_JsqKNGjKq3vcUPFiPa9JNq-8=oP=uBSD=tyKaPMH3cvAkww@mail.gmail.com

>>
>> From: Daero Lee <skseofh@gmail.com>
>>
>> After page aligning, the size may become zero. So I added exception
>> handling code for size 0.
>
>That may be true, but when would anyone only have memory regions of
>less than 2 pages. In any case memblock_add will just do nothing. What
>is the actual problem you are having?

I modified the patch to clear this. Please check.
diff mbox series

Patch

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index bf502ba8da95..01156088fbb4 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -1232,6 +1232,11 @@  void __init __weak early_init_dt_add_memory_arch(u64 base, u64 size)
 		base = PAGE_ALIGN(base);
 	}
 	size &= PAGE_MASK;
+	if (!size) {
+		pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",
+			base, base + size);
+		return;
+	}
 
 	if (base > MAX_MEMBLOCK_ADDR) {
 		pr_warn("Ignoring memory block 0x%llx - 0x%llx\n",