Search Linux Wireless

[PATCH] wifi: brcmfmac: use generic lists to manage TDLS entries

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Prefer generic lists over ad-hoc quirks to manage TDLS
entries, adjust related code.

Signed-off-by: Dmitry Antipov <dmantipov@xxxxxxxxx>
---
 .../broadcom/brcm80211/brcmfmac/flowring.c    | 69 ++++++-------------
 .../broadcom/brcm80211/brcmfmac/flowring.h    |  4 +-
 2 files changed, 22 insertions(+), 51 deletions(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
index e1127d7e086d..acd3a7b5231d 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.c
@@ -44,13 +44,9 @@ brcmf_flowring_is_tdls_mac(struct brcmf_flowring *flow, u8 mac[ETH_ALEN])
 {
 	struct brcmf_flowring_tdls_entry *search;
 
-	search = flow->tdls_entry;
-
-	while (search) {
+	list_for_each_entry(search, &flow->tdls_entries, list)
 		if (memcmp(search->mac, mac, ETH_ALEN) == 0)
 			return true;
-		search = search->next;
-	}
 
 	return false;
 }
@@ -365,6 +361,7 @@ struct brcmf_flowring *brcmf_flowring_attach(struct device *dev, u16 nrofrings)
 		flow->dev = dev;
 		flow->nrofrings = nrofrings;
 		spin_lock_init(&flow->block_lock);
+		INIT_LIST_HEAD(&flow->tdls_entries);
 		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++)
@@ -385,8 +382,7 @@ void brcmf_flowring_detach(struct brcmf_flowring *flow)
 {
 	struct brcmf_bus *bus_if = dev_get_drvdata(flow->dev);
 	struct brcmf_pub *drvr = bus_if->drvr;
-	struct brcmf_flowring_tdls_entry *search;
-	struct brcmf_flowring_tdls_entry *remove;
+	struct brcmf_flowring_tdls_entry *remove, *tmp;
 	u16 flowid;
 
 	for (flowid = 0; flowid < flow->nrofrings; flowid++) {
@@ -394,12 +390,11 @@ void brcmf_flowring_detach(struct brcmf_flowring *flow)
 			brcmf_msgbuf_delete_flowring(drvr, flowid);
 	}
 
-	search = flow->tdls_entry;
-	while (search) {
-		remove = search;
-		search = search->next;
+	list_for_each_entry_safe(remove, tmp, &flow->tdls_entries, list) {
+		list_del(&remove->list);
 		kfree(remove);
 	}
+
 	kfree(flow->rings);
 	kfree(flow);
 }
@@ -433,24 +428,19 @@ void brcmf_flowring_delete_peer(struct brcmf_flowring *flow, int ifidx,
 	struct brcmf_bus *bus_if = dev_get_drvdata(flow->dev);
 	struct brcmf_pub *drvr = bus_if->drvr;
 	struct brcmf_flowring_hash *hash;
-	struct brcmf_flowring_tdls_entry *prev;
-	struct brcmf_flowring_tdls_entry *search;
+	struct brcmf_flowring_tdls_entry *search = NULL, *tmp;
 	u32 i;
 	u16 flowid;
 	bool sta;
 
 	sta = (flow->addr_mode[ifidx] == ADDR_INDIRECT);
 
-	search = flow->tdls_entry;
-	prev = NULL;
-	while (search) {
-		if (memcmp(search->mac, peer, ETH_ALEN) == 0) {
+	list_for_each_entry(tmp, &flow->tdls_entries, list)
+		if (memcmp(tmp->mac, peer, ETH_ALEN) == 0) {
+			search = tmp;
 			sta = false;
 			break;
 		}
-		prev = search;
-		search = search->next;
-	}
 
 	hash = flow->hash;
 	for (i = 0; i < BRCMF_FLOWRING_HASHSIZE; i++) {
@@ -463,12 +453,9 @@ void brcmf_flowring_delete_peer(struct brcmf_flowring *flow, int ifidx,
 	}
 
 	if (search) {
-		if (prev)
-			prev->next = search->next;
-		else
-			flow->tdls_entry = search->next;
+		list_del(&search->list);
 		kfree(search);
-		if (flow->tdls_entry == NULL)
+		if (list_empty(&flow->tdls_entries))
 			flow->tdls_active = false;
 	}
 }
@@ -478,31 +465,15 @@ void brcmf_flowring_add_tdls_peer(struct brcmf_flowring *flow, int ifidx,
 				  u8 peer[ETH_ALEN])
 {
 	struct brcmf_flowring_tdls_entry *tdls_entry;
-	struct brcmf_flowring_tdls_entry *search;
 
-	tdls_entry = kzalloc(sizeof(*tdls_entry), GFP_ATOMIC);
-	if (tdls_entry == NULL)
-		return;
+	list_for_each_entry(tdls_entry, &flow->tdls_entries, list)
+		if (memcmp(tdls_entry->mac, peer, ETH_ALEN) == 0)
+			return;
 
-	memcpy(tdls_entry->mac, peer, ETH_ALEN);
-	tdls_entry->next = NULL;
-	if (flow->tdls_entry == NULL) {
-		flow->tdls_entry = tdls_entry;
-	} else {
-		search = flow->tdls_entry;
-		if (memcmp(search->mac, peer, ETH_ALEN) == 0)
-			goto free_entry;
-		while (search->next) {
-			search = search->next;
-			if (memcmp(search->mac, peer, ETH_ALEN) == 0)
-				goto free_entry;
-		}
-		search->next = tdls_entry;
+	tdls_entry = kzalloc(sizeof(*tdls_entry), GFP_ATOMIC);
+	if (tdls_entry) {
+		memcpy(tdls_entry->mac, peer, ETH_ALEN);
+		list_add_tail(&tdls_entry->list, &flow->tdls_entries);
+		flow->tdls_active = true;
 	}
-
-	flow->tdls_active = true;
-	return;
-
-free_entry:
-	kfree(tdls_entry);
 }
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.h
index 818882b0fd01..e7bfb5495aaf 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/flowring.h
@@ -32,7 +32,7 @@ struct brcmf_flowring_ring {
 
 struct brcmf_flowring_tdls_entry {
 	u8 mac[ETH_ALEN];
-	struct brcmf_flowring_tdls_entry *next;
+	struct list_head list;
 };
 
 struct brcmf_flowring {
@@ -43,7 +43,7 @@ struct brcmf_flowring {
 	enum proto_addr_mode addr_mode[BRCMF_MAX_IFS];
 	u16 nrofrings;
 	bool tdls_active;
-	struct brcmf_flowring_tdls_entry *tdls_entry;
+	struct list_head tdls_entries;
 };
 
 
-- 
2.41.0




[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Wireless Personal Area Network]     [Linux Bluetooth]     [Wireless Regulations]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite Hiking]     [MIPS Linux]     [ARM Linux]     [Linux RAID]

  Powered by Linux