i2c: core: fix use after free in of_i2c_notify
authorWen Yang <wenyang@linux.alibaba.com>
Fri, 8 Nov 2019 08:36:48 +0000 (16:36 +0800)
committerWolfram Sang <wsa@the-dreams.de>
Fri, 15 Nov 2019 21:01:13 +0000 (22:01 +0100)
We can't use "adap->dev" after it has been freed.

Fixes: 5bf4fa7daea6 ("i2c: break out OF support into separate file")
Signed-off-by: Wen Yang <wenyang@linux.alibaba.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
drivers/i2c/i2c-core-of.c

index 6f632d543fcc1f569184fce28f737c4d8436206a..7eb41990bd6deff1271c388395614c7d85fa54ad 100644 (file)
@@ -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? */