Skip to contentSkip to conversation

watchdog: sp5100_tco: Fix PCI device refcount leak

PATCH In review Xiongfeng Wang 2 participants 2 messages Nov 22, 2022 – Nov 23, 2022 Watchdog device drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 watchdog: sp5100_tco: Fix PCI device refcount leak

for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL.

If we break out for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. Add the missing pci_dev_put() in error path of sp5100_tco_init() and also when we unload module.

Fixes 15e28bf13008 ("watchdog: Add support for sp5100 chipset TCO")
---
 drivers/watchdog/sp5100_tco.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/watchdog/sp5100_tco.c +4 -1
index fb426b7d81da..f00f26f90444 100644
@@ -599,7 +599,7 @@ static int __init sp5100_tco_init(void)
 
 	err = platform_driver_register(&sp5100_tco_driver);
 	if (err)
-		return err;
+		goto put_dev;
 
 	sp5100_tco_platform_device =
 		platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0);
@@ -612,6 +612,8 @@ static int __init sp5100_tco_init(void)
 
 unreg_platform_driver:
 	platform_driver_unregister(&sp5100_tco_driver);
+put_dev:
+	pci_dev_put(sp5100_tco_pci);
 	return err;
 }
 
@@ -619,6 +621,7 @@ static void __exit sp5100_tco_exit(void)
 {
 	platform_device_unregister(sp5100_tco_platform_device);
 	platform_driver_unregister(&sp5100_tco_driver);
+	pci_dev_put(sp5100_tco_pci);
 }
 
 module_init(sp5100_tco_init);
Signature · 1 line
2.20.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Xiongfeng Wang

for_each_pci_dev() is implemented by pci_get_device(). The comment of pci_get_device() says that it will increase the reference count for the returned pci_dev and also decrease the reference count for the input pci_dev @from if it is not NULL.

Quoted 7 lines

If we break out for_each_pci_dev() loop with pdev not NULL, we need to call pci_dev_put() to decrease the reference count. Add the missing pci_dev_put() in error path of sp5100_tco_init() and also when we unload module.

Fixes 15e28bf13008 ("watchdog: Add support for sp5100 chipset TCO")
Quoted 37 lines
---
 drivers/watchdog/sp5100_tco.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/watchdog/sp5100_tco.c +4 -1
index fb426b7d81da..f00f26f90444 100644
@@ -599,7 +599,7 @@ static int __init sp5100_tco_init(void)
 
 	err = platform_driver_register(&sp5100_tco_driver);
 	if (err)
-		return err;
+		goto put_dev;
 
 	sp5100_tco_platform_device =
 		platform_device_register_simple(TCO_DRIVER_NAME, -1, NULL, 0);
@@ -612,6 +612,8 @@ static int __init sp5100_tco_init(void)
 
 unreg_platform_driver:
 	platform_driver_unregister(&sp5100_tco_driver);
+put_dev:
+	pci_dev_put(sp5100_tco_pci);
 	return err;
 }
 
@@ -619,6 +621,7 @@ static void __exit sp5100_tco_exit(void)
 {
 	platform_device_unregister(sp5100_tco_platform_device);
 	platform_driver_unregister(&sp5100_tco_driver);
+	pci_dev_put(sp5100_tco_pci);
 }
 
 module_init(sp5100_tco_init);
Signature · 1 line
2.20.1