Skip to content

Commit

Permalink
mt76: mt7915: Fix PCI device refcount leak in mt7915_pci_init_hif2()
Browse files Browse the repository at this point in the history
[ Upstream commit 5938196 ]

As comment of pci_get_device() says, it returns a pci_device with its
refcount increased. We need to call pci_dev_put() to decrease the
refcount. Save the return value of pci_get_device() and call
pci_dev_put() to decrease the refcount.

Fixes: 9093cff ("mt76: mt7915: add support for using a secondary PCIe link for gen1")
Fixes: 2e30db0 ("mt76: mt7915: add device id for mt7916")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
fenghusthu authored and gregkh committed Dec 31, 2022
1 parent d26fdb1 commit 2d4b9c7
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7915/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,17 @@ static void mt7915_put_hif2(struct mt7915_hif *hif)

static struct mt7915_hif *mt7915_pci_init_hif2(struct pci_dev *pdev)
{
struct pci_dev *tmp_pdev;

hif_idx++;
if (!pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x7916, NULL) &&
!pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x790a, NULL))
return NULL;

tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x7916, NULL);
if (!tmp_pdev) {
tmp_pdev = pci_get_device(PCI_VENDOR_ID_MEDIATEK, 0x790a, NULL);
if (!tmp_pdev)
return NULL;
}
pci_dev_put(tmp_pdev);

writel(hif_idx | MT_PCIE_RECOG_ID_SEM,
pcim_iomap_table(pdev)[0] + MT_PCIE_RECOG_ID);
Expand Down

0 comments on commit 2d4b9c7

Please sign in to comment.