Skip to content

Commit eb46640

Browse files
GoodLuck612gregkh
authored andcommitted
wifi: mt76: Fix memory leak after mt76_connac_mcu_alloc_sta_req()
[ Upstream commit c41075c ] mt76_connac_mcu_alloc_sta_req() allocates an skb which is expected to be freed eventually by mt76_mcu_skb_send_msg(). However, currently if an intermediate function fails before sending, the allocated skb is leaked. Specifically, mt76_connac_mcu_sta_wed_update() and mt76_connac_mcu_sta_key_tlv() may fail, leading to an immediate memory leak in the error path. Fix this by explicitly freeing the skb in these error paths. Commit 7c0f63f ("wifi: mt76: mt7996: fix memory leak on mt7996_mcu_sta_key_tlv error") made a similar change. Compile tested only. Issue found using a prototype static analysis tool and code review. Fixes: d1369e5 ("wifi: mt76: connac: introduce mt76_connac_mcu_sta_wed_update utility routine") Fixes: 6683d98 ("mt76: connac: move mt76_connac_mcu_add_key in connac module") Fixes: 4f831d1 ("wifi: mt76: mt7915: enable WED RX support") Fixes: c948b5d ("wifi: mt76: mt7925: add Mediatek Wi-Fi7 driver for mt7925 chips") Signed-off-by: Zilin Guan <zilin@seu.edu.cn> Link: https://patch.msgid.link/20260116144919.1482558-1-zilin@seu.edu.cn Signed-off-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2d8e005 commit eb46640

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,8 +1295,10 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif,
12951295
wtbl_hdr);
12961296

12971297
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
1298-
if (ret)
1298+
if (ret) {
1299+
dev_kfree_skb(skb);
12991300
return ret;
1301+
}
13001302

13011303
ret = mt76_mcu_skb_send_msg(dev, skb, cmd, true);
13021304
if (ret)
@@ -1309,8 +1311,10 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif_link *mvif,
13091311
mt76_connac_mcu_sta_ba_tlv(skb, params, enable, tx);
13101312

13111313
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
1312-
if (ret)
1314+
if (ret) {
1315+
dev_kfree_skb(skb);
13131316
return ret;
1317+
}
13141318

13151319
return mt76_mcu_skb_send_msg(dev, skb, cmd, true);
13161320
}
@@ -2764,12 +2768,16 @@ int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
27642768
return PTR_ERR(skb);
27652769

27662770
ret = mt76_connac_mcu_sta_key_tlv(sta_key_conf, skb, key, cmd);
2767-
if (ret)
2771+
if (ret) {
2772+
dev_kfree_skb(skb);
27682773
return ret;
2774+
}
27692775

27702776
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
2771-
if (ret)
2777+
if (ret) {
2778+
dev_kfree_skb(skb);
27722779
return ret;
2780+
}
27732781

27742782
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
27752783
}

drivers/net/wireless/mediatek/mt76/mt7915/mcu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1765,8 +1765,10 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif,
17651765
}
17661766
out:
17671767
ret = mt76_connac_mcu_sta_wed_update(&dev->mt76, skb);
1768-
if (ret)
1768+
if (ret) {
1769+
dev_kfree_skb(skb);
17691770
return ret;
1771+
}
17701772

17711773
return mt76_mcu_skb_send_msg(&dev->mt76, skb,
17721774
MCU_EXT_CMD(STA_REC_UPDATE), true);

drivers/net/wireless/mediatek/mt76/mt7925/mcu.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,10 @@ int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
12881288
return PTR_ERR(skb);
12891289

12901290
ret = mt7925_mcu_sta_key_tlv(wcid, sta_key_conf, skb, key, cmd, msta);
1291-
if (ret)
1291+
if (ret) {
1292+
dev_kfree_skb(skb);
12921293
return ret;
1294+
}
12931295

12941296
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
12951297
}

0 commit comments

Comments
 (0)