i3c: Fix potential refcount leak in i3c_master_register_new_i3c_devs
authorDinghao Liu <dinghao.liu@zju.edu.cn>
Thu, 21 Sep 2023 08:24:10 +0000 (16:24 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Mon, 25 Sep 2023 21:45:10 +0000 (23:45 +0200)
put_device() needs to be called on failure of device_register()
to give up the reference initialized in it to avoid refcount leak.

Fixes: 3a379bbcea0a ("i3c: Add core I3C infrastructure")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Link: https://lore.kernel.org/r/20230921082410.25548-1-dinghao.liu@zju.edu.cn
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/i3c/master.c

index 839eb8b4bbdec94d103e85760aa411d782d794af..e66a1f84cefbcefdb88bc1864013508c7c5afd0a 100644 (file)
@@ -1525,9 +1525,11 @@ i3c_master_register_new_i3c_devs(struct i3c_master_controller *master)
                        desc->dev->dev.of_node = desc->boardinfo->of_node;
 
                ret = device_register(&desc->dev->dev);
-               if (ret)
+               if (ret) {
                        dev_err(&master->dev,
                                "Failed to add I3C device (err = %d)\n", ret);
+                       put_device(&desc->dev->dev);
+               }
        }
 }