linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH wireless-next v4 0/3] fix_scan_ap_flag_requirement_during_mlo
@ 2025-08-12  7:23 Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 1/3] wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Aditya Kumar Singh @ 2025-08-12  7:23 UTC (permalink / raw)
  To: Johannes Berg, Aditya Kumar Singh
  Cc: Johannes Berg, linux-wireless, linux-kernel

Patch 1 and 2 are clean ups.
Patch 3 is actually fixing the issue.

---
Changes in v4:
- Rebased on ToT.
- Handled get radio idx callers properly and simplified the logic overall. 
- Link to v3: https://lore.kernel.org/r/20250625-fix_scan_ap_flag_requirement_during_mlo-v3-1-dca408b10ba4@oss.qualcomm.com

Changes in v3:
- Rebased on ToT.
- Fixed hwsim warning issues.
- Link to v2: https://lore.kernel.org/r/20250624-fix_scan_ap_flag_requirement_during_mlo-v2-1-c8067d0ee1f0@oss.qualcomm.com

Changes in v2:
- Rebased on ToT after dependent changes got merged.
- Link to v1: https://lore.kernel.org/r/20250528-fix_scan_ap_flag_requirement_during_mlo-v1-1-35ac0e3a2f7b@oss.qualcomm.com

---
Aditya Kumar Singh (3):
      wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan()
      wifi: mac80211: simplify return value handling of cfg80211_get_radio_idx_by_chan()
      wifi: mac80211: consider links for validating SCAN_FLAG_AP in scan request during MLO

 include/net/cfg80211.h |  2 +-
 net/mac80211/cfg.c     | 34 +++++++++++++++++-----------------
 net/mac80211/chan.c    | 11 -----------
 net/mac80211/util.c    | 15 ++++++---------
 net/wireless/util.c    |  2 +-
 5 files changed, 25 insertions(+), 39 deletions(-)
---
base-commit: d9104cec3e8fe4b458b74709853231385779001f
change-id: 20250527-fix_scan_ap_flag_requirement_during_mlo-d9bce1b859a1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH wireless-next v4 1/3] wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan()
  2025-08-12  7:23 [PATCH wireless-next v4 0/3] fix_scan_ap_flag_requirement_during_mlo Aditya Kumar Singh
@ 2025-08-12  7:23 ` Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 2/3] wifi: mac80211: simplify return value handling of cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 3/3] wifi: mac80211: consider links for validating SCAN_FLAG_AP in scan request during MLO Aditya Kumar Singh
  2 siblings, 0 replies; 4+ messages in thread
From: Aditya Kumar Singh @ 2025-08-12  7:23 UTC (permalink / raw)
  To: Johannes Berg, Aditya Kumar Singh
  Cc: Johannes Berg, linux-wireless, linux-kernel

If a valid radio index is not found, the function returns -ENOENT. If the
channel argument itself is invalid, it returns -EINVAL. However, since the
caller only checks for < 0, the distinction between these error codes is
not utilized much. Also, handling these two distinct error codes throughout
the codebase adds complexity, as both cases must be addressed separately. A
subsequent change aims to simplify this by using a single error code for
all invalid cases, making error handling more consistent and streamlined.

To support this change, update the return value to -EINVAL when a valid
radio index is not found. This is still appropriate because, even if the
channel argument is structurally valid, the absence of a corresponding
radio index implies that the argument is effectively invalid—otherwise, a
valid index would have been found.

Signed-off-by: Aditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
---
 include/net/cfg80211.h | 2 +-
 net/wireless/util.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 406626ff6cc89df4df30e6e623403b4d9ceb6cbd..cb1c36be27493bc0b356497cdbc68f1be7b4a94d 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -9548,7 +9548,7 @@ int cfg80211_iter_combinations(struct wiphy *wiphy,
  * @wiphy: the wiphy
  * @chan: channel for which the supported radio index is required
  *
- * Return: radio index on success or a negative error code
+ * Return: radio index on success or -EINVAL otherwise
  */
 int cfg80211_get_radio_idx_by_chan(struct wiphy *wiphy,
 				   const struct ieee80211_channel *chan);
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 240c68baa3d1f71a80a36af854acf4aa7ce75d05..d12d49134c88159f19c2226517d129f74f3ce764 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -2584,7 +2584,7 @@ int cfg80211_get_radio_idx_by_chan(struct wiphy *wiphy,
 		}
 	}
 
-	return -ENOENT;
+	return -EINVAL;
 }
 EXPORT_SYMBOL(cfg80211_get_radio_idx_by_chan);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH wireless-next v4 2/3] wifi: mac80211: simplify return value handling of cfg80211_get_radio_idx_by_chan()
  2025-08-12  7:23 [PATCH wireless-next v4 0/3] fix_scan_ap_flag_requirement_during_mlo Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 1/3] wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
@ 2025-08-12  7:23 ` Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 3/3] wifi: mac80211: consider links for validating SCAN_FLAG_AP in scan request during MLO Aditya Kumar Singh
  2 siblings, 0 replies; 4+ messages in thread
From: Aditya Kumar Singh @ 2025-08-12  7:23 UTC (permalink / raw)
  To: Johannes Berg, Aditya Kumar Singh
  Cc: Johannes Berg, linux-wireless, linux-kernel

In several instances where cfg80211_get_radio_idx_by_chan() is called,
redundant checks are performed across function — such as verifying if
wiphy->n_radio < 2 or if the returned index is negative. These checks are
unnecessary, as the return value can be directly compared. Moreover, the
function can be safely called even when radio-level properties are not
explicitly advertised since in such case in each call it is going to get
same error value.

Therefore, simplify the usage of this function across all such cases by
removing redundant conditions and relying on the return value directly.

Signed-off-by: Aditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
---
 net/mac80211/cfg.c  | 13 -------------
 net/mac80211/chan.c | 11 -----------
 net/mac80211/util.c | 15 ++++++---------
 3 files changed, 6 insertions(+), 33 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 2ed07fa121ab73d3afd2f841eb53e6cdc0be91a3..d4100d046442a51a0baf42d6ab3b921302d307f7 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -3677,12 +3677,7 @@ static bool ieee80211_is_scan_ongoing(struct wiphy *wiphy,
 	if (list_empty(&local->roc_list) && !local->scanning)
 		return false;
 
-	if (wiphy->n_radio < 2)
-		return true;
-
 	req_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chandef->chan);
-	if (req_radio_idx < 0)
-		return true;
 
 	if (local->scanning) {
 		scan_req = wiphy_dereference(wiphy, local->scan_req);
@@ -3701,14 +3696,6 @@ static bool ieee80211_is_scan_ongoing(struct wiphy *wiphy,
 	list_for_each_entry(roc, &local->roc_list, list) {
 		chan_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy,
 								roc->chan);
-		/*
-		 * The roc work is added but chan_radio_idx is invalid.
-		 * Should not happen but if it does, let's not take
-		 * risk and return true.
-		 */
-		if (chan_radio_idx < 0)
-			return true;
-
 		if (chan_radio_idx == req_radio_idx)
 			return true;
 	}
diff --git a/net/mac80211/chan.c b/net/mac80211/chan.c
index c9cea0e7ac169839f883f73186b575eacfe55db5..57065714cf8ceb5e612705ddc913b90c1f296e2a 100644
--- a/net/mac80211/chan.c
+++ b/net/mac80211/chan.c
@@ -659,19 +659,8 @@ bool ieee80211_is_radar_required(struct ieee80211_local *local,
 
 	for_each_sdata_link(local, link) {
 		if (link->radar_required) {
-			if (wiphy->n_radio < 2)
-				return true;
-
 			chan = link->conf->chanreq.oper.chan;
 			radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan);
-			/*
-			 * The radio index (radio_idx) is expected to be valid,
-			 * as it's derived from a channel tied to a link. If
-			 * it's invalid (i.e., negative), return true to avoid
-			 * potential issues with radar-sensitive operations.
-			 */
-			if (radio_idx < 0)
-				return true;
 
 			if (ieee80211_is_radio_idx_in_scan_req(wiphy, req,
 							       radio_idx))
diff --git a/net/mac80211/util.c b/net/mac80211/util.c
index 32f1bc5908c571416df905bdda1ba54dd7b41f33..51e3e3c913f7f9faa4a0283c0aa9509efc805391 100644
--- a/net/mac80211/util.c
+++ b/net/mac80211/util.c
@@ -4022,16 +4022,13 @@ bool ieee80211_is_radio_idx_in_scan_req(struct wiphy *wiphy,
 	for (i = 0; i < scan_req->n_channels; i++) {
 		chan = scan_req->channels[i];
 		chan_radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan);
-		/*
-		 * The chan_radio_idx should be valid since it's taken from a
-		 * valid scan request.
-		 * However, if chan_radio_idx is unexpectedly invalid (negative),
-		 * we take a conservative approach and assume the scan request
-		 * might use the specified radio_idx. Hence, return true.
-		 */
-		if (WARN_ON(chan_radio_idx < 0))
-			return true;
 
+		/* The radio index either matched successfully, or an error
+		 * occurred. For example, if radio-level information is
+		 * missing, the same error value is returned. This
+		 * typically implies a single-radio setup, in which case
+		 * the operation should not be allowed.
+		 */
 		if (chan_radio_idx == radio_idx)
 			return true;
 	}

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH wireless-next v4 3/3] wifi: mac80211: consider links for validating SCAN_FLAG_AP in scan request during MLO
  2025-08-12  7:23 [PATCH wireless-next v4 0/3] fix_scan_ap_flag_requirement_during_mlo Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 1/3] wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
  2025-08-12  7:23 ` [PATCH wireless-next v4 2/3] wifi: mac80211: simplify return value handling of cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
@ 2025-08-12  7:23 ` Aditya Kumar Singh
  2 siblings, 0 replies; 4+ messages in thread
From: Aditya Kumar Singh @ 2025-08-12  7:23 UTC (permalink / raw)
  To: Johannes Berg, Aditya Kumar Singh
  Cc: Johannes Berg, linux-wireless, linux-kernel

Commit 78a7a126dc5b ("wifi: mac80211: validate SCAN_FLAG_AP in scan request
during MLO") introduced a check that rejects scan requests if any link is
already beaconing. This works fine when all links share the same radio, but
breaks down in multi-radio setups.

Consider a scenario where a 2.4 GHz link is beaconing and a scan is
requested on a 5 GHz link, each backed by a different physical radio. The
current logic still blocks the scan, even though it should be allowed. As a
result, interface bring-up fails unnecessarily in valid configurations.

Fix this by checking whether the scan is being requested on the same
underlying radio as the beaconing link. Only reject the scan if it targets
a link that is already beaconing and the NL80211_FEATURE_AP_SCAN is not
set. This ensures correct behavior in multi-radio environments and avoids
false rejections.

Fixes: 78a7a126dc5b ("wifi: mac80211: validate SCAN_FLAG_AP in scan request during MLO")
Signed-off-by: Aditya Kumar Singh <aditya.kumar.singh@oss.qualcomm.com>
---
 net/mac80211/cfg.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index d4100d046442a51a0baf42d6ab3b921302d307f7..fc39a5bc2ccbd0e6fd1128c6cd422f8b2c3c987b 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -3001,6 +3001,9 @@ static int ieee80211_scan(struct wiphy *wiphy,
 			  struct cfg80211_scan_request *req)
 {
 	struct ieee80211_sub_if_data *sdata;
+	struct ieee80211_link_data *link;
+	struct ieee80211_channel *chan;
+	int radio_idx;
 
 	sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
 
@@ -3028,10 +3031,20 @@ static int ieee80211_scan(struct wiphy *wiphy,
 		 * the frames sent while scanning on other channel will be
 		 * lost)
 		 */
-		if (ieee80211_num_beaconing_links(sdata) &&
-		    (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
-		     !(req->flags & NL80211_SCAN_FLAG_AP)))
-			return -EOPNOTSUPP;
+		for_each_link_data(sdata, link) {
+			/* if the link is not beaconing, ignore it */
+			if (!sdata_dereference(link->u.ap.beacon, sdata))
+				continue;
+
+			chan = link->conf->chanreq.oper.chan;
+			radio_idx = cfg80211_get_radio_idx_by_chan(wiphy, chan);
+
+			if (ieee80211_is_radio_idx_in_scan_req(wiphy, req,
+							       radio_idx) &&
+			    (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
+			     !(req->flags & NL80211_SCAN_FLAG_AP)))
+				return -EOPNOTSUPP;
+		}
 		break;
 	case NL80211_IFTYPE_NAN:
 	default:

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-08-12  7:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-12  7:23 [PATCH wireless-next v4 0/3] fix_scan_ap_flag_requirement_during_mlo Aditya Kumar Singh
2025-08-12  7:23 ` [PATCH wireless-next v4 1/3] wifi: cfg80211: fix return value in cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
2025-08-12  7:23 ` [PATCH wireless-next v4 2/3] wifi: mac80211: simplify return value handling of cfg80211_get_radio_idx_by_chan() Aditya Kumar Singh
2025-08-12  7:23 ` [PATCH wireless-next v4 3/3] wifi: mac80211: consider links for validating SCAN_FLAG_AP in scan request during MLO Aditya Kumar Singh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).