]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: mt76: mt7921: fix resource leak in probe error path
authorHongling Zeng <zenghongling@kylinos.cn>
Tue, 12 May 2026 06:52:45 +0000 (14:52 +0800)
committerFelix Fietkau <nbd@nbd.name>
Tue, 9 Jun 2026 10:15:19 +0000 (10:15 +0000)
When pcim_iomap_region() or devm_kmemdup() fail, the code returns
directly without cleaning up previously allocated resources:
  - mt76_device allocated by mt76_alloc_device()
  - pci irq vectors allocated by pci_alloc_irq_vectors()
Fix this by jumping to the existing error cleanup path instead of
returning directly.

Fixes: ee5bb35d2b83 ("wifi: mt76: mt7921: Replace deprecated PCI function")
Fixes: 222606f43b58 ("wifi: mt76: mt7921: handle MT7902 irq_map quirk with mutable copy")
Signed-off-by: Hongling Zeng <zenghongling@kylinos.cn>
Link: https://patch.msgid.link/20260512065245.46496-1-zenghongling@kylinos.cn
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7921/pci.c

index 7a790ddf43bb698b2c7d7935d6f862ca58dfe7fb..49a37185f0564ec69cd46e93ffecc8128d925461 100644 (file)
@@ -343,11 +343,14 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
 
        pci_set_drvdata(pdev, mdev);
 
+       dev = container_of(mdev, struct mt792x_dev, mt76);
+
        regs =  pcim_iomap_region(pdev, 0, pci_name(pdev));
-       if (IS_ERR(regs))
-               return PTR_ERR(regs);
+       if (IS_ERR(regs)) {
+               ret = PTR_ERR(regs);
+               goto err_free_dev;
+       }
 
-       dev = container_of(mdev, struct mt792x_dev, mt76);
        dev->fw_features = features;
        dev->hif_ops = &mt7921_pcie_ops;
        dev->irq_map = &irq_map;
@@ -359,8 +362,10 @@ static int mt7921_pci_probe(struct pci_dev *pdev,
                /* MT7902 needs a mutable copy because wm2_complete_mask differs */
                map = devm_kmemdup(&pdev->dev, &irq_map,
                                   sizeof(irq_map), GFP_KERNEL);
-               if (!map)
-                       return -ENOMEM;
+               if (!map) {
+                       ret = -ENOMEM;
+                       goto err_free_dev;
+               }
 
                map->rx.wm2_complete_mask = 0;
                dev->irq_map = map;