Skip to contentSkip to conversation

i2c: amd-mp2: Unregister callback on adapter add failure

PATCH Applied Myeonghun Pak 2 participants 2 messages Jul 21 – Jul 24

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

PATCH 1/1 i2c: amd-mp2: Unregister callback on adapter add failure

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")
---
 drivers/i2c/busses/i2c-amd-mp2-plat.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/i2c/busses/i2c-amd-mp2-plat.c +3 -1
index 188e24cc4d..9fdd6a5fb8 100644
@@ -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;
 }
Signature · 1 line
2.47.1
maintainer Applied
#1 lore raw

Hi Myeonghun,

Quoted 6 lines · Myeonghun Pak

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.

Quoted 7 lines

Unregister the callback before returning the adapter registration error.

Fixes 529766e0a011 ("i2c: Add drivers for the AMD PCIe MP2 I2C controller")

merged to i2c/i2c-fixes.

Thanks,
Andi