Skip to contentSkip to conversation

wifi: brcmsmac: use FAM for debug code

PATCH Superseded Rosen Penev 2 participants 2 messages Feb 23 – Mar 9 Broadcom BRCM80211 IEEE802.11 wireless drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wifi: brcmsmac: use FAM for debug code

Debug code requires a separate allocation to duplicate a string. A FAM allows properly sized allocation with a single kfree.

---
 .../broadcom/brcm80211/brcmsmac/mac80211_if.c     | 15 +++++----------
 .../broadcom/brcm80211/brcmsmac/mac80211_if.h     |  2 +-
 2 files changed, 6 insertions(+), 11 deletions(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.c +5 -10
index aadcff1e2b5d..87b636273b3f 100644
@@ -317,9 +317,6 @@ static void brcms_free(struct brcms_info *wl)
 	/* free timers */
 	for (t = wl->timers; t; t = next) {
 		next = t->next;
-#ifdef DEBUG
-		kfree(t->name);
-#endif
 		kfree(t);
 	}
 }
@@ -1499,7 +1496,11 @@ struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
 {
 	struct brcms_timer *t;
 
+#ifdef DEBUG
+	t = kzalloc(struct_size(t, name, strlen(name) + 1), GFP_ATOMIC);
+#else
 	t = kzalloc(sizeof(*t), GFP_ATOMIC);
+#endif
 	if (!t)
 		return NULL;
 
@@ -1511,7 +1512,7 @@ struct brcms_timer *brcms_init_timer(struct brcms_info *wl,
 	wl->timers = t;
 
 #ifdef DEBUG
-	t->name = kstrdup(name, GFP_ATOMIC);
+	strcpy(t->name, name);
 #endif
 
 	return t;
@@ -1574,9 +1575,6 @@ void brcms_free_timer(struct brcms_timer *t)
 
 	if (wl->timers == t) {
 		wl->timers = wl->timers->next;
-#ifdef DEBUG
-		kfree(t->name);
-#endif
 		kfree(t);
 		return;
 
@@ -1586,9 +1584,6 @@ void brcms_free_timer(struct brcms_timer *t)
 	while (tmp) {
 		if (tmp->next == t) {
 			tmp->next = t->next;
-#ifdef DEBUG
-			kfree(t->name);
-#endif
 			kfree(t);
 			return;
 		}
drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.h +1 -1
index eaf926a96a88..8ef6d657e487 100644
@@ -43,7 +43,7 @@ struct brcms_timer {
 	bool set;		/* indicates if timer is active */
 	struct brcms_timer *next;	/* for freeing on unload */
 #ifdef DEBUG
-	char *name;		/* Description of the timer */
+	char name[];		/* Description of the timer */
 #endif
 };
 

--
2.53.0

#1 lore raw

drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.h struct brcms_timer { · line 48

Quoted 10 lines · Rosen Penev

+++ b/drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.h

drivers/net/wireless/broadcom/brcm80211/brcmsmac/mac80211_if.h +1 -1
@@ -43,7 +43,7 @@ struct brcms_timer {
 	bool set;		/* indicates if timer is active */
 	struct brcms_timer *next;	/* for freeing on unload */
 #ifdef DEBUG
-	char *name;		/* Description of the timer */
+	char name[];		/* Description of the timer */
 #endif
 

Might be better to remove that ifdef too, if only to have cleaner code and get errors when someone tries to add something after it in non-debug builds?

johannes