Skip to contentSkip to conversation

RDMA/pvrdma: Use bitmap_zalloc() when applicable

PATCH Applied Christophe JAILLET 2 participants 3 messages Nov 25, 2021 – Nov 29, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 RDMA/pvrdma: Use bitmap_zalloc() when applicable

Use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments.

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

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_doorbell.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_doorbell.c +2 -2
index bf51357ea3aa..21ef3fb39915 100644
@@ -63,7 +63,7 @@ int pvrdma_uar_table_init(struct pvrdma_dev *dev)
 	tbl->max = num;
 	tbl->mask = mask;
 	spin_lock_init(&tbl->lock);
-	tbl->table = kcalloc(BITS_TO_LONGS(num), sizeof(long), GFP_KERNEL);
+	tbl->table = bitmap_zalloc(num, GFP_KERNEL);
 	if (!tbl->table)
 		return -ENOMEM;
 
@@ -77,7 +77,7 @@ void pvrdma_uar_table_cleanup(struct pvrdma_dev *dev)
 {
 	struct pvrdma_id_table *tbl = &dev->uar_table.tbl;
 
-	kfree(tbl->table);
+	bitmap_free(tbl->table);
 }
 
 int pvrdma_uar_alloc(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 2/2 RDMA/pvrdma: Use non-atomic bitmap functions when possible

In 'pvrdma_uar_table_init()', the 'tbl->table' bitmap has just been allocated, so no concurrent accesses can occur.

The other accesses to the 'tbl->table' bitmap are protected by the 'tbl->lock' spinlock, so no concurrent accesses can happen.

So prefer the non-atomic '__[set|clear]_bit()' functions to save a few cycles.

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_doorbell.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/infiniband/hw/vmw_pvrdma/pvrdma_doorbell.c +3 -3
index 21ef3fb39915..9a4de962e947 100644
@@ -68,7 +68,7 @@ int pvrdma_uar_table_init(struct pvrdma_dev *dev)
 		return -ENOMEM;
 
 	/* 0th UAR is taken by the device. */
-	set_bit(0, tbl->table);
+	__set_bit(0, tbl->table);
 
 	return 0;
 }
@@ -100,7 +100,7 @@ int pvrdma_uar_alloc(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar)
 		return -ENOMEM;
 	}
 
-	set_bit(obj, tbl->table);
+	__set_bit(obj, tbl->table);
 	obj |= tbl->top;
 
 	spin_unlock_irqrestore(&tbl->lock, flags);
@@ -120,7 +120,7 @@ void pvrdma_uar_free(struct pvrdma_dev *dev, struct pvrdma_uar_map *uar)
 
 	obj = uar->index & (tbl->max - 1);
 	spin_lock_irqsave(&tbl->lock, flags);
-	clear_bit(obj, tbl->table);
+	__clear_bit(obj, tbl->table);
 	tbl->last = min(tbl->last, obj);
 	tbl->top = (tbl->top + tbl->max) & tbl->mask;
 	spin_unlock_irqrestore(&tbl->lock, flags);
Signature · 1 line
2.30.2
maintainer Applied
#2 lore raw
In reply to Christophe JAILLET
Quoted 10 lines · Christophe JAILLET

Use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments.

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

---
 drivers/infiniband/hw/vmw_pvrdma/pvrdma_doorbell.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Applied to for-next, thanks

Jason