gpib: tnt4882: Fix device reference leak in mite_init()
Subsystems (2)
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.
--- drivers/gpib/tnt4882/mite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpib/tnt4882/mite.c +3 -1
@@ -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
Quoted 20 lines · Wentao Liang
In
mite_init(), eachpci_get_device()iteration returns a new reference to a National Instruments PCI device, which is consumed by the next iteration. Ifkzalloc_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")Signed-off-by Wentao Liang <[email protected]>--- drivers/gpib/tnt4882/mite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpib/tnt4882/mite.c +0
-0@@ -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
-1pcidev = 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