mt7921_regd_channel_update() and __mt7921_mcu_set_clc() never release the nodes returned by mt76_find_power_limits_node(), of_get_child_by_name() and mt76_find_channel_node(). Each regulatory domain change and each CLC update on a device with DT power limits leaks these references. Release every node after use. This relies on mt76_find_power_limits_node() also returning a reference for the fallback node, which it does since commit 3a62c9f7ec3d ("wifi: mt76: Fix of_node reference leak in mt76_get_rate_power_limits()"). Fixes: 09382d8f8641 ("wifi: mt76: mt7921: update the channel usage when the regd domain changed") Signed-off-by: Felix Fietkau --- .../net/wireless/mediatek/mt76/mt7921/mcu.c | 7 ++++- .../net/wireless/mediatek/mt76/mt7921/regd.c | 28 ++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c index bdeb6614a5a9..25638c68c468 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/mcu.c @@ -3,6 +3,7 @@ #include #include +#include #include "mt7921.h" #include "regd.h" #include "mcu.h" @@ -1363,6 +1364,7 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, .acpi_conf = mt792x_acpi_get_flags(&dev->phy), .mtcl_conf = mt792x_acpi_get_mtcl_conf(&dev->phy, alpha2), }; + struct device_node *np; int ret, valid_cnt = 0; u32 buf_len = 0; u8 *pos; @@ -1372,8 +1374,11 @@ int __mt7921_mcu_set_clc(struct mt792x_dev *dev, u8 *alpha2, if (dev->phy.chip_cap & MT792x_CHIP_CAP_CLC_EVT_EN) req.cap |= CLC_CAP_EVT_EN; - if (mt76_find_power_limits_node(&dev->mt76)) + + np = mt76_find_power_limits_node(&dev->mt76); + if (np) req.cap |= CLC_CAP_DTS_EN; + of_node_put(np); buf_len = le32_to_cpu(clc->len) - sizeof(*clc); pos = clc->data; diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c index fcdeb65cd8ef..699617d9e48f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7921/regd.c +++ b/drivers/net/wireless/mediatek/mt76/mt7921/regd.c @@ -28,6 +28,21 @@ bool mt7921_regd_clc_supported(struct mt792x_dev *dev) return true; } +static bool +mt7921_regd_dt_has_channel(struct device_node *band_np, + struct ieee80211_channel *ch) +{ + struct device_node *chan_np; + + if (!band_np) + return false; + + chan_np = mt76_find_channel_node(band_np, ch); + of_node_put(chan_np); + + return !!chan_np; +} + static void mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) { @@ -43,14 +58,14 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) sband = wiphy->bands[NL80211_BAND_5GHZ]; if (!sband) - return; + goto out; band_np = np ? of_get_child_by_name(np, "txpower-5g") : NULL; for (i = 0; i < sband->n_channels; i++) { ch = &sband->channels[i]; cfreq = ch->center_freq; - if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) { + if (np && !mt7921_regd_dt_has_channel(band_np, ch)) { ch->flags |= IEEE80211_CHAN_DISABLED; continue; } @@ -59,17 +74,18 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) if (IS_UNII_INVALID(0, 5845, 5925)) ch->flags |= IEEE80211_CHAN_DISABLED; } + of_node_put(band_np); sband = wiphy->bands[NL80211_BAND_6GHZ]; if (!sband) - return; + goto out; band_np = np ? of_get_child_by_name(np, "txpower-6g") : NULL; for (i = 0; i < sband->n_channels; i++) { ch = &sband->channels[i]; cfreq = ch->center_freq; - if (np && (!band_np || !mt76_find_channel_node(band_np, ch))) { + if (np && !mt7921_regd_dt_has_channel(band_np, ch)) { ch->flags |= IEEE80211_CHAN_DISABLED; continue; } @@ -81,6 +97,10 @@ mt7921_regd_channel_update(struct wiphy *wiphy, struct mt792x_dev *dev) IS_UNII_INVALID(4, 6875, 7125)) ch->flags |= IEEE80211_CHAN_DISABLED; } + of_node_put(band_np); + +out: + of_node_put(np); } int __mt7921_mcu_regd_update(struct mt792x_dev *dev, u8 *alpha2, -- 2.47.3