Skip to contentSkip to conversation

i2c: core: fix use after free in of_i2c_notify

PATCH Applied Wen Yang 2 participants 2 messages Nov 8, 2019 – Nov 15, 2019

Subsystems (2)
lore
Share & tools
lore

Wen Yang

author
#0 lore raw

PATCH 1/1 i2c: core: fix use after free in of_i2c_notify

We can't use "adap" after it has been freed.

Fixes 5bf4fa7daea6 ("i2c: break out OF support into separate file")
Cc Wolfram Sang <[email protected]>
---
 drivers/i2c/i2c-core-of.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/i2c-core-of.c +2 -2
index 6f632d54..7eb4199 100644
@@ -245,14 +245,14 @@ static int of_i2c_notify(struct notifier_block *nb, unsigned long action,
 		}
 
 		client = of_i2c_register_device(adap, rd->dn);
-		put_device(&adap->dev);
-
 		if (IS_ERR(client)) {
 			dev_err(&adap->dev, "failed to create client for '%pOF'\n",
 				 rd->dn);
+			put_device(&adap->dev);
 			of_node_clear_flag(rd->dn, OF_POPULATED);
 			return notifier_from_errno(PTR_ERR(client));
 		}
+		put_device(&adap->dev);
 		break;
 	case OF_RECONFIG_CHANGE_REMOVE:
 		/* already depopulated? */
Signature · 1 line
1.8.3.1