media: s5p-mfc: Use 'bitmap_zalloc()' when applicable
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Sat, 23 Oct 2021 10:10:48 +0000 (11:10 +0100)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Mon, 15 Nov 2021 08:12:02 +0000 (08:12 +0000)
'mfc_dev->mem_bitmap' is a bitmap. So use 'bitmap_zalloc()' to simplify
code and improve the semantic.

Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
consistency.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/media/platform/s5p-mfc/s5p_mfc.c

index fc85e4e..f6732f0 100644 (file)
@@ -1185,7 +1185,6 @@ static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev)
 {
        struct device *dev = &mfc_dev->plat_dev->dev;
        unsigned long mem_size = SZ_4M;
-       unsigned int bitmap_size;
 
        if (IS_ENABLED(CONFIG_DMA_CMA) || exynos_is_iommu_available(dev))
                mem_size = SZ_8M;
@@ -1193,16 +1192,14 @@ static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev)
        if (mfc_mem_size)
                mem_size = memparse(mfc_mem_size, NULL);
 
-       bitmap_size = BITS_TO_LONGS(mem_size >> PAGE_SHIFT) * sizeof(long);
-
-       mfc_dev->mem_bitmap = kzalloc(bitmap_size, GFP_KERNEL);
+       mfc_dev->mem_bitmap = bitmap_zalloc(mem_size >> PAGE_SHIFT, GFP_KERNEL);
        if (!mfc_dev->mem_bitmap)
                return -ENOMEM;
 
        mfc_dev->mem_virt = dma_alloc_coherent(dev, mem_size,
                                               &mfc_dev->mem_base, GFP_KERNEL);
        if (!mfc_dev->mem_virt) {
-               kfree(mfc_dev->mem_bitmap);
+               bitmap_free(mfc_dev->mem_bitmap);
                dev_err(dev, "failed to preallocate %ld MiB for the firmware and context buffers\n",
                        (mem_size / SZ_1M));
                return -ENOMEM;
@@ -1241,7 +1238,7 @@ static void s5p_mfc_unconfigure_common_memory(struct s5p_mfc_dev *mfc_dev)
 
        dma_free_coherent(dev, mfc_dev->mem_size, mfc_dev->mem_virt,
                          mfc_dev->mem_base);
-       kfree(mfc_dev->mem_bitmap);
+       bitmap_free(mfc_dev->mem_bitmap);
        vb2_dma_contig_clear_max_seg_size(dev);
 }