Skip to contentSkip to conversation

gpib: tnt4882: Fix device reference leak in mite_init()

PATCH In review Wentao Liang 2 participants 2 messages Sep 16 – Sep 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpib: tnt4882: Fix device reference leak in mite_init()

In mite_init(), each pci_get_device() iteration returns a new reference to a National Instruments PCI device, which is consumed by the next iteration. If kzalloc_obj() fails, the function returns without consuming or putting that reference, leaking it.

Put the device reference before returning when the allocation fails.

Fixes 0cd5b05551e0 ("staging: gpib: Add TNT4882 chip based GPIB driver")
---
 drivers/gpib/tnt4882/mite.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpib/tnt4882/mite.c +3 -1
index c75c45cdf03f..3e411653ffc7 100644
@@ -58,8 +58,10 @@ void mite_init(void)
 		pcidev;
 		pcidev = pci_get_device(PCI_VENDOR_ID_NATINST, PCI_ANY_ID, pcidev)) {
 		mite = kzalloc_obj(*mite);
-		if (!mite)
+		if (!mite) {
+			pci_dev_put(pcidev);
 			return;
+		}
 
 		mite->pcidev = pcidev;
 		pci_dev_get(mite->pcidev);
Signature · 1 line
2.34.1
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Wentao Liang

In mite_init(), each pci_get_device() iteration returns a new reference to a National Instruments PCI device, which is consumed by the next iteration. If kzalloc_obj() fails, the function returns without consuming or putting that reference, leaking it.

Put the device reference before returning when the allocation fails.

Fixes 0cd5b05551e0 ("staging: gpib: Add TNT4882 chip based GPIB driver")
---
 drivers/gpib/tnt4882/mite.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpib/tnt4882/mite.c +0 -0
index c75c45cdf03f..3e411653ffc7 100644
@@ -58,8 +58,10 @@ void mite_init(void)
 		pcidev;

drivers/gpib/tnt4882/mite.c void mite_init(void) · line 67

Quoted 10 lines
drivers/gpib/tnt4882/mite.c +3 -1
 		pcidev = pci_get_device(PCI_VENDOR_ID_NATINST, PCI_ANY_ID, pcidev)) {
 		mite = kzalloc_obj(*mite);
-		if (!mite)
+		if (!mite) {
+			pci_dev_put(pcidev);
 			return;
+		}
 
 		mite->pcidev = pcidev;
 		pci_dev_get(mite->pcidev);

thanks

Quoted 3 lines
Signature · 1 line
2.34.1