Commit e4c72c06 authored by Xu Wang's avatar Xu Wang Committed by Wolfram Sang

i2c: Fix a potential use after free

Free the adap structure only after we are done using it.
This patch just moves the put_device() down a bit to avoid the
use after free.

Fixes: 611e12ea ("i2c: core: manage i2c bus device refcount in i2c_[get|put]_adapter")
Signed-off-by: default avatarXu Wang <vulab@iscas.ac.cn>
[wsa: added comment to the code, added Fixes tag]
Signed-off-by: default avatarWolfram Sang <wsa@kernel.org>
parent 4dc1372f
......@@ -2461,8 +2461,9 @@ void i2c_put_adapter(struct i2c_adapter *adap)
if (!adap)
return;
put_device(&adap->dev);
module_put(adap->owner);
/* Should be last, otherwise we risk use-after-free with 'adap' */
put_device(&adap->dev);
}
EXPORT_SYMBOL(i2c_put_adapter);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment