From: Jonas Karlman <jonas@kwiboo.se>
To: Tom Rini <trini@konsulko.com>, Randolph Sapp <rs@ti.com>,
Simon Glass <sjg@chromium.org>,
Ilias Apalodimas <ilias.apalodimas@linaro.org>
Cc: Joseph Guo <qijian.guo@nxp.com>,
Emanuele Ghidoli <ghidoliemanuele@gmail.com>,
Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>,
u-boot@lists.u-boot-project.org, Jonas Karlman <jonas@kwiboo.se>
Subject: [PATCH v2 1/3] lmb: Return -EFAULT when requested region is not part of memory map
Date: Tue, 11 Aug 2026 23:16:47 +0000 [thread overview]
Message-ID: <20260811231650.3150771-2-jonas@kwiboo.se> (raw)
In-Reply-To: <20260811231650.3150771-1-jonas@kwiboo.se>
lmb_alloc_addr() is documented to return -EINVAL when the requested
memory region is not part of the LMB memory map. However, -EINVAL is
also used to e.g. indicate that a NULL pointer is passed as the addr
parameter or when the requested memory region partially overlaps an
existing region.
Change lmb_alloc_addr() to return -EFAULT when the requested memory
region is not part of the LMB memory map to make the type of error known
to callers. Also extend unit tests to validate that the return code has
stay the same when the requested memory region partially overlaps.
No caller of lmb_alloc_addr() is checking what type of error code is
returned, so this change has no intended behavior change.
Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
include/lmb.h | 2 +-
lib/lmb.c | 4 +++-
test/lib/lmb.c | 10 +++++++++-
3 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h
index ed472e9ef2e1..028dabb19e86 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -124,7 +124,7 @@ struct lmb {
* Return: 0 on success, -ve value on failure
*
* When the allocation is of type @LMB_MEM_ALLOC_ADDR, the return value can
- * be -EINVAL if the requested memory region is not part of the LMB memory
+ * be -EFAULT if the requested memory region is not part of the LMB memory
* map, and -EEXIST if the requested region is already allocated.
*/
int lmb_alloc_mem(enum lmb_mem_type type, u64 align, phys_addr_t *addr,
diff --git a/lib/lmb.c b/lib/lmb.c
index 77440a48486c..f7c2e826d067 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -752,9 +752,11 @@ 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 -EINVAL;
+ return -EFAULT;
}
int lmb_alloc_mem(enum lmb_mem_type type, u64 align, phys_addr_t *addr,
diff --git a/test/lib/lmb.c b/test/lib/lmb.c
index b6259bef4426..b93b903f99f9 100644
--- a/test/lib/lmb.c
+++ b/test/lib/lmb.c
@@ -779,11 +779,19 @@ static int test_alloc_addr(struct unit_test_state *uts, const phys_addr_t ram)
/* check that allocating outside memory fails */
if (ram_end != 0) {
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);
+ ret = lmb_alloc_addr(ram_end - 1, 2, LMB_NOOVERWRITE);
ut_asserteq(ret, -EINVAL);
}
if (ram != 0) {
ret = lmb_alloc_addr(ram - 1, 1, LMB_NONE);
- ut_asserteq(ret, -EINVAL);
+ ut_asserteq(ret, -EFAULT);
+ ret = lmb_alloc_addr(ram - 1, 2, LMB_NOMAP);
+ ut_asserteq(ret, -EEXIST);
+ ret = lmb_alloc_addr(ram - 1, 2, LMB_NOOVERWRITE);
+ ut_asserteq(ret, -EEXIST);
}
lmb_pop(&store);
--
2.55.0
next prev parent reply other threads:[~2026-08-11 23:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-11 23:16 [PATCH v2 0/3] boot: image-fdt: Restore suppression of irrelevant ERROR message Jonas Karlman
2026-08-11 23:16 ` Jonas Karlman [this message]
2026-08-12 21:12 ` [PATCH v2 1/3] lmb: Return -EFAULT when requested region is not part of memory map Randolph Sapp
2026-08-11 23:16 ` [PATCH v2 2/3] lmb: Return -EFAULT when freeing unallocated memory regions Jonas Karlman
2026-08-12 21:13 ` Randolph Sapp
2026-08-11 23:16 ` [PATCH v2 3/3] boot: image-fdt: Restore suppression of irrelevant ERROR message Jonas Karlman
2026-08-12 21:14 ` Randolph Sapp
2026-08-25 0:46 ` [PATCH v2 0/3] " Tom Rini
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=20260811231650.3150771-2-jonas@kwiboo.se \
--to=jonas@kwiboo.se \
--cc=balaji.selvanathan@oss.qualcomm.com \
--cc=ghidoliemanuele@gmail.com \
--cc=ilias.apalodimas@linaro.org \
--cc=qijian.guo@nxp.com \
--cc=rs@ti.com \
--cc=sjg@chromium.org \
--cc=trini@konsulko.com \
--cc=u-boot@lists.u-boot-project.org \
/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