Skip to contentSkip to conversation

mmc: sdhci-pci: Fix possible memory leak caused by missing pci_dev_put()

PATCH In review Xiongfeng Wang 2 participants 2 messages Nov 14, 2022 – Nov 16, 2022

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

PATCH 1/1 mmc: sdhci-pci: Fix possible memory leak caused by missing pci_dev_put()

pci_get_device() will increase the reference count for the returned pci_dev. We need to use pci_dev_put() to decrease the reference count before amd_probe() returns. There is no problem for the 'smbus_dev == NULL' branch because pci_dev_put() can also handle the NULL input parameter case.

Fixes 659c9bc114a8 ("mmc: sdhci-pci: Build o2micro support in the same module")
---
 drivers/mmc/host/sdhci-pci-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-pci-core.c +2 -0
index 34ea1acbb3cc..28dc65023fa9 100644
@@ -1749,6 +1749,8 @@ static int amd_probe(struct sdhci_pci_chip *chip)
 		}
 	}
 
+	pci_dev_put(smbus_dev);
+
 	if (gen == AMD_CHIPSET_BEFORE_ML || gen == AMD_CHIPSET_CZ)
 		chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
 
Signature · 1 line
2.20.1
#1 lore raw
Quoted 9 lines · Xiongfeng Wang

pci_get_device() will increase the reference count for the returned pci_dev. We need to use pci_dev_put() to decrease the reference count before amd_probe() returns. There is no problem for the 'smbus_dev == NULL' branch because pci_dev_put() can also handle the NULL input parameter case.

Fixes 659c9bc114a8 ("mmc: sdhci-pci: Build o2micro support in the same module")

Applied for fixes and by adding a stable tag, thanks!

Kind regards
Uffe

Quoted 20 lines
---
 drivers/mmc/host/sdhci-pci-core.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/mmc/host/sdhci-pci-core.c +2 -1
index 34ea1acbb3cc..28dc65023fa9 100644
@@ -1749,6 +1749,8 @@ static int amd_probe(struct sdhci_pci_chip *chip)
                }
        }
 
+       pci_dev_put(smbus_dev);
+
        if (gen == AMD_CHIPSET_BEFORE_ML || gen == AMD_CHIPSET_CZ)
                chip->quirks2 |= SDHCI_QUIRK2_CLEAR_TRANSFERMODE_REG_BEFORE_CMD;
 
--

2.20.1