diff mbox series

[v2,13/13] wiphy: don't re-dump wiphy if the regdom didn't change

Message ID 20220803213644.277534-13-prestwoj@gmail.com (mailing list archive)
State Not Applicable, archived
Headers show
Series [v2,01/13] wiphy: fix runtime error from bit shift | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Aug. 3, 2022, 9:36 p.m. UTC
For whatever reason the kernel will send regdom updates even if
the regdom didn't change. This ends up causing wiphy to dump
which isn't needed since there should be no changes in disabled
frequencies.

Now the previous country is checked against the new one, and if
they match the wiphy is not dumped again.
---
 src/wiphy.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/src/wiphy.c b/src/wiphy.c
index dec4b15e..cf7bd9bd 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -2029,7 +2029,20 @@  static void wiphy_dump_after_regdom(struct wiphy *wiphy)
 static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
 					struct l_genl_msg *msg)
 {
-	char *out_country;
+	char out_country[2];
+	char *orig;
+
+	/*
+	 * Write the new country code or XX if the reg domain is not a
+	 * country domain.
+	 */
+	if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
+				NL80211_ATTR_UNSPEC) < 0)
+		out_country[0] = out_country[1] = 'X';
+
+	l_debug("New reg domain country code for %s is %c%c",
+		global ? "(global)" : wiphy->name,
+		out_country[0], out_country[1]);
 
 	if (global)
 		/*
@@ -2043,21 +2056,24 @@  static void wiphy_update_reg_domain(struct wiphy *wiphy, bool global,
 		 * wiphy created (that is not self-managed anyway) and we
 		 * haven't received any REG_CHANGE events yet.
 		 */
-		out_country = regdom_country;
+		orig = regdom_country;
+
 	else
-		out_country = wiphy->regdom_country;
+		orig = wiphy->regdom_country;
 
 	/*
-	 * Write the new country code or XX if the reg domain is not a
-	 * country domain.
+	 * The kernel seems to send regdom updates even if the country didn't
+	 * change. Skip these as there is no reason to re-dump.
 	 */
-	if (nl80211_parse_attrs(msg, NL80211_ATTR_REG_ALPHA2, out_country,
-				NL80211_ATTR_UNSPEC) < 0)
-		out_country[0] = out_country[1] = 'X';
+	if (orig[0] == out_country[0] && orig[1] == out_country[1]) {
+		if (wiphy && wiphy->get_reg_id)
+			wiphy->get_reg_id = 0;
 
-	l_debug("New reg domain country code for %s is %c%c",
-		global ? "(global)" : wiphy->name,
-		out_country[0], out_country[1]);
+		return;
+	}
+
+	orig[0] = out_country[0];
+	orig[1] = out_country[1];
 
 	/* Don't dump wiphy from a GET_REG call */
 	if (wiphy && wiphy->get_reg_id) {