OSDN Git Service

cxl: Use the bitmap API to allocate bitmaps
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Mon, 11 Jul 2022 19:14:38 +0000 (21:14 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 14 Jul 2022 14:53:52 +0000 (16:53 +0200)
Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.

It is less verbose and it improves the semantic.

Acked-by: Andrew Donnellan <ajd@linux.ibm.com>
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Link: https://lore.kernel.org/r/59010cc7c62443030c69cb1ce0b2b62c5d47e064.1657566849.git.christophe.jaillet@wanadoo.fr
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/misc/cxl/context.c
drivers/misc/cxl/guest.c
drivers/misc/cxl/irq.c
drivers/misc/cxl/of.c

index e627b40..acaa448 100644 (file)
@@ -331,7 +331,7 @@ static void reclaim_ctx(struct rcu_head *rcu)
                __free_page(ctx->ff_page);
        ctx->sstp = NULL;
 
-       kfree(ctx->irq_bitmap);
+       bitmap_free(ctx->irq_bitmap);
 
        /* Drop ref to the afu device taken during cxl_context_init */
        cxl_afu_put(ctx->afu);
index 3321c01..375f692 100644 (file)
@@ -1053,7 +1053,7 @@ static void free_adapter(struct cxl *adapter)
                if (adapter->guest->irq_avail) {
                        for (i = 0; i < adapter->guest->irq_nranges; i++) {
                                cur = &adapter->guest->irq_avail[i];
-                               kfree(cur->bitmap);
+                               bitmap_free(cur->bitmap);
                        }
                        kfree(adapter->guest->irq_avail);
                }
index 5f0e2dc..0ce91d9 100644 (file)
@@ -319,8 +319,7 @@ int afu_allocate_irqs(struct cxl_context *ctx, u32 count)
        }
 
        ctx->irq_count = count;
-       ctx->irq_bitmap = kcalloc(BITS_TO_LONGS(count),
-                                 sizeof(*ctx->irq_bitmap), GFP_KERNEL);
+       ctx->irq_bitmap = bitmap_zalloc(count, GFP_KERNEL);
        if (!ctx->irq_bitmap)
                goto out;
 
index 1cfecba..25ce725 100644 (file)
@@ -308,8 +308,7 @@ static int read_adapter_irq_config(struct cxl *adapter, struct device_node *np)
                cur = &adapter->guest->irq_avail[i];
                cur->offset = be32_to_cpu(ranges[i * 2]);
                cur->range  = be32_to_cpu(ranges[i * 2 + 1]);
-               cur->bitmap = kcalloc(BITS_TO_LONGS(cur->range),
-                               sizeof(*cur->bitmap), GFP_KERNEL);
+               cur->bitmap = bitmap_zalloc(cur->range, GFP_KERNEL);
                if (cur->bitmap == NULL)
                        goto err;
                if (cur->offset < adapter->guest->irq_base_offset)
@@ -326,7 +325,7 @@ static int read_adapter_irq_config(struct cxl *adapter, struct device_node *np)
 err:
        for (i--; i >= 0; i--) {
                cur = &adapter->guest->irq_avail[i];
-               kfree(cur->bitmap);
+               bitmap_free(cur->bitmap);
        }
        kfree(adapter->guest->irq_avail);
        adapter->guest->irq_avail = NULL;