Skip to contentSkip to conversation

wifi: mt76: mt7996: prevent uninit return in mt7996_mac_sta_add_links

PATCH Superseded Qasim Ijaz 2 participants 2 messages Mar 22, 2025 – Mar 23, 2025

Subsystems (2)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH v2 1/1 wifi: mt76: mt7996: prevent uninit return in mt7996_mac_sta_add_links

If link_conf_dereference_protected() or mt7996_vif_link() or link_sta_dereference_protected() fail the code jumps to the error_unlink label and returns ret which is uninitialised.

Fix this by setting err before jumping to error_unlink.

Fixes c7e4fc362443 ("wifi: mt76: mt7996: Update mt7996_mcu_add_sta to MLO support")
Fixes dd82a9e02c05 ("wifi: mt76: mt7996: Rely on mt7996_sta_link in sta_add/sta_remove callbacks")

---
v2:
- Added missing semi-colon as pointed out by Jonas Gorski

 drivers/net/wireless/mediatek/mt76/mt7996/main.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7996/main.c +9 -3
index 91c64e3a0860..70823bbb165c 100644
@@ -998,16 +998,22 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			continue;
 
 		link_conf = link_conf_dereference_protected(vif, link_id);
-		if (!link_conf)
+		if (!link_conf) {
+			err = -EINVAL;
 			goto error_unlink;
+		}
 
 		link = mt7996_vif_link(dev, vif, link_id);
-		if (!link)
+		if (!link) {
+			err = -EINVAL;
 			goto error_unlink;
+		}
 
 		link_sta = link_sta_dereference_protected(sta, link_id);
-		if (!link_sta)
+		if (!link_sta) {
+			err = -EINVAL;
 			goto error_unlink;
+		}
 
 		err = mt7996_mac_sta_init_link(dev, link_conf, link_sta, link,
 					       link_id);
Signature · 1 line
2.39.5
#1 lore raw

…

Quoted 2 lines

or link_sta_dereference_protected() fail the code jumps to the error_unlink label and returns ret which is uninitialised.

…

* Would you like to avoid typos in such a change description?

* Can any background information become more relevant for the usage of source code analysis tools?

* Can the summary phrase be improved also another bit?

…

Quoted 7 lines

+++ b/drivers/net/wireless/mediatek/mt76/mt7996/main.c

drivers/net/wireless/mediatek/mt76/mt7996/main.c +1 -1
@@ -998,16 +998,22 @@ mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif,
 			continue;
 
 		link_conf = link_conf_dereference_protected(vif, link_id);
-		if (!link_conf)
+		if (!link_conf) {

drivers/net/wireless/mediatek/mt76/mt7996/main.c mt7996_mac_sta_add_links(struct mt7996_dev *dev, struct ieee80211_vif *vif, · line 1010

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/mt7996/main.c +5 -1
+			err = -EINVAL;
 			goto error_unlink;
+		}
 
 		link = mt7996_vif_link(dev, vif, link_id);
-		if (!link)
+		if (!link) {
+			err = -EINVAL;
 			goto error_unlink;
+		}

…

Can software development interests evolve in ways which might make the avoidance of duplicate source code more feasible also for affected error/exception handling?

Regards,
Markus