_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 <[email protected]>
---
Changes in v2:
- Reworded the commit message to explain why the overlap is not a
  serious error and why it could be ignored
- Link to v1: 
https://lore.kernel.org/u-boot/20260907-lmb-alloc-addr-efault-v1-1-7a5b73c23...@oss.qualcomm.com/
---
 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 ca00047f624..745410a8895 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 168c66ae649..e6c05a492df 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);

---
base-commit: 509312dc5386ff4c5adabf53a573abca0aac4ce5
change-id: 20260907-lmb-alloc-addr-efault-a29212da721d

Best regards,
-- 
Balaji Selvanathan <[email protected]>

Reply via email to