Skip to content

Commit a6ee6aa

Browse files
Ma KeAndi Shyti
authored andcommitted
i2c: amd-mp2: fix reference leak in MP2 PCI device
In i2c_amd_probe(), amd_mp2_find_device() utilizes driver_find_next_device() which internally calls driver_find_device() to locate the matching device. driver_find_device() increments the reference count of the found device by calling get_device(), but amd_mp2_find_device() fails to call put_device() to decrement the reference count before returning. This results in a reference count leak of the PCI device each time i2c_amd_probe() is executed, which may prevent the device from being properly released and cause a memory leak. Found by code review. Cc: stable@vger.kernel.org Fixes: 529766e ("i2c: Add drivers for the AMD PCIe MP2 I2C controller") Signed-off-by: Ma Ke <make24@iscas.ac.cn> Signed-off-by: Andi Shyti <andi.shyti@kernel.org> Link: https://lore.kernel.org/r/20251022095402.8846-1-make24@iscas.ac.cn
1 parent eeaaf5b commit a6ee6aa

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/i2c/busses/i2c-amd-mp2-pci.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,13 +458,16 @@ struct amd_mp2_dev *amd_mp2_find_device(void)
458458
{
459459
struct device *dev;
460460
struct pci_dev *pci_dev;
461+
struct amd_mp2_dev *mp2_dev;
461462

462463
dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
463464
if (!dev)
464465
return NULL;
465466

466467
pci_dev = to_pci_dev(dev);
467-
return (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
468+
mp2_dev = (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
469+
put_device(dev);
470+
return mp2_dev;
468471
}
469472
EXPORT_SYMBOL_GPL(amd_mp2_find_device);
470473

0 commit comments

Comments
 (0)