diff options
| -rw-r--r-- | include/lmb.h | 2 | ||||
| -rw-r--r-- | lib/lmb.c | 4 | ||||
| -rw-r--r-- | test/lib/lmb.c | 10 |
3 files changed, 13 insertions, 3 deletions
diff --git a/include/lmb.h b/include/lmb.h index ed472e9ef2e..028dabb19e8 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 77440a48486..f7c2e826d06 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 b6259bef442..b93b903f99f 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); |
