platform/x86: amd-pmc: put device on error paths
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines · Pan Bian
Put the PCI device rdev on error paths to fix potential reference count leaks.
Can you make a stronger statment than "fix potenital reference count leaks?". Also, make the commit comment match the code better.
maybe something like:
"On the prob error return paths associated with rdev we are leaking ref counts, add pci_dev_put to return patch to avoid the leaks".
Note: I'm not sure there is a leak but, assuming the code is correct the commit comment should be more clear and match the code.
Do you have a test case that show this change is good?
--mark
Quoted 57 lines
Signed-off-by Pan Bian <[email protected]>--- drivers/platform/x86/amd-pmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/platform/x86/amd-pmc.c +11
-3@@ -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);Signature · 1 line
2.17.1
Hi,
Quoted 4 lines · Pan Bian
Put the PCI device rdev on error paths to fix potential reference count leaks.
Signed-off-by Pan Bian <[email protected]>
Thank you for your patch, I've applied this patch to my review-hans branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=review-hans
Note it will show up in my review-hans branch once I've pushed my local branch there, which might take a while.
Once I've run some tests on this branch the patches there will be added to the platform-drivers-x86/for-next branch and eventually will be included in the pdx86 pull-request to Linus for the next merge-window.
Regards,
Hans
Quoted 52 lines
--- drivers/platform/x86/amd-pmc.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)drivers/platform/x86/amd-pmc.c +11
-3@@ -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);