staging: vme_user: fix flush_image leak in tsi148 bridge
Subsystems (3)
PATCH 1/1 staging: vme_user: fix flush_image leak in tsi148 bridge
When error checking is enabled (err_chk=1), tsi148_probe() allocates an extra master window resource, tsi148_device->flush_image, which is used to flush posted writes by reading back over the VME bus. Unlike the regular master windows, this resource is not linked into tsi148_bridge->master_resources.
Because it is not on any resource list, it is freed neither by the probe error path (which only walks the master_resources list) nor by tsi148_remove(), so it is leaked whenever err_chk is set and either probe fails after the allocation or the device is unbound / the module is unloaded.
Free flush_image in both the probe error path and tsi148_remove(). This is safe when err_chk is disabled: tsi148_device is allocated with kzalloc() so flush_image is NULL and kfree(NULL) is a no-op.
--- drivers/staging/vme_user/vme_tsi148.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/staging/vme_user/vme_tsi148.c +3 -0
@@ -2513,6 +2513,7 @@ static int tsi148_probe(struct pci_dev *pdev, const struct pci_device_id *id)list_del (pos);kfree (master_image); } +kfree (tsi148_device->flush_image);tsi148_irq_exit (tsi148_bridge, pdev); err_irq:
@@ -2619,6 +2620,8 @@ static void tsi148_remove(struct pci_dev *pdev)kfree (master_image); } +kfree (bridge->flush_image); +iounmap (bridge->base);pci_release_regions (pdev);
Signature · 1 line
2.25.1
Greg Kroah-Hartman
maintainerQuoted 16 lines · Cong Nguyen
When error checking is enabled (err_chk=1),
tsi148_probe()allocates an extra master window resource,tsi148_device->flush_image, which is used to flush posted writes by reading back over the VME bus. Unlike the regular master windows, this resource is not linked intotsi148_bridge->master_resources.Because it is not on any resource list, it is freed neither by the probe error path (which only walks the
master_resourceslist) nor bytsi148_remove(), so it is leaked whenevererr_chkis set and either probe fails after the allocation or the device is unbound / the module is unloaded.Free
flush_imagein both the probe error path andtsi148_remove(). This is safe whenerr_chkis disabled:tsi148_deviceis allocated withkzalloc()soflush_imageis NULL and kfree(NULL) is a no-op.
Quoted 6 lines
Fixes d22b8ed9a3b0 ("Staging: vme: add Tundra TSI148 VME-PCI Bridge driver")Signed-off-by Cong Nguyen <[email protected]>--- drivers/staging/vme_user/vme_tsi148.c | 3 +++ 1 file changed, 3 insertions(+)
How was this found and tested?
Did you forget an Assisted-by: tag?
thanks,
greg k-h
Quoted 18 lines · Greg Kroah-Hartman
Quoted 16 lines · Cong Nguyen
When error checking is enabled (err_chk=1),
tsi148_probe()allocates an extra master window resource,tsi148_device->flush_image, which is used to flush posted writes by reading back over the VME bus. Unlike the regular master windows, this resource is not linked intotsi148_bridge->master_resources.Because it is not on any resource list, it is freed neither by the probe error path (which only walks the
master_resourceslist) nor bytsi148_remove(), so it is leaked whenevererr_chkis set and either probe fails after the allocation or the device is unbound / the module is unloaded.Free
flush_imagein both the probe error path andtsi148_remove(). This is safe whenerr_chkis disabled:tsi148_deviceis allocated withkzalloc()soflush_imageis NULL and kfree(NULL) is a no-op.
Quoted 8 lines
Quoted 6 lines
Fixes d22b8ed9a3b0 ("Staging: vme: add Tundra TSI148 VME-PCI Bridge driver")Signed-off-by Cong Nguyen <[email protected]>--- drivers/staging/vme_user/vme_tsi148.c | 3 +++ 1 file changed, 3 insertions(+)How was this found and tested?
Code inspection: flush_image is allocated in tsi148_probe() (when err_chk is set) but never added to master_resources, while both the probe error path and tsi148_remove() only free windows on that list. Build-tested only; I have no TSI148 hardware.
Quoted 2 lines
Did you forget an Assisted-by: tag?
Yes, sorry -- found with AI assistance and I missed the tag. I'll send a v2 adding:
Quoted 4 lines
thanks,
greg k-h
Thanks,
Cong