Skip to content

Commit 3f8c4f5

Browse files
joehattoriWolfram Sang
authored andcommitted
i2c: core: fix reference leak in i2c_register_adapter()
The reference count of the device incremented in device_initialize() is not decremented when device_add() fails. Add a put_device() call before returning from the function. This bug was found by an experimental static analysis tool that I am developing. Fixes: 60f6859 ("i2c: core: Setup i2c_adapter runtime-pm before calling device_add()") Signed-off-by: Joe Hattori <joe@pf.is.s.u-tokyo.ac.jp> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
1 parent 9d89551 commit 3f8c4f5

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/i2c/i2c-core-base.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
15621562
res = device_add(&adap->dev);
15631563
if (res) {
15641564
pr_err("adapter '%s': can't register device (%d)\n", adap->name, res);
1565+
put_device(&adap->dev);
15651566
goto out_list;
15661567
}
15671568

0 commit comments

Comments
 (0)