i2c: core: decrease reference count of device node in i2c_unregister_device
authorLixin Wang <alan.1.wang@nokia-sbell.com>
Mon, 27 Nov 2017 07:06:55 +0000 (15:06 +0800)
committerWolfram Sang <wsa@the-dreams.de>
Wed, 17 Jan 2018 14:23:31 +0000 (15:23 +0100)
Reference count of device node was increased in of_i2c_register_device,
but without decreasing it in i2c_unregister_device. Then the added
device node will never be released. Fix this by adding the of_node_put.

Signed-off-by: Lixin Wang <alan.1.wang@nokia-sbell.com>
Tested-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Cc: stable@kernel.org
drivers/i2c/i2c-core-base.c

index 706164b4c5be46bf2f98aa5a8ddde44800eeae0e..f7829a74140cf1b764d8ed3f8e00ec4e60f9eaad 100644 (file)
@@ -821,8 +821,12 @@ void i2c_unregister_device(struct i2c_client *client)
 {
        if (!client)
                return;
-       if (client->dev.of_node)
+
+       if (client->dev.of_node) {
                of_node_clear_flag(client->dev.of_node, OF_POPULATED);
+               of_node_put(client->dev.of_node);
+       }
+
        if (ACPI_COMPANION(&client->dev))
                acpi_device_clear_enumerated(ACPI_COMPANION(&client->dev));
        device_unregister(&client->dev);