]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
wifi: rtw88: Use devm_kmemdup() in rtw_set_supported_band()
authorBitterblue Smith <rtl8821cerfe2@gmail.com>
Tue, 23 Dec 2025 23:25:32 +0000 (01:25 +0200)
committerPing-Ke Shih <pkshih@realtek.com>
Fri, 26 Dec 2025 05:32:48 +0000 (13:32 +0800)
Simplify the code by using device managed memory allocations.

This also fixes a memory leak in rtw_register_hw(). The supported bands
were not freed in the error path.

Copied from commit 145df52a8671 ("wifi: rtw89: Convert
rtw89_core_set_supported_band to use devm_*").

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Link: https://patch.msgid.link/1aa7fdef-2d5b-4a31-a4e9-fac8257ed30d@gmail.com
drivers/net/wireless/realtek/rtw88/main.c

index 9470042b12a8df68295dc18feb730ce73c8c8c88..46af5bcbb8bc5835d162b76970b3573ed4ffff94 100644 (file)
@@ -1664,11 +1664,13 @@ static u16 rtw_get_max_scan_ie_len(struct rtw_dev *rtwdev)
 static void rtw_set_supported_band(struct ieee80211_hw *hw,
                                   const struct rtw_chip_info *chip)
 {
-       struct rtw_dev *rtwdev = hw->priv;
        struct ieee80211_supported_band *sband;
+       struct rtw_dev *rtwdev = hw->priv;
+       struct device *dev = rtwdev->dev;
 
        if (chip->band & RTW_BAND_2G) {
-               sband = kmemdup(&rtw_band_2ghz, sizeof(*sband), GFP_KERNEL);
+               sband = devm_kmemdup(dev, &rtw_band_2ghz, sizeof(*sband),
+                                    GFP_KERNEL);
                if (!sband)
                        goto err_out;
                if (chip->ht_supported)
@@ -1677,7 +1679,8 @@ static void rtw_set_supported_band(struct ieee80211_hw *hw,
        }
 
        if (chip->band & RTW_BAND_5G) {
-               sband = kmemdup(&rtw_band_5ghz, sizeof(*sband), GFP_KERNEL);
+               sband = devm_kmemdup(dev, &rtw_band_5ghz, sizeof(*sband),
+                                    GFP_KERNEL);
                if (!sband)
                        goto err_out;
                if (chip->ht_supported)
@@ -1693,13 +1696,6 @@ err_out:
        rtw_err(rtwdev, "failed to set supported band\n");
 }
 
-static void rtw_unset_supported_band(struct ieee80211_hw *hw,
-                                    const struct rtw_chip_info *chip)
-{
-       kfree(hw->wiphy->bands[NL80211_BAND_2GHZ]);
-       kfree(hw->wiphy->bands[NL80211_BAND_5GHZ]);
-}
-
 static void rtw_vif_smps_iter(void *data, u8 *mac,
                              struct ieee80211_vif *vif)
 {
@@ -2323,10 +2319,7 @@ EXPORT_SYMBOL(rtw_register_hw);
 
 void rtw_unregister_hw(struct rtw_dev *rtwdev, struct ieee80211_hw *hw)
 {
-       const struct rtw_chip_info *chip = rtwdev->chip;
-
        ieee80211_unregister_hw(hw);
-       rtw_unset_supported_band(hw, chip);
        rtw_debugfs_deinit(rtwdev);
        rtw_led_deinit(rtwdev);
 }