mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-07-22 08:07:32 -04:00
i2c: core: fix NULL-deref on adapter registration failure
If adapter registration ever fails the release callback would trigger a
NULL-pointer dereference as the completion struct has not been
initialised.
Note that before the offending commit this would instead have resulted
in a minor memory leak of the adapter name.
Fixes: 3f8c4f5e9a ("i2c: core: fix reference leak in i2c_register_adapter()")
Cc: stable@vger.kernel.org
Cc: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Signed-off-by: Johan Hovold <johan@kernel.org>
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
This commit is contained in:
committed by
Wolfram Sang
parent
3c7e164344
commit
2295d2bb10
@@ -1574,8 +1574,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
|
||||
res = device_add(&adap->dev);
|
||||
if (res) {
|
||||
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
|
||||
put_device(&adap->dev);
|
||||
goto err_remove_irq_domain;
|
||||
goto err_put_adap;
|
||||
}
|
||||
|
||||
adap->debugfs = debugfs_create_dir(dev_name(&adap->dev), i2c_debugfs_root);
|
||||
@@ -1608,10 +1607,12 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
|
||||
out_reg:
|
||||
i2c_deregister_clients(adap);
|
||||
debugfs_remove_recursive(adap->debugfs);
|
||||
device_del(&adap->dev);
|
||||
err_put_adap:
|
||||
init_completion(&adap->dev_released);
|
||||
device_unregister(&adap->dev);
|
||||
put_device(&adap->dev);
|
||||
wait_for_completion(&adap->dev_released);
|
||||
err_remove_irq_domain:
|
||||
|
||||
i2c_host_notify_irq_teardown(adap);
|
||||
out_list:
|
||||
mutex_lock(&core_lock);
|
||||
|
||||
Reference in New Issue
Block a user