lmb: check if a region can be reserved by lmb_reserve()
authorSughosh Ganu <sughosh.ganu@linaro.org>
Mon, 3 Mar 2025 13:32:26 +0000 (19:02 +0530)
committerTom Rini <trini@konsulko.com>
Tue, 18 Mar 2025 01:39:27 +0000 (19:39 -0600)
commit56f186a68b35e8b45136fd44b69c554a0bb0ce35
tree133f5792ddff48913c6df72ab72777920420ade1
parent9943015f1b39fcb2de16ee72f1599c342620c561
lmb: check if a region can be reserved by lmb_reserve()

The logic used in lmb_alloc() takes into consideration the existing
reserved regions, and ensures that the allocated region does not
overlap with any existing allocated regions. The lmb_reserve()
function is not doing any such checks -- the requested region might
overlap with an existing region. This also shows up with
lmb_alloc_addr() as this function ends up calling lmb_reserve().

Add a function which checks if the region requested is overlapping
with an existing reserved region, and allow for the reservation to
happen only if both the regions have LMB_NONE flag, which allows
re-requesting of the region. In any other scenario of an overlap, have
lmb_reserve() return -EEXIST, implying that the requested region is
already reserved.

Add corresponding test cases which check for overlapping reservation
requests made through lmb_reserve() and lmb_alloc_addr(). And while
here, fix some of the comments in the test function being touched.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
lib/lmb.c
test/lib/lmb.c