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]> --- include/lmb.h | 2 ++ lib/lmb.c | 2 +- test/lib/lmb.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/lmb.h b/include/lmb.h index 028dabb19e86..157a24baf978 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 f7c2e826d067..ca00047f6242 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 b93b903f99f9..168c66ae6499 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); -- 2.55.0
