From 51b57393cfd5ccbc6bbc7451e8878c48fbd96c95 Mon Sep 17 00:00:00 2001 From: Balaji Selvanathan Date: Mon, 7 Sep 2026 16:12:38 +0530 Subject: [PATCH] lib: lmb: return -EFAULT for partial bank-boundary overlap _lmb_alloc_addr() currently returns -EINVAL when a reservation overlaps an available memory bank but extends beyond the bank boundary. It returns -EFAULT when the reservation does not overlap any available memory bank. From LMB's perspective, neither request can be satisfied because the requested reservation is not fully contained within an available region. Callers therefore cannot make practical use of the distinction. boot_fdt_handle_region() treats -EFAULT as a non-fatal condition and silently skips the reservation, while -EINVAL causes a boot-time error message to be printed. For bank-boundary overlap cases this message is misleading because no internal LMB error has occurred; the reservation simply does not fit within available memory. Return -EFAULT for the partial-overlap case as well and update the corresponding unit tests. Signed-off-by: Balaji Selvanathan --- lib/lmb.c | 2 -- test/lib/lmb.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/lmb.c b/lib/lmb.c index ca00047f6242..745410a88954 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -752,8 +752,6 @@ static int _lmb_alloc_addr(phys_addr_t base, phys_size_t size, u32 flags) base + size - 1, 1)) /* ok, reserve the memory */ return lmb_reserve(base, size, flags); - - return -EINVAL; } return -EFAULT; diff --git a/test/lib/lmb.c b/test/lib/lmb.c index 168c66ae6499..e6c05a492dfd 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -781,9 +781,9 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram) ret = lmb_alloc_addr(ram_end, 1, LMB_NONE); ut_asserteq(ret, -EFAULT); ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOMAP); - ut_asserteq(ret, -EINVAL); + ut_asserteq(ret, -EFAULT); ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOOVERWRITE); - ut_asserteq(ret, -EINVAL); + ut_asserteq(ret, -EFAULT); } if (ram != 0) { ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE);