Skip to contentSkip to conversation

platform/x86/amd: Fix refcount leak in amd_pmc_probe

PATCH In review Miaoqian Lin 3 participants 3 messages Dec 29, 2022 – Jan 12, 2023 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 platform/x86/amd: Fix refcount leak in amd_pmc_probe

pci_get_domain_bus_and_slot() takes reference, the caller should release the reference by calling pci_dev_put() after use. Call pci_dev_put() in the error path to fix this.

Fixes 3d7d407dfb05 ("platform/x86: amd-pmc: Add support for AMD Spill to DRAM STB feature")
---
 drivers/platform/x86/amd/pmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/amd/pmc.c +1 -1
index 439d282aafd1..8d924986381b 100644
@@ -932,7 +932,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
 	if (enable_stb && (dev->cpu_id == AMD_CPU_ID_YC || dev->cpu_id == AMD_CPU_ID_CB)) {
 		err = amd_pmc_s2d_init(dev);
 		if (err)
-			return err;
+			goto err_pci_dev_put;
 	}
 
 	platform_set_drvdata(pdev, dev);
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw

[Public]

Quoted 11 lines

-----Original Message-----
From: Miaoqian Lin <[email protected]>
Sent: Thursday, December 29, 2022 01:26
To: S-k, Shyam-sundar <[email protected]>; Hans de Goede <[email protected]>; Mark Gross <[email protected]>; Goswami, Sanket <[email protected]>; Limonciello, Mario <[email protected]>; [email protected]; linux- [email protected]
Cc: [email protected]
Subject: [PATCH] platform/x86/amd: Fix refcount leak in amd_pmc_probe

Quoted 7 lines

pci_get_domain_bus_and_slot() takes reference, the caller should release the reference by calling pci_dev_put() after use. Call pci_dev_put() in the error path to fix this.

Fixes 3d7d407dfb05 ("platform/x86: amd-pmc: Add support for AMD Spill to

DRAM STB feature")

Makes sense to me, thanks!

Quoted 22 lines
---
 drivers/platform/x86/amd/pmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/amd/pmc.c +1 -1
index 439d282aafd1..8d924986381b 100644
@@ -932,7 +932,7 @@ static int amd_pmc_probe(struct platform_device
 *pdev)
 	if (enable_stb && (dev->cpu_id == AMD_CPU_ID_YC || dev->cpu_id
 == AMD_CPU_ID_CB)) {
 		err = amd_pmc_s2d_init(dev);
 		if (err)
-			return err;
+			goto err_pci_dev_put;
 	}

platform_set_drvdata(pdev, dev);
--
2.25.1

#2 lore raw
In reply to Miaoqian Lin

Hi,

Quoted 6 lines · Miaoqian Lin

pci_get_domain_bus_and_slot() takes reference, the caller should release the reference by calling pci_dev_put() after use. Call pci_dev_put() in the error path to fix this.

Fixes 3d7d407dfb05 ("platform/x86: amd-pmc: Add support for AMD Spill to DRAM STB feature")

Thank you for your patch, I've applied this patch to my fixes branch:
https://git.kernel.org/pub/scm/linux/kernel/git/pdx86/platform-drivers-x86.git/log/?h=fixes

Note it will show up in my fixes branch once I've pushed my local branch there, which might take a while.

I will include this patch in my next fixes pull-req to Linus for the current kernel development cycle.

Regards,

Hans

Quoted 17 lines
---
 drivers/platform/x86/amd/pmc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/x86/amd/pmc.c +1 -1
index 439d282aafd1..8d924986381b 100644
@@ -932,7 +932,7 @@ static int amd_pmc_probe(struct platform_device *pdev)
 	if (enable_stb && (dev->cpu_id == AMD_CPU_ID_YC || dev->cpu_id == AMD_CPU_ID_CB)) {
 		err = amd_pmc_s2d_init(dev);
 		if (err)
-			return err;
+			goto err_pci_dev_put;
 	}
 
 	platform_set_drvdata(pdev, dev);