diff options
| author | Jonas Karlman <[email protected]> | 2026-08-11 23:16:48 +0000 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-08-24 13:58:00 -0600 |
| commit | 480644c06e202abec58543aec502f218939fff1e (patch) | |
| tree | bf3b79e3c718430c7a442ef2225a06349af1aa71 | |
| parent | 93e5e5f4cbefccab206a79f86e98c2c39a9d2440 (diff) | |
lmb: Return -EFAULT when freeing unallocated memory regions
Make lmb_free() return -EFAULT when the requested memory region is not
allocated, instead of the generic -1 error value.
Document the updated error code in the public API comment and change the
LMB unit test to check for the new -EFAULT errno value.
Signed-off-by: Jonas Karlman <[email protected]>
Reviewed-by: Randolph Sapp <[email protected]>
| -rw-r--r-- | include/lmb.h | 2 | ||||
| -rw-r--r-- | lib/lmb.c | 2 | ||||
| -rw-r--r-- | test/lib/lmb.c | 2 |
3 files changed, 4 insertions, 2 deletions
diff --git a/include/lmb.h b/include/lmb.h index 028dabb19e8..157a24baf97 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -168,6 +168,8 @@ int lmb_is_reserved_flags(phys_addr_t addr, int flags); * @flags: Memory region attributes * * Return: 0 on success, negative error code on failure. + * + * The return value can be -EFAULT when the region has not been allocated. */ long lmb_free(phys_addr_t base, phys_size_t size, u32 flags); diff --git a/lib/lmb.c b/lib/lmb.c index f7c2e826d06..ca00047f624 100644 --- a/lib/lmb.c +++ b/lib/lmb.c @@ -286,7 +286,7 @@ static long _lmb_free(struct alist *lmb_rgn_lst, phys_addr_t base, /* Didn't find the region */ if (i == lmb_rgn_lst->count) - return -1; + return -EFAULT; /* Check to see if we are removing entire region */ if (rgnbegin == base && rgnend == end) { diff --git a/test/lib/lmb.c b/test/lib/lmb.c index b93b903f99f..168c66ae649 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -477,7 +477,7 @@ static int lib_test_lmb_at_0(struct unit_test_state *uts) 0, 0, 0, 0); /* check that this was an error by freeing b */ ret = lmb_free(b, 4, LMB_NONE); - ut_asserteq(ret, -1); + ut_asserteq(ret, -EFAULT); ASSERT_LMB(mem_lst, used_lst, ram, ram_size, 1, a, ram_size - 4, 0, 0, 0, 0); |
