Skip to content

Commit

Permalink
i3c: Fix potential refcount leak in i3c_master_register_new_i3c_devs
Browse files Browse the repository at this point in the history
put_device() needs to be called on failure of device_register()
to give up the reference initialized in it to avoid refcount leak.

Fixes: 3a379bb ("i3c: Add core I3C infrastructure")
Signed-off-by: Dinghao Liu <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Alexandre Belloni <[email protected]>
  • Loading branch information
dinghaoliu authored and alexandrebelloni committed Sep 25, 2023
1 parent fc9176e commit cab63f6
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/i3c/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit cab63f6

Please sign in to comment.