Module: xenomai-3
Branch: stable-3.0.x
Commit: 984d13432547d9cb9283162e3efd6b2224acb2a9
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=984d13432547d9cb9283162e3efd6b2224acb2a9

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Apr 26 11:03:50 2018 +0200

copperplate/heapobj-pshared: fix reservation in allocation bitmap

This is a severe bug which would cause an already reserved page range
to be returned twice in specific situations depending on the bitmap
contents at the time of the second allocation.

---

 lib/copperplate/heapobj-pshared.c |   13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/copperplate/heapobj-pshared.c 
b/lib/copperplate/heapobj-pshared.c
index a3c5484..d4324df 100644
--- a/lib/copperplate/heapobj-pshared.c
+++ b/lib/copperplate/heapobj-pshared.c
@@ -289,8 +289,12 @@ static int reserve_page_range(uint32_t *bitmap, int 
bitwords, int nrpages)
         */
        for (n = 0, seq = 0; n < bitwords; n++) {
                v = bitmap[n];
+               if (v == -1U) {
+                       seq = 0;
+                       continue;
+               }
                b = 0;
-               while (v != -1U) {
+               for (;;) {
                        r = __ctz(v);
                        if (r) {
                                seq += r;
@@ -316,8 +320,11 @@ static int reserve_page_range(uint32_t *bitmap, int 
bitwords, int nrpages)
                         * keep searching for one which is at least
                         * nrpages-bit long.
                         */
-                       if (v == -1U && b < 32)
-                               seq = 0;
+                       if (v == -1U) {
+                               if (b < 32)
+                                       seq = 0;
+                               break;
+                       }
                }
        }
        


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
https://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to