pkarashchenko commented on code in PR #7618: URL: https://github.com/apache/incubator-nuttx/pull/7618#discussion_r1026479288
########## mm/mm_gran/mm_granmark.c: ########## @@ -75,35 +77,49 @@ void gran_mark_allocated(FAR struct gran_s *priv, uintptr_t alloc, avail = 32 - gatbit; if (ngranules > avail) { - /* Mark bits in the first GAT entry */ + uint32_t gatmask2; - gatmask = 0xffffffff << gatbit; - DEBUGASSERT((priv->gat[gatidx] & gatmask) == 0); - - priv->gat[gatidx] |= gatmask; + gatmask = 0xffffffff << gatbit; ngranules -= avail; + gatmask2 = 0xffffffff >> (32 - ngranules); + + /* Check that the area is free, from both mask words */ - /* Mark bits in the second GAT entry */ + if (((priv->gat[gatidx] & gatmask) != 0) || + ((priv->gat[gatidx + 1] & gatmask2) != 0)) + { + ret = -ENOMEM; + goto err_nomem; + } - gatmask = 0xffffffff >> (32 - ngranules); - DEBUGASSERT((priv->gat[gatidx + 1] & gatmask) == 0); + /* Mark bits in the first and second GAT entry */ - priv->gat[gatidx + 1] |= gatmask; + priv->gat[gatidx] |= gatmask; + priv->gat[gatidx + 1] |= gatmask2; Review Comment: Anything that avoids unnecessary goto works for me. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org