acassis opened a new pull request, #21914:
URL: https://github.com/apache/nuttx/pull/21914

   ## Summary
   
   gran_alloc_align() rounds the start granule up with a mask, which only works 
when the alignment is a power of two:
   
   * An alignment of zero gave a mask of zero, so the allocation was placed at 
granule 0 even when granule 0 was in use, and the same memory was returned 
twice.  A request of one granule returned NULL.
   * An alignment that is not a power of two, for example three granules, 
returned memory that was not aligned.
   
   Check the alignment as mm_memalign() does: zero means no alignment, and an 
alignment that is not a power of two returns NULL.
   
   ## Impact
   
   Improvemet
   
   ## Testing
   
   ```
     Tested on sim:nsh with CONFIG_GRAN, CONFIG_TESTING_GRANTEST and 
CONFIG_DEBUG_ASSERTIONS.
     On upstream/master:
     grantest: reserve one granule:               FAIL (expected 1, got 2)
     grantest: reserve the last granule:          FAIL (expected 15, got -1)
     grantest: reserve, free, allocate the heap:  FAIL (expected 0, got -1)
     grantest: align 0, two granules:             FAIL (expected 2, got 0)
     grantest: align 0, one granule:              FAIL (expected 0, got -1)
     grantest: align 3 granules:                  FAIL (expected -1, got 1)
     grantest: align 4 granules:                  PASS (expected 4, got 4)
     grantest: 6 failed
   
   ```
   
   After this commit the align tests pass


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to