mwifiex_clean_auto_tdls() clears auto_tdls_timer_active and deletes the timer, but the callback may already be past that check and rearm the timer with mod_timer() before it returns. timer_delete() does not wait for a running callback, so the timer survives the cleanup. The mwifiex_private structure is freed later by mwifiex_uninit_sw(), and a timer that fires after that dereferences the freed structure in timer_container_of() at the top of mwifiex_check_auto_tdls(). Use timer_shutdown_sync(), which waits for a running callback and prevents the rearm. A reconnect sets the timer up again with timer_setup() in mwifiex_setup_auto_tdls_timer(), which restores the callback, so the timer is not lost for the next association. The cleanup also has to happen when the interface is no longer a station. The feature flags and priv->bss_type are re-read on every call, so a bss_type change while the timer is armed skips the cleanup entirely and leaves the timer running past the interface teardown. Key the timer shutdown on auto_tdls_timer_active instead, which is set only by mwifiex_setup_auto_tdls_timer() and cleared here, so the timer is stopped exactly when it was started. The peer list is independent of the timer and is flushed unconditionally: mwifiex_add_auto_tdls_peer() appends to it whenever adapter->auto_tdls is set, whether or not this interface ever armed the timer, so guarding the whole cleanup on the timer state would leave list entries behind. Fixes: 9927baa3c724 ("mwifiex: add auto TDLS support") Signed-off-by: Yaohan Li --- Prepared against v7.4-rc1-1969-g666539eecdf4. AI assistance: the analysis, the change and its review notes were prepared with Claude (Anthropic) as a coding assistant. The author reviewed the reasoning and takes responsibility for the content. Testing: compile tested only (arm64, gcc 11.4). No mwifiex hardware was available, so the disconnect/unbind race was not run. drivers/net/wireless/marvell/mwifiex/tdls.c | 26 +++++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/tdls.c b/drivers/net/wireless/marvell/mwifiex/tdls.c index c71ffe8399e4..99948db5bbdf 100644 --- a/drivers/net/wireless/marvell/mwifiex/tdls.c +++ b/drivers/net/wireless/marvell/mwifiex/tdls.c @@ -1483,13 +1483,29 @@ void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv) void mwifiex_clean_auto_tdls(struct mwifiex_private *priv) { - if (ISSUPP_TDLS_ENABLED(priv->adapter->fw_cap_info) && - priv->adapter->auto_tdls && - priv->bss_type == MWIFIEX_BSS_TYPE_STA) { + /* + * The timer itself records whether this interface set it up: the + * feature flags and bss_type are re-read on every call and can have + * changed since the association that armed the timer. + */ + if (priv->auto_tdls_timer_active) { priv->auto_tdls_timer_active = false; - timer_delete(&priv->auto_tdls_timer); - mwifiex_flush_auto_tdls_list(priv); + + /* + * timer_delete() does not wait for a callback that is + * already running, and that callback rearms the timer when + * it finishes; timer_shutdown_sync() waits for it and + * prevents the rearm. + */ + timer_shutdown_sync(&priv->auto_tdls_timer); } + + /* + * The peer list does not depend on the timer: entries are added + * whenever adapter->auto_tdls is set, so it has to be flushed even + * when this interface never armed the timer. + */ + mwifiex_flush_auto_tdls_list(priv); } static int mwifiex_config_tdls(struct mwifiex_private *priv, u8 enable) -- 2.34.1