]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: cfg80211: split control freq check from chandef check
authorJohannes Berg <johannes.berg@intel.com>
Tue, 3 Mar 2026 14:26:19 +0000 (15:26 +0100)
committerJohannes Berg <johannes.berg@intel.com>
Fri, 13 Mar 2026 06:11:14 +0000 (07:11 +0100)
In order to introduce NPCA later, split the control frequency
check out of cfg80211_chandef_valid().

Link: https://patch.msgid.link/20260303152641.11b31e4878a7.I534669506008e12ffcd6c115161777e528fdc838@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
net/wireless/chan.c

index d9d4e043bb392e87947471543bfc65ce18ae6af0..e3c18a4392bb397d3c789599394cfdc7da1e6303 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright 2009      Johannes Berg <johannes@sipsolutions.net>
  * Copyright 2013-2014  Intel Mobile Communications GmbH
- * Copyright 2018-2025 Intel Corporation
+ * Copyright 2018-2026 Intel Corporation
  */
 
 #include <linux/export.h>
@@ -339,6 +339,58 @@ static bool cfg80211_valid_center_freq(u32 center,
        return (center - bw / 2 - 5945) % step == 0;
 }
 
+static bool
+cfg80211_chandef_valid_control_freq(const struct cfg80211_chan_def *chandef,
+                                   u32 control_freq)
+{
+       switch (chandef->width) {
+       case NL80211_CHAN_WIDTH_5:
+       case NL80211_CHAN_WIDTH_10:
+       case NL80211_CHAN_WIDTH_20:
+       case NL80211_CHAN_WIDTH_20_NOHT:
+       case NL80211_CHAN_WIDTH_1:
+       case NL80211_CHAN_WIDTH_2:
+       case NL80211_CHAN_WIDTH_4:
+       case NL80211_CHAN_WIDTH_8:
+       case NL80211_CHAN_WIDTH_16:
+               /* checked separately */
+               break;
+       case NL80211_CHAN_WIDTH_320:
+               if (chandef->center_freq1 == control_freq + 150 ||
+                   chandef->center_freq1 == control_freq + 130 ||
+                   chandef->center_freq1 == control_freq + 110 ||
+                   chandef->center_freq1 == control_freq + 90 ||
+                   chandef->center_freq1 == control_freq - 90 ||
+                   chandef->center_freq1 == control_freq - 110 ||
+                   chandef->center_freq1 == control_freq - 130 ||
+                   chandef->center_freq1 == control_freq - 150)
+                       break;
+               fallthrough;
+       case NL80211_CHAN_WIDTH_160:
+               if (chandef->center_freq1 == control_freq + 70 ||
+                   chandef->center_freq1 == control_freq + 50 ||
+                   chandef->center_freq1 == control_freq - 50 ||
+                   chandef->center_freq1 == control_freq - 70)
+                       break;
+               fallthrough;
+       case NL80211_CHAN_WIDTH_80P80:
+       case NL80211_CHAN_WIDTH_80:
+               if (chandef->center_freq1 == control_freq + 30 ||
+                   chandef->center_freq1 == control_freq - 30)
+                       break;
+               fallthrough;
+       case NL80211_CHAN_WIDTH_40:
+               if (chandef->center_freq1 == control_freq + 10 ||
+                   chandef->center_freq1 == control_freq - 10)
+                       break;
+               fallthrough;
+       default:
+               return false;
+       }
+
+       return true;
+}
+
 bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
 {
        u32 control_freq, control_freq_khz, start_khz, end_khz;
@@ -393,50 +445,8 @@ bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef)
                break;
        }
 
-       switch (chandef->width) {
-       case NL80211_CHAN_WIDTH_5:
-       case NL80211_CHAN_WIDTH_10:
-       case NL80211_CHAN_WIDTH_20:
-       case NL80211_CHAN_WIDTH_20_NOHT:
-       case NL80211_CHAN_WIDTH_1:
-       case NL80211_CHAN_WIDTH_2:
-       case NL80211_CHAN_WIDTH_4:
-       case NL80211_CHAN_WIDTH_8:
-       case NL80211_CHAN_WIDTH_16:
-               /* all checked above */
-               break;
-       case NL80211_CHAN_WIDTH_320:
-               if (chandef->center_freq1 == control_freq + 150 ||
-                   chandef->center_freq1 == control_freq + 130 ||
-                   chandef->center_freq1 == control_freq + 110 ||
-                   chandef->center_freq1 == control_freq + 90 ||
-                   chandef->center_freq1 == control_freq - 90 ||
-                   chandef->center_freq1 == control_freq - 110 ||
-                   chandef->center_freq1 == control_freq - 130 ||
-                   chandef->center_freq1 == control_freq - 150)
-                       break;
-               fallthrough;
-       case NL80211_CHAN_WIDTH_160:
-               if (chandef->center_freq1 == control_freq + 70 ||
-                   chandef->center_freq1 == control_freq + 50 ||
-                   chandef->center_freq1 == control_freq - 50 ||
-                   chandef->center_freq1 == control_freq - 70)
-                       break;
-               fallthrough;
-       case NL80211_CHAN_WIDTH_80P80:
-       case NL80211_CHAN_WIDTH_80:
-               if (chandef->center_freq1 == control_freq + 30 ||
-                   chandef->center_freq1 == control_freq - 30)
-                       break;
-               fallthrough;
-       case NL80211_CHAN_WIDTH_40:
-               if (chandef->center_freq1 == control_freq + 10 ||
-                   chandef->center_freq1 == control_freq - 10)
-                       break;
-               fallthrough;
-       default:
+       if (!cfg80211_chandef_valid_control_freq(chandef, control_freq))
                return false;
-       }
 
        if (!cfg80211_valid_center_freq(chandef->center_freq1, chandef->width))
                return false;