summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDinghao Liu <dinghao.liu@zju.edu.cn>2023-09-21 16:24:10 +0800
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2023-09-25 23:45:10 +0200
commitcab63f64887616e3c4e31cfd8103320be6ebc8d3 (patch)
tree64028770e0bdda4f25bb55e08d5ae063a7cb40d5
parentfc9176e794d74baccb1e4ef41894ac141f524992 (diff)
downloadlinux-stable-cab63f64887616e3c4e31cfd8103320be6ebc8d3.tar.gz
linux-stable-cab63f64887616e3c4e31cfd8103320be6ebc8d3.tar.bz2
linux-stable-cab63f64887616e3c4e31cfd8103320be6ebc8d3.zip
i3c: Fix potential refcount leak in i3c_master_register_new_i3c_devs
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>
-rw-r--r--drivers/i3c/master.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
index 839eb8b4bbde..e66a1f84cefb 100644
--- a/drivers/i3c/master.c
+++ b/drivers/i3c/master.c
@@ -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);
+ }
}
}