diff mbox series

[v4,38/40] wifi: mac80211: drop locking around ntp_fltr_bmap

Message ID 20240620175703.605111-39-yury.norov@gmail.com (mailing list archive)
State Not Applicable
Delegated to: Netdev Maintainers
Headers show
Series lib/find: add atomic find_bit() primitives | expand

Commit Message

Yury Norov June 20, 2024, 5:57 p.m. UTC
The driver operates on individual bits of the bitmap. Now that we have
atomic find_and_set_bit() helper, we can move the map manipulation out
of ntp_fltr_lock-protected area.

Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
 drivers/net/ethernet/broadcom/bnxt/bnxt.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
index c437ca1c0fd3..5f4c3449570d 100644
--- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c
+++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -51,6 +51,7 @@ 
 #include <linux/bitmap.h>
 #include <linux/cpu_rmap.h>
 #include <linux/cpumask.h>
+#include <linux/find_atomic.h>
 #include <net/pkt_cls.h>
 #include <net/page_pool/helpers.h>
 #include <linux/align.h>
@@ -5616,17 +5617,16 @@  static int bnxt_init_l2_filter(struct bnxt *bp, struct bnxt_l2_filter *fltr,
 			       struct bnxt_l2_key *key, u32 idx)
 {
 	struct hlist_head *head;
+	int bit_id;
 
 	ether_addr_copy(fltr->l2_key.dst_mac_addr, key->dst_mac_addr);
 	fltr->l2_key.vlan = key->vlan;
 	fltr->base.type = BNXT_FLTR_TYPE_L2;
 	if (fltr->base.flags) {
-		int bit_id;
-
-		bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap,
-						 bp->max_fltr, 0);
-		if (bit_id < 0)
+		bit_id = find_and_set_bit(bp->ntp_fltr_bmap, bp->max_fltr);
+		if (bit_id >= bp->max_fltr)
 			return -ENOMEM;
+
 		fltr->base.sw_id = (u16)bit_id;
 		bp->ntp_fltr_count++;
 	}
@@ -14396,13 +14396,11 @@  int bnxt_insert_ntp_filter(struct bnxt *bp, struct bnxt_ntuple_filter *fltr,
 	struct hlist_head *head;
 	int bit_id;
 
-	spin_lock_bh(&bp->ntp_fltr_lock);
-	bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, bp->max_fltr, 0);
-	if (bit_id < 0) {
-		spin_unlock_bh(&bp->ntp_fltr_lock);
+	bit_id = find_and_set_bit(bp->ntp_fltr_bmap, bp->max_fltr);
+	if (bit_id >= bp->max_fltr)
 		return -ENOMEM;
-	}
 
+	spin_lock_bh(&bp->ntp_fltr_lock);
 	fltr->base.sw_id = (u16)bit_id;
 	fltr->base.type = BNXT_FLTR_TYPE_NTUPLE;
 	fltr->base.flags |= BNXT_ACT_RING_DST;