mm/gran: Fix GRAN_ALIGNED() macro

GRAN_ALIGNED should check that the memory block's alignment (log2align)
is correct, not that the memory block is aligned with the granule size.

This fixes DEBUGASSERT() in mm_granfree:
_assert: Assertion failed : at file: mm_gran/mm_granfree.c:49

The assertion triggers if granule size != alignment.
This commit is contained in:
Ville Juven 2024-06-03 13:08:37 +03:00 committed by Xiang Xiao
parent 39e6e25565
commit 36cafbb37f
3 changed files with 4 additions and 1 deletions

View File

@ -66,6 +66,7 @@
struct gran_s
{
uint8_t log2gran; /* Log base 2 of the size of one granule */
uint8_t log2align; /* Log base 2 of required alignment */
uint16_t ngranules; /* The total number of (aligned) granules in the heap */
#ifdef CONFIG_GRAN_INTR
irqstate_t irqstate; /* For exclusive access to the GAT */

View File

@ -132,6 +132,7 @@ GRAN_HANDLE gran_initialize(FAR void *heapstart, size_t heapsize,
/* Initialize non-zero elements of the granules heap info structure */
priv->log2gran = log2gran;
priv->log2align = log2align;
priv->ngranules = ngranules;
priv->heapstart = alignedstart;

View File

@ -36,7 +36,8 @@
#define MEM2GRAN(g, m) ((((uintptr_t)m) - g->heapstart) >> g->log2gran)
#define GRAN2MEM(g, x) ((((uintptr_t)x) << g->log2gran) + g->heapstart)
#define GRAN_ALIGNED(g, m) ((((uintptr_t)(m)) & GRANMASK(g)) == 0)
#define ALIGNMASK(g) ((1 << g->log2align) - 1)
#define GRAN_ALIGNED(g, m) ((((uintptr_t)(m)) & ALIGNMASK(g)) == 0)
#define GRAN_INRANGE(g, m) (g->heapstart <= (uintptr_t)(m) && \
(uintptr_t)(m) < GRANENDA(g))
#define GRAN_PRODUCT(g, m) (GRAN_ALIGNED(g, m) && GRAN_INRANGE(g, m))