mtd: nand: bbt: Use the bitmap API to allocate bitmaps
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sun, 3 Jul 2022 16:09:45 +0000 (18:09 +0200)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Tue, 20 Sep 2022 08:06:58 +0000 (10:06 +0200)
Use bitmap_zalloc()/bitmap_free() instead of hand-writing them.

It is less verbose and it improves the semantic.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/b18c2b6711b8930f0dfb8318b5d19ef6e41f0f9a.1656864573.git.christophe.jaillet@wanadoo.fr
drivers/mtd/nand/bbt.c

index 64af689..db4f93a 100644 (file)
@@ -24,11 +24,8 @@ int nanddev_bbt_init(struct nand_device *nand)
 {
        unsigned int bits_per_block = fls(NAND_BBT_BLOCK_NUM_STATUS);
        unsigned int nblocks = nanddev_neraseblocks(nand);
-       unsigned int nwords = DIV_ROUND_UP(nblocks * bits_per_block,
-                                          BITS_PER_LONG);
 
-       nand->bbt.cache = kcalloc(nwords, sizeof(*nand->bbt.cache),
-                                 GFP_KERNEL);
+       nand->bbt.cache = bitmap_zalloc(nblocks * bits_per_block, GFP_KERNEL);
        if (!nand->bbt.cache)
                return -ENOMEM;
 
@@ -44,7 +41,7 @@ EXPORT_SYMBOL_GPL(nanddev_bbt_init);
  */
 void nanddev_bbt_cleanup(struct nand_device *nand)
 {
-       kfree(nand->bbt.cache);
+       bitmap_free(nand->bbt.cache);
 }
 EXPORT_SYMBOL_GPL(nanddev_bbt_cleanup);