]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
i2c: core: fix reference leak in i2c_register_adapter()
authorJoe Hattori <joe@pf.is.s.u-tokyo.ac.jp>
Wed, 11 Dec 2024 03:08:03 +0000 (12:08 +0900)
committerWolfram Sang <wsa+renesas@sang-engineering.com>
Thu, 9 Jan 2025 10:02:31 +0000 (11:02 +0100)
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: 60f68597024d ("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>
drivers/i2c/i2c-core-base.c

index 7c810893bfa332721d242f6c4a83f6217f22a6fc..75d30861ffe21a5983ffa9d1b018999b20c226f0 100644 (file)
@@ -1562,6 +1562,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 out_list;
        }