]> git.ozlabs.org Git - ccan/blobdiff - ccan/alloc/alloc.c
alloc: dont clash with libc's fls, avoid void pointer arithmetic
[ccan] / ccan / alloc / alloc.c
index 643efedc85d1be3212e175051e3558def8021545..181f6302f458540d6549560954d41a76e204b2aa 100644 (file)
@@ -124,7 +124,7 @@ static unsigned long bucket_to_size(unsigned int bucket)
  */
 static unsigned int size_to_bucket(unsigned long size)
 {
-       unsigned int base = fls(size/2);
+       unsigned int base = afls(size/2);
        unsigned long overshoot;
 
        overshoot = size - (1UL << base);
@@ -134,7 +134,7 @@ static unsigned int size_to_bucket(unsigned long size)
 
 static unsigned int small_page_bits(unsigned long poolsize)
 {
-       return fls(poolsize / MAX_SMALL_PAGES - 1);
+       return afls(poolsize / MAX_SMALL_PAGES - 1);
 }
 
 static struct page_header *from_pgnum(struct header *head,
@@ -313,7 +313,7 @@ static unsigned int find_free_bit(const unsigned long bitmap[])
        unsigned int i;
 
        for (i = 0; bitmap[i] == -1UL; i++);
-       return (i*BITS_PER_LONG) + ffsl(~bitmap[i]) - 1;
+       return (i*BITS_PER_LONG) + affsl(~bitmap[i]) - 1;
 }
 
 /* How many elements can we fit in a page? */
@@ -422,7 +422,8 @@ static void del_large_from_small_free_list(struct header *head,
 
        for (i = 0; i < SMALL_PAGES_PER_LARGE_PAGE; i++) {
                del_from_list(head, &head->small_free_list,
-                             (void *)ph + (i << sp_bits),
+                             (struct page_header *)((char *)ph
+                                                    + (i << sp_bits)),
                              sp_bits);
        }
 }
@@ -467,9 +468,7 @@ static void recombine_small_pages(struct header *head, unsigned long poolsize,
 static u16 get_large_page(struct header *head, unsigned long poolsize,
                          unsigned int sp_bits)
 {
-       unsigned int lp_bits, page;
-
-       lp_bits = sp_bits + BITS_FROM_SMALL_TO_LARGE_PAGE;
+       unsigned int page;
 
        page = pop_from_list(head, &head->large_free_list, sp_bits);
        if (likely(page))
@@ -527,9 +526,8 @@ static bool huge_allocated(struct header *head, unsigned long offset)
 }
 
 /* They want something really big.  Aim for contiguous pages (slow). */
-static COLD_ATTRIBUTE
-void *huge_alloc(void *pool, unsigned long poolsize,
-                unsigned long size, unsigned long align)
+static COLD void *huge_alloc(void *pool, unsigned long poolsize,
+                            unsigned long size, unsigned long align)
 {
        struct header *head = pool;
        struct huge_alloc *ha;
@@ -647,7 +645,7 @@ done:
        return (char *)pool + ha->off;
 }
 
-static COLD_ATTRIBUTE void
+static COLD void
 huge_free(struct header *head, unsigned long poolsize, void *free)
 {
        unsigned long i, off, pgnum, free_off = (char *)free - (char *)head;
@@ -687,8 +685,7 @@ huge_free(struct header *head, unsigned long poolsize, void *free)
        alloc_free(head, poolsize, ha);
 }
 
-static COLD_ATTRIBUTE unsigned long
-huge_size(struct header *head, void *p)
+static COLD unsigned long huge_size(struct header *head, void *p)
 {
        unsigned long i, off = (char *)p - (char *)head;
        struct huge_alloc *ha;