[PATCH] habanalabs: Use the bitmap API to allocate bitmaps

Christophe JAILLET posted 1 patch 3 years, 9 months ago
drivers/misc/habanalabs/common/asid.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
[PATCH] habanalabs: Use the bitmap API to allocate bitmaps
Posted by Christophe JAILLET 3 years, 9 months ago
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>
---
 drivers/misc/habanalabs/common/asid.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/misc/habanalabs/common/asid.c b/drivers/misc/habanalabs/common/asid.c
index ede04c032b6e..c9c2619cc43d 100644
--- a/drivers/misc/habanalabs/common/asid.c
+++ b/drivers/misc/habanalabs/common/asid.c
@@ -11,8 +11,7 @@
 
 int hl_asid_init(struct hl_device *hdev)
 {
-	hdev->asid_bitmap = kcalloc(BITS_TO_LONGS(hdev->asic_prop.max_asid),
-					sizeof(*hdev->asid_bitmap), GFP_KERNEL);
+	hdev->asid_bitmap = bitmap_zalloc(hdev->asic_prop.max_asid, GFP_KERNEL);
 	if (!hdev->asid_bitmap)
 		return -ENOMEM;
 
@@ -27,7 +26,7 @@ int hl_asid_init(struct hl_device *hdev)
 void hl_asid_fini(struct hl_device *hdev)
 {
 	mutex_destroy(&hdev->asid_mutex);
-	kfree(hdev->asid_bitmap);
+	bitmap_free(hdev->asid_bitmap);
 }
 
 unsigned long hl_asid_alloc(struct hl_device *hdev)
-- 
2.34.1
Re: [PATCH] habanalabs: Use the bitmap API to allocate bitmaps
Posted by Oded Gabbay 3 years, 9 months ago
On Sun, Jul 3, 2022 at 11:36 PM Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> 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>
> ---
>  drivers/misc/habanalabs/common/asid.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/misc/habanalabs/common/asid.c b/drivers/misc/habanalabs/common/asid.c
> index ede04c032b6e..c9c2619cc43d 100644
> --- a/drivers/misc/habanalabs/common/asid.c
> +++ b/drivers/misc/habanalabs/common/asid.c
> @@ -11,8 +11,7 @@
>
>  int hl_asid_init(struct hl_device *hdev)
>  {
> -       hdev->asid_bitmap = kcalloc(BITS_TO_LONGS(hdev->asic_prop.max_asid),
> -                                       sizeof(*hdev->asid_bitmap), GFP_KERNEL);
> +       hdev->asid_bitmap = bitmap_zalloc(hdev->asic_prop.max_asid, GFP_KERNEL);
>         if (!hdev->asid_bitmap)
>                 return -ENOMEM;
>
> @@ -27,7 +26,7 @@ int hl_asid_init(struct hl_device *hdev)
>  void hl_asid_fini(struct hl_device *hdev)
>  {
>         mutex_destroy(&hdev->asid_mutex);
> -       kfree(hdev->asid_bitmap);
> +       bitmap_free(hdev->asid_bitmap);
>  }
>
>  unsigned long hl_asid_alloc(struct hl_device *hdev)
> --
> 2.34.1
>

Thanks!
This patch is
Reviewed-by: Oded Gabbay <ogabbay@kernel.org>
Applied to -next.
Oded