[PATCH] i2c: amd-mp2: Unregister callback on adapter add failure

Myeonghun Pak posted 1 patch 3 days, 9 hours ago
drivers/i2c/busses/i2c-amd-mp2-plat.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] i2c: amd-mp2: Unregister callback on adapter add failure
Posted by Myeonghun Pak 3 days, 9 hours ago
amd_mp2_register_cb() stores the platform I2C context in the MP2 PCI
driver's callback table before the adapter is registered. If
i2c_add_adapter() fails, probe returns and devres frees the context,
but the PCI driver can still dereference the stale pointer from its IRQ
and system-sleep callbacks.

Unregister the callback before returning the adapter registration error.

Fixes: 529766e0a011 ("i2c: Add drivers for the AMD PCIe MP2 I2C controller")
Cc: stable@vger.kernel.org
Co-developed-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Ijae Kim <ae878000@gmail.com>
Signed-off-by: Myeonghun Pak <mhun512@gmail.com>
---
 drivers/i2c/busses/i2c-amd-mp2-plat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/busses/i2c-amd-mp2-plat.c b/drivers/i2c/busses/i2c-amd-mp2-plat.c
index 188e24cc4d..9fdd6a5fb8 100644
--- a/drivers/i2c/busses/i2c-amd-mp2-plat.c
+++ b/drivers/i2c/busses/i2c-amd-mp2-plat.c
@@ -316,8 +316,10 @@ static int i2c_amd_probe(struct platform_device *pdev)
 
 	amd_mp2_pm_runtime_put(mp2_dev);
 
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(&pdev->dev, "i2c add adapter failed = %d\n", ret);
+		amd_mp2_unregister_cb(&i2c_dev->common);
+	}
 
 	return ret;
 }
-- 
2.47.1
Re: [PATCH] i2c: amd-mp2: Unregister callback on adapter add failure
Posted by Andi Shyti an hour ago
Hi Myeonghun,

On Tue, Jul 21, 2026 at 11:41:47PM +0900, Myeonghun Pak wrote:
> amd_mp2_register_cb() stores the platform I2C context in the MP2 PCI
> driver's callback table before the adapter is registered. If
> i2c_add_adapter() fails, probe returns and devres frees the context,
> but the PCI driver can still dereference the stale pointer from its IRQ
> and system-sleep callbacks.
> 
> Unregister the callback before returning the adapter registration error.
> 
> Fixes: 529766e0a011 ("i2c: Add drivers for the AMD PCIe MP2 I2C controller")
> Cc: stable@vger.kernel.org
> Co-developed-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Ijae Kim <ae878000@gmail.com>
> Signed-off-by: Myeonghun Pak <mhun512@gmail.com>

merged to i2c/i2c-fixes.

Thanks,
Andi