git: 2217448bcc2f - stable/13 - LinuxKPI: 802.11: cleanup lsta better

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Fri, 01 Jul 2022 14:57:48 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=2217448bcc2f8e8d5f5c20ab0b1be4511bf5fd01

commit 2217448bcc2f8e8d5f5c20ab0b1be4511bf5fd01
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-06-26 19:13:00 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-07-01 13:50:03 +0000

    LinuxKPI: 802.11: cleanup lsta better
    
    This changes cleans up lsta from the VIF station list as well as
    deals with freeing the lsta itself so it is not leaked.
    
    lkpi_iv_update_bss() makes this more complicated than it should be
    as we ties more sta state (incl. drv/fw) to the node that net80211
    does not know about.  There is more work to be done detangling this
    now that is better understood.
    
    (cherry picked from commit e24e8103e0e2140751a1b2baf7b68725ca20aaa2)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 29 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 728f732e5a75..522e3c92906f 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -179,9 +179,12 @@ lkpi_lsta_remove(struct lkpi_sta *lsta, struct lkpi_vif *lvif)
 
 	lsta->ni = NULL;
 	ni->ni_drv_data = NULL;
-	ieee80211_free_node(ni);
+	if (ni != NULL)
+		ieee80211_free_node(ni);
+
+	IMPROVE("more from lkpi_ic_node_free() should happen here.");
 
-	IMPROVE("free lsta here?  We won't have a pointer to it from the node anymore.");
+	free(lsta, M_LKPI80211);
 }
 
 static struct lkpi_sta *
@@ -998,12 +1001,15 @@ lkpi_sta_scan_to_auth(struct ieee80211vap *vap, enum ieee80211_state nstate, int
 			goto out;
 		}
 		lsta->ni = ieee80211_ref_node(ni);
-		LKPI_80211_LVIF_LOCK(lvif);
-		TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry);
-		LKPI_80211_LVIF_UNLOCK(lvif);
 	} else {
 		lsta = ni->ni_drv_data;
 	}
+
+	/* Insert the [l]sta into the list of known stations. */
+	LKPI_80211_LVIF_LOCK(lvif);
+	TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry);
+	LKPI_80211_LVIF_UNLOCK(lvif);
+
 	/* Add (or adjust) sta and change state (from NOTEXIST) to NONE. */
 	KASSERT(lsta != NULL, ("%s: ni %p lsta is NULL\n", __func__, ni));
 	KASSERT(lsta->state == IEEE80211_STA_NOTEXIST, ("%s: lsta %p state not "
@@ -2775,7 +2781,6 @@ lkpi_ic_node_init(struct ieee80211_node *ni)
 	struct ieee80211com *ic;
 	struct lkpi_hw *lhw;
 	struct lkpi_sta *lsta;
-	struct lkpi_vif *lvif;
 	int error;
 
 	ic = ni->ni_ic;
@@ -2787,17 +2792,11 @@ lkpi_ic_node_init(struct ieee80211_node *ni)
 			return (error);
 	}
 
-	lvif = VAP_TO_LVIF(ni->ni_vap);
-
 	lsta = ni->ni_drv_data;
 
 	/* Now take the reference before linking it to the table. */
 	lsta->ni = ieee80211_ref_node(ni);
 
-	LKPI_80211_LVIF_LOCK(lvif);
-	TAILQ_INSERT_TAIL(&lvif->lsta_head, lsta, lsta_entry);
-	LKPI_80211_LVIF_UNLOCK(lvif);
-
 	/* XXX-BZ Sync other state over. */
 	IMPROVE();
 
@@ -2847,11 +2846,11 @@ lkpi_ic_node_free(struct ieee80211_node *ni)
 	mtx_destroy(&lsta->txq_mtx);
 
 	/* Remove lsta if added_to_drv. */
-	/* Remove lsta from vif */
-
-	/* remove ref from lsta node... */
 
+	/* Remove lsta from vif */
+	/* Remove ref from lsta node... */
 	/* Free lsta. */
+	lkpi_lsta_remove(lsta, VAP_TO_LVIF(ni->ni_vap));
 
 out:
 	if (lhw->ic_node_free != NULL)