]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i2c: amd-mp2: fix reference leak in MP2 PCI device
authorMa Ke <make24@iscas.ac.cn>
Wed, 22 Oct 2025 09:54:02 +0000 (17:54 +0800)
committerAndi Shyti <andi.shyti@kernel.org>
Mon, 8 Dec 2025 02:11:27 +0000 (03:11 +0100)
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: 529766e0a011 ("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
drivers/i2c/busses/i2c-amd-mp2-pci.c

index ef7370d3dbea318a8265f8014a46a94ba5b29aad..60edbabc2986be0f3a87ab0b84fe0c4ad59459c0 100644 (file)
@@ -458,13 +458,16 @@ struct amd_mp2_dev *amd_mp2_find_device(void)
 {
        struct device *dev;
        struct pci_dev *pci_dev;
+       struct amd_mp2_dev *mp2_dev;
 
        dev = driver_find_next_device(&amd_mp2_pci_driver.driver, NULL);
        if (!dev)
                return NULL;
 
        pci_dev = to_pci_dev(dev);
-       return (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
+       mp2_dev = (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
+       put_device(dev);
+       return mp2_dev;
 }
 EXPORT_SYMBOL_GPL(amd_mp2_find_device);