[PATCH v2 1/1] wifi: mac80211: don't coalesce a new ROC onto an expired one

From
James-LY Huang <hidden>
Date
2026-11-10 12:34:07
Also in
linux-mediatek
Reply to
James-LY Huang, 2026-11-10
From: james-ly huang <redacted>

ieee80211_coalesce_hw_started_roc() computes the time the running
ROC has left with an unsigned subtraction of 'now' from its end
time. When the running ROC has already expired, the subtraction
wraps around, the check whether the new request still fits into
the remaining time passes, and the new request is coalesced onto
a ROC that has already delivered its events: the new ROC is never
started, and the cookie handed to userspace never expires.

That state is not unusual: a driver usually processes
ieee80211_remain_on_channel_expired() in a work item, so until
that work runs an expired ROC is still on the list with
started=true. A remain-on-channel or off-channel mgmt-TX request
issued in that window hits exactly this path.

Track the end time of the running ROC explicitly and refuse to
coalesce once it has passed. The remaining window computed from
that end time is then guaranteed to be positive.

Signed-off-by: james-ly huang <redacted>
---
v2: rewrite commit message and comment
---
 net/mac80211/offchannel.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/net/mac80211/offchannel.c b/net/mac80211/offchannel.c
index 44808120ff51..e54425d87b08 100644
--- a/net/mac80211/offchannel.c
+++ b/net/mac80211/offchannel.c
@@ -529,7 +529,7 @@ ieee80211_coalesce_hw_started_roc(struct ieee80211_local *local,
 				  struct ieee80211_roc_work *cur_roc)
 {
 	unsigned long now = jiffies;
-	unsigned long remaining;
+	unsigned long end;
 
 	if (WARN_ON(!cur_roc->started))
 		return false;
@@ -540,12 +540,19 @@ ieee80211_coalesce_hw_started_roc(struct ieee80211_local *local,
 	if (!cur_roc->hw_begun && new_roc->duration > cur_roc->duration)
 		return false;
 
-	remaining = cur_roc->start_time +
-		    msecs_to_jiffies(cur_roc->duration) -
-		    now;
+	end = cur_roc->start_time + msecs_to_jiffies(cur_roc->duration);
+
+	/* the current ROC may already be over: drivers handle its
+	 * expiry in a work item, so until that work runs it is
+	 * still listed here with started set and no time left -
+	 * coalescing onto it would leave the new request queued
+	 * behind a ROC that produces no more events
+	 */
+	if (time_after_eq(now, end))
+		return false;
 
 	/* if it doesn't fit entirely, schedule a new one */
-	if (new_roc->duration > jiffies_to_msecs(remaining))
+	if (new_roc->duration > jiffies_to_msecs(end - now))
 		return false;
 
 	/* add just after the current one so we combine their finish later */
-- 
2.45.2
Thread (2 messages) 2 messages, 1 author, last reply 8d ago
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help