pussuw commented on code in PR #7618: URL: https://github.com/apache/incubator-nuttx/pull/7618#discussion_r1026412994
########## 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; } /* Handle the case where where all of the granules come from one entry */ else { - /* Mark bits in a single GAT entry */ - gatmask = 0xffffffff >> (32 - ngranules); gatmask <<= gatbit; - DEBUGASSERT((priv->gat[gatidx] & gatmask) == 0); + + /* Check that the area is free */ + + if ((priv->gat[gatidx] & gatmask) != 0) + { + ret = -ENOMEM; + goto err_nomem; + } + + /* Mark bits in a single GAT entry */ priv->gat[gatidx] |= gatmask; - return; } + +err_nomem: Review Comment: I had error cleanup here that I ended up removing, I thought it doesn't hurt to leave it like this so it is ready if clean up is needed later, but I can change it to your suggestion as well -- 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