diff mbox series

[2/2] RDMA/rxe: Use 'bitmap_zalloc()' when applicable

Message ID 4a3e11d45865678d570333d1962820eb13168848.1635093628.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show
Series [1/2] RDMA/rxe: Save a few bytes from struct rxe_pool | expand

Commit Message

Christophe JAILLET Oct. 24, 2021, 4:43 p.m. UTC
'index.table' is a bitmap. So use 'bitmap_zalloc()' to simplify code,
improve the semantic and avoid some open-coded arithmetic in allocator
arguments.

Using 'bitmap_zalloc()' also allows the removal of a now useless
'bitmap_zero()'.

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

Finally, while at it, axe the useless 'bitmap' variable and use
'mem->bitmap' directly.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/infiniband/sw/rxe/rxe_pool.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

Comments

Christophe JAILLET Oct. 24, 2021, 5:30 p.m. UTC | #1
Le 24/10/2021 à 18:43, Christophe JAILLET a écrit :
> 'index.table' is a bitmap. So use 'bitmap_zalloc()' to simplify code,
> improve the semantic and avoid some open-coded arithmetic in allocator
> arguments.
> 
> Using 'bitmap_zalloc()' also allows the removal of a now useless
> 'bitmap_zero()'.
> 
> Also change the corresponding 'kfree()' into 'bitmap_free()' to keep
> consistency.
> 
> Finally, while at it, axe the useless 'bitmap' variable and use
> 'mem->bitmap' directly.

This last sentence should not be there (cut'n'paste error)
It should be removed when the patch is applied, or I can resend if needed.

CJ

> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
>   drivers/infiniband/sw/rxe/rxe_pool.c | 8 ++------
>   1 file changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
> index 271d4ac0e0aa..ed2427369c2c 100644
> --- a/drivers/infiniband/sw/rxe/rxe_pool.c
> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
> @@ -96,7 +96,6 @@ static inline const char *pool_name(struct rxe_pool *pool)
>   static int rxe_pool_init_index(struct rxe_pool *pool, u32 max, u32 min)
>   {
>   	int err = 0;
> -	size_t size;
>   
>   	if ((max - min + 1) < pool->max_elem) {
>   		pr_warn("not enough indices for max_elem\n");
> @@ -107,15 +106,12 @@ static int rxe_pool_init_index(struct rxe_pool *pool, u32 max, u32 min)
>   	pool->index.max_index = max;
>   	pool->index.min_index = min;
>   
> -	size = BITS_TO_LONGS(max - min + 1) * sizeof(long);
> -	pool->index.table = kmalloc(size, GFP_KERNEL);
> +	pool->index.table = bitmap_zalloc(max - min + 1, GFP_KERNEL);
>   	if (!pool->index.table) {
>   		err = -ENOMEM;
>   		goto out;
>   	}
>   
> -	bitmap_zero(pool->index.table, max - min + 1);
> -
>   out:
>   	return err;
>   }
> @@ -167,7 +163,7 @@ void rxe_pool_cleanup(struct rxe_pool *pool)
>   		pr_warn("%s pool destroyed with unfree'd elem\n",
>   			pool_name(pool));
>   
> -	kfree(pool->index.table);
> +	bitmap_free(pool->index.table);
>   }
>   
>   static u32 alloc_index(struct rxe_pool *pool)
>
diff mbox series

Patch

diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
index 271d4ac0e0aa..ed2427369c2c 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.c
+++ b/drivers/infiniband/sw/rxe/rxe_pool.c
@@ -96,7 +96,6 @@  static inline const char *pool_name(struct rxe_pool *pool)
 static int rxe_pool_init_index(struct rxe_pool *pool, u32 max, u32 min)
 {
 	int err = 0;
-	size_t size;
 
 	if ((max - min + 1) < pool->max_elem) {
 		pr_warn("not enough indices for max_elem\n");
@@ -107,15 +106,12 @@  static int rxe_pool_init_index(struct rxe_pool *pool, u32 max, u32 min)
 	pool->index.max_index = max;
 	pool->index.min_index = min;
 
-	size = BITS_TO_LONGS(max - min + 1) * sizeof(long);
-	pool->index.table = kmalloc(size, GFP_KERNEL);
+	pool->index.table = bitmap_zalloc(max - min + 1, GFP_KERNEL);
 	if (!pool->index.table) {
 		err = -ENOMEM;
 		goto out;
 	}
 
-	bitmap_zero(pool->index.table, max - min + 1);
-
 out:
 	return err;
 }
@@ -167,7 +163,7 @@  void rxe_pool_cleanup(struct rxe_pool *pool)
 		pr_warn("%s pool destroyed with unfree'd elem\n",
 			pool_name(pool));
 
-	kfree(pool->index.table);
+	bitmap_free(pool->index.table);
 }
 
 static u32 alloc_index(struct rxe_pool *pool)