diff mbox series

[1/2] RDMA/rtrs-clt: Use the bitmap API to allocate bitmaps

Message ID ca9c5c8301d76d60de34640568b3db0d4401d050.1657298747.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Headers show
Series [1/2] RDMA/rtrs-clt: Use the bitmap API to allocate bitmaps | expand

Commit Message

Christophe JAILLET July 8, 2022, 4:47 p.m. UTC
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/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Comments

Jinpu Wang July 11, 2022, 10:01 a.m. UTC | #1
On Fri, Jul 8, 2022 at 6:47 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>
Acked-by: Jack Wang <jinpu.wang@ionos.com>
Thx!
> ---
>  drivers/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> index 9809c3883979..06c27a3d83f5 100644
> --- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> +++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
> @@ -1403,8 +1403,7 @@ static int alloc_permits(struct rtrs_clt_sess *clt)
>         unsigned int chunk_bits;
>         int err, i;
>
> -       clt->permits_map = kcalloc(BITS_TO_LONGS(clt->queue_depth),
> -                                  sizeof(long), GFP_KERNEL);
> +       clt->permits_map = bitmap_zalloc(clt->queue_depth, GFP_KERNEL);
>         if (!clt->permits_map) {
>                 err = -ENOMEM;
>                 goto out_err;
> @@ -1426,7 +1425,7 @@ static int alloc_permits(struct rtrs_clt_sess *clt)
>         return 0;
>
>  err_map:
> -       kfree(clt->permits_map);
> +       bitmap_free(clt->permits_map);
>         clt->permits_map = NULL;
>  out_err:
>         return err;
> @@ -1440,7 +1439,7 @@ static void free_permits(struct rtrs_clt_sess *clt)
>                 wait_event(clt->permits_wait,
>                            find_first_bit(clt->permits_map, sz) >= sz);
>         }
> -       kfree(clt->permits_map);
> +       bitmap_free(clt->permits_map);
>         clt->permits_map = NULL;
>         kfree(clt->permits);
>         clt->permits = NULL;
> --
> 2.34.1
>
Leon Romanovsky July 18, 2022, 9:04 a.m. UTC | #2
On Fri, Jul 08, 2022 at 06:47:27PM +0200, Christophe JAILLET 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/infiniband/ulp/rtrs/rtrs-clt.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 

Thanks, applied
diff mbox series

Patch

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-clt.c b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
index 9809c3883979..06c27a3d83f5 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-clt.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-clt.c
@@ -1403,8 +1403,7 @@  static int alloc_permits(struct rtrs_clt_sess *clt)
 	unsigned int chunk_bits;
 	int err, i;
 
-	clt->permits_map = kcalloc(BITS_TO_LONGS(clt->queue_depth),
-				   sizeof(long), GFP_KERNEL);
+	clt->permits_map = bitmap_zalloc(clt->queue_depth, GFP_KERNEL);
 	if (!clt->permits_map) {
 		err = -ENOMEM;
 		goto out_err;
@@ -1426,7 +1425,7 @@  static int alloc_permits(struct rtrs_clt_sess *clt)
 	return 0;
 
 err_map:
-	kfree(clt->permits_map);
+	bitmap_free(clt->permits_map);
 	clt->permits_map = NULL;
 out_err:
 	return err;
@@ -1440,7 +1439,7 @@  static void free_permits(struct rtrs_clt_sess *clt)
 		wait_event(clt->permits_wait,
 			   find_first_bit(clt->permits_map, sz) >= sz);
 	}
-	kfree(clt->permits_map);
+	bitmap_free(clt->permits_map);
 	clt->permits_map = NULL;
 	kfree(clt->permits);
 	clt->permits = NULL;