From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tom Rini Date: Sat, 15 Dec 2018 10:10:58 -0500 Subject: [U-Boot] [PATCH v6 3/9] lib: lmb: reserving overlapping regions should fail In-Reply-To: <20181214201357.26316-4-simon.k.r.goldschmidt@gmail.com> References: <20181214201357.26316-1-simon.k.r.goldschmidt@gmail.com> <20181214201357.26316-4-simon.k.r.goldschmidt@gmail.com> Message-ID: <20181215151058.GV8702@bill-the-cat> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Fri, Dec 14, 2018 at 09:13:51PM +0100, Simon Goldschmidt wrote: > lmb_add_region handles overlapping regions wrong: instead of merging > or rejecting to add a new reserved region that overlaps an existing > one, it just adds the new region. > > Since internally the same function is used for lmb_alloc, change > lmb_add_region to reject overlapping regions. > > Also, to keep reserved memory correct after 'free', reserved entries > created by allocating memory must not set their size to a multiple > of alignment but to the original size. This ensures the reserved > region is completely removed when the caller calls 'lmb_free', as > this one takes the same size as passed to 'lmb_alloc' etc. > > Add test to assert this. > > Signed-off-by: Simon Goldschmidt [snip] > + if (alloc_size == alloc_size_aligned) > + ASSERT_LMB(&lmb, ram, ram_size, 1, ram + ram_size - > + (alloc_size_aligned * 2), alloc_size * 2, 0, 0, 0, > + 0); > + else > + ASSERT_LMB(&lmb, ram, ram_size, 2, ram + ram_size - > + (alloc_size_aligned * 2), alloc_size, ram + ram_size > + - alloc_size_aligned, alloc_size, 0, 0); I've fixed this inline for testing but, we need braces with this if/else as I guess due to all of the macro expansion it's more than one line and both gcc and clang fail. -- Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: