Skip to content

Commit c9ba7ee

Browse files
GoodLuck612opsiff
authored andcommitted
wifi: mt76: Fix memory leak after mt76_connac_mcu_alloc_sta_req()
mainline inclusion from mainline-v7.1-rc1 category: bugfix 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> (cherry picked from commit c41075ce8cf05ed8c0e7b7efef000dce548ffc42) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 93fa5a1 commit c9ba7ee

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
@@ -1283,8 +1283,10 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
12831283
wtbl_hdr);
12841284

12851285
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
1286-
if (ret)
1286+
if (ret) {
1287+
dev_kfree_skb(skb);
12871288
return ret;
1289+
}
12881290

12891291
ret = mt76_mcu_skb_send_msg(dev, skb, cmd, true);
12901292
if (ret)
@@ -1297,8 +1299,10 @@ int mt76_connac_mcu_sta_ba(struct mt76_dev *dev, struct mt76_vif *mvif,
12971299
mt76_connac_mcu_sta_ba_tlv(skb, params, enable, tx);
12981300

12991301
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
1300-
if (ret)
1302+
if (ret) {
1303+
dev_kfree_skb(skb);
13011304
return ret;
1305+
}
13021306

13031307
return mt76_mcu_skb_send_msg(dev, skb, cmd, true);
13041308
}
@@ -2689,12 +2693,16 @@ int mt76_connac_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
26892693
return PTR_ERR(skb);
26902694

26912695
ret = mt76_connac_mcu_sta_key_tlv(sta_key_conf, skb, key, cmd);
2692-
if (ret)
2696+
if (ret) {
2697+
dev_kfree_skb(skb);
26932698
return ret;
2699+
}
26942700

26952701
ret = mt76_connac_mcu_sta_wed_update(dev, skb);
2696-
if (ret)
2702+
if (ret) {
2703+
dev_kfree_skb(skb);
26972704
return ret;
2705+
}
26982706

26992707
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
27002708
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,10 @@ int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif,
17151715
}
17161716
out:
17171717
ret = mt76_connac_mcu_sta_wed_update(&dev->mt76, skb);
1718-
if (ret)
1718+
if (ret) {
1719+
dev_kfree_skb(skb);
17191720
return ret;
1721+
}
17201722

17211723
return mt76_mcu_skb_send_msg(&dev->mt76, skb,
17221724
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
@@ -1116,8 +1116,10 @@ int mt7925_mcu_add_key(struct mt76_dev *dev, struct ieee80211_vif *vif,
11161116
return PTR_ERR(skb);
11171117

11181118
ret = mt7925_mcu_sta_key_tlv(wcid, sta_key_conf, skb, key, cmd, msta);
1119-
if (ret)
1119+
if (ret) {
1120+
dev_kfree_skb(skb);
11201121
return ret;
1122+
}
11211123

11221124
return mt76_mcu_skb_send_msg(dev, skb, mcu_cmd, true);
11231125
}

0 commit comments

Comments
 (0)