Skip to contentSkip to conversation

wifi: brcmfmac: flowring: simplify flow allocation

PATCH In review Rosen Penev 2 participants 2 messages Jun 8 – Jun 9 Broadcom BRCM80211 IEEE802.11 wireless drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: brcmfmac: flowring: simplify flow allocation

Use a flexible array member and kzalloc_flex to combine allocations. Simplifies code slightly.

Add __counted_by for extra runtime analysis.

---
 .../wireless/broadcom/brcm80211/brcmfmac/flowring.c    | 10 ++--------
 .../wireless/broadcom/brcm80211/brcmfmac/flowring.h    |  2 +-
 2 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c +2 -8
index df7e3bee19f2..35cbcea0abc9 100644
@@ -360,20 +360,15 @@ struct brcmf_flowring *brcmf_flowring_attach(struct device *dev, u16 nrofrings)
 	struct brcmf_flowring *flow;
 	u32 i;
 
-	flow = kzalloc_obj(*flow);
+	flow = kzalloc_flex(*flow, rings, nrofrings);
 	if (flow) {
-		flow->dev = dev;
 		flow->nrofrings = nrofrings;
+		flow->dev = dev;
 		spin_lock_init(&flow->block_lock);
 		for (i = 0; i < ARRAY_SIZE(flow->addr_mode); i++)
 			flow->addr_mode[i] = ADDR_INDIRECT;
 		for (i = 0; i < ARRAY_SIZE(flow->hash); i++)
 			flow->hash[i].ifidx = BRCMF_FLOWRING_INVALID_IFIDX;
-		flow->rings = kzalloc_objs(*flow->rings, nrofrings);
-		if (!flow->rings) {
-			kfree(flow);
-			flow = NULL;
-		}
 	}
 
 	return flow;
@@ -399,7 +394,6 @@ void brcmf_flowring_detach(struct brcmf_flowring *flow)
 		search = search->next;
 		kfree(remove);
 	}
-	kfree(flow->rings);
 	kfree(flow);
 }
 
drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.h +1 -1
index 818882b0fd01..f3d511f9a3c9 100644
@@ -38,12 +38,12 @@ struct brcmf_flowring_tdls_entry {
 struct brcmf_flowring {
 	struct device *dev;
 	struct brcmf_flowring_hash hash[BRCMF_FLOWRING_HASHSIZE];
-	struct brcmf_flowring_ring **rings;
 	spinlock_t block_lock;
 	enum proto_addr_mode addr_mode[BRCMF_MAX_IFS];
 	u16 nrofrings;
 	bool tdls_active;
 	struct brcmf_flowring_tdls_entry *tdls_entry;
+	struct brcmf_flowring_ring *rings[] __counted_by(nrofrings);
 };
 
 

--
2.54.0

maintainer Acked-by on v1 1/1
#1 lore raw

Op 8 juni 2026 07:11:22 schreef Rosen Penev <[email protected]>:

Quoted 4 lines

Use a flexible array member and kzalloc_flex to combine allocations. Simplifies code slightly.

Add __counted_by for extra runtime analysis.

Quoted 5 lines

---
.../wireless/broadcom/brcm80211/brcmfmac/flowring.c | 10 ++--------
.../wireless/broadcom/brcm80211/brcmfmac/flowring.h | 2 +-

2 files changed, 3 insertions(+), 9 deletions(-)