Skip to content

Commit

Permalink
platform/x86: amd-pmc: put device on error paths
Browse files Browse the repository at this point in the history
Put the PCI device rdev on error paths to fix potential reference count
leaks.

Signed-off-by: Pan Bian <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Hans de Goede <[email protected]>
Signed-off-by: Hans de Goede <[email protected]>
  • Loading branch information
SinkFinder authored and jwrdegoede committed Feb 2, 2021
1 parent eabe533 commit 745ed17
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions drivers/platform/x86/amd-pmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,31 +210,39 @@ static int amd_pmc_probe(struct platform_device *pdev)
dev->dev = &pdev->dev;

rdev = pci_get_domain_bus_and_slot(0, 0, PCI_DEVFN(0, 0));
if (!rdev || !pci_match_id(pmc_pci_ids, rdev))
if (!rdev || !pci_match_id(pmc_pci_ids, rdev)) {
pci_dev_put(rdev);
return -ENODEV;
}

dev->cpu_id = rdev->device;
err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_LO);
if (err) {
dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS);
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}

err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val);
if (err)
if (err) {
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}

base_addr_lo = val & AMD_PMC_BASE_ADDR_HI_MASK;

err = pci_write_config_dword(rdev, AMD_PMC_SMU_INDEX_ADDRESS, AMD_PMC_BASE_ADDR_HI);
if (err) {
dev_err(dev->dev, "error writing to 0x%x\n", AMD_PMC_SMU_INDEX_ADDRESS);
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}

err = pci_read_config_dword(rdev, AMD_PMC_SMU_INDEX_DATA, &val);
if (err)
if (err) {
pci_dev_put(rdev);
return pcibios_err_to_errno(err);
}

base_addr_hi = val & AMD_PMC_BASE_ADDR_LO_MASK;
pci_dev_put(rdev);
Expand Down

0 comments on commit 745ed17

Please sign in to comment.