diff mbox series

arch/powerpc/setup: Fix reference count issue in pas_setup_mce_regs()

Message ID 20221116113944.181197-1-wangxiongfeng2@huawei.com (mailing list archive)
State New
Headers show
Series arch/powerpc/setup: Fix reference count issue in pas_setup_mce_regs() | expand

Checks

Context Check Description
snowpatch_ozlabs/github-powerpc_sparse success Successfully ran 4 jobs.
snowpatch_ozlabs/github-powerpc_clang success Successfully ran 6 jobs.
snowpatch_ozlabs/github-powerpc_selftests success Successfully ran 8 jobs.
snowpatch_ozlabs/github-powerpc_ppctests success Successfully ran 8 jobs.

Commit Message

Xiongfeng Wang Nov. 16, 2022, 11:39 a.m. UTC
pci_get_device() will increase the reference count for the returned
pci_dev, and also decrease the reference count for the input parameter
*from* if it is not NULL.

In function pas_setup_mce_regs(), after we break out the loop with 'dev'
not NULL, we need to decrease the reference count of 'dev'. Since
pci_dev_put() can handle the NULL input parameter, we can just add
pci_dev_put() after the loop. Also add pci_dev_put() for another two
pci_get_device().

Fixes: cd7834167ffb ("[POWERPC] pasemi: Print more information at machine check")
Signed-off-by: Xiongfeng Wang <wangxiongfeng2@huawei.com>
---
 arch/powerpc/platforms/pasemi/setup.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox series

Patch

diff --git a/arch/powerpc/platforms/pasemi/setup.c b/arch/powerpc/platforms/pasemi/setup.c
index 2aef49e04dd4..4799b0a7b727 100644
--- a/arch/powerpc/platforms/pasemi/setup.c
+++ b/arch/powerpc/platforms/pasemi/setup.c
@@ -167,6 +167,7 @@  static int __init pas_setup_mce_regs(void)
 		dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa00a, dev);
 		reg++;
 	}
+	pci_dev_put(dev);
 
 	dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
 	if (dev && reg+4 < MAX_MCE_REGS) {
@@ -183,6 +184,7 @@  static int __init pas_setup_mce_regs(void)
 		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0xc1c);
 		reg++;
 	}
+	pci_dev_put(dev);
 
 	dev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa009, NULL);
 	if (dev && reg+2 < MAX_MCE_REGS) {
@@ -193,6 +195,7 @@  static int __init pas_setup_mce_regs(void)
 		mce_regs[reg].addr = pasemi_pci_getcfgaddr(dev, 0x214);
 		reg++;
 	}
+	pci_dev_put(dev);
 
 	num_mce_regs = reg;