public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] i2c: amd-mp2: fix device leak on probe()
@ 2025-11-21 11:37 Johan Hovold
  0 siblings, 0 replies; only message in thread
From: Johan Hovold @ 2025-11-21 11:37 UTC (permalink / raw)
  To: Elie Morisse, Shyam Sundar S K, Andi Shyti
  Cc: Wolfram Sang, linux-i2c, linux-kernel, Johan Hovold, stable

Make sure to drop the reference taken to the PCI device when looking up
its driver data during probe of the platform device.

Note that holding a reference to a device does not prevent its driver
data from going away so there is no point in keeping the reference.

Fixes: 529766e0a011 ("i2c: Add drivers for the AMD PCIe MP2 I2C controller")
Cc: stable@vger.kernel.org	# 5.2
Cc: Elie Morisse <syniurge@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/i2c/busses/i2c-amd-mp2-pci.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-pci.c b/drivers/i2c/busses/i2c-amd-mp2-pci.c
index ef7370d3dbea..5b41d18b62d3 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-pci.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-pci.c
@@ -456,6 +456,7 @@ module_pci_driver(amd_mp2_pci_driver);
 
 struct amd_mp2_dev *amd_mp2_find_device(void)
 {
+	struct amd_mp2_dev *privdata;
 	struct device *dev;
 	struct pci_dev *pci_dev;
 
@@ -464,7 +465,11 @@ struct amd_mp2_dev *amd_mp2_find_device(void)
 		return NULL;
 
 	pci_dev = to_pci_dev(dev);
-	return (struct amd_mp2_dev *)pci_get_drvdata(pci_dev);
+	privdata = pci_get_drvdata(pci_dev);
+
+	put_device(dev);
+
+	return privdata;
 }
 EXPORT_SYMBOL_GPL(amd_mp2_find_device);
 
-- 
2.51.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-11-21 11:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 11:37 [PATCH] i2c: amd-mp2: fix device leak on probe() Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox