Skip to content

Commit b5a2893

Browse files
outman119gregkh
authored andcommitted
i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers()
[ Upstream commit 256cc1f ] The dw_i3c_master_i3c_xfers() function allocates memory for the xfer structure using dw_i3c_master_alloc_xfer(). If pm_runtime_resume_and_get() fails, the function returns without freeing the allocated xfer, resulting in a memory leak. Since dw_i3c_master_free_xfer() is a thin wrapper around kfree(), use the __free(kfree) cleanup attribute to handle the free automatically on all exit paths. Fixes: 62fe9d0 ("i3c: dw: Add power management support") Signed-off-by: Felix Gu <ustc.gu@gmail.com> Reviewed-by: Frank Li <Frank.Li@nxp.com> Link: https://patch.msgid.link/20260404-dw-i3c-2-v3-1-8f7d146549c1@gmail.com Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 1b6a7e9 commit b5a2893

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

drivers/i3c/master/dw-i3c-master.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <linux/bitops.h>
9+
#include <linux/cleanup.h>
910
#include <linux/clk.h>
1011
#include <linux/completion.h>
1112
#include <linux/err.h>
@@ -905,7 +906,6 @@ static int dw_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
905906
struct i3c_master_controller *m = i3c_dev_get_master(dev);
906907
struct dw_i3c_master *master = to_dw_i3c_master(m);
907908
unsigned int nrxwords = 0, ntxwords = 0;
908-
struct dw_i3c_xfer *xfer;
909909
int i, ret = 0;
910910

911911
if (!i3c_nxfers)
@@ -925,7 +925,7 @@ static int dw_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
925925
nrxwords > master->caps.datafifodepth)
926926
return -EOPNOTSUPP;
927927

928-
xfer = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
928+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
929929
if (!xfer)
930930
return -ENOMEM;
931931

@@ -976,7 +976,6 @@ static int dw_i3c_master_priv_xfers(struct i3c_dev_desc *dev,
976976
}
977977

978978
ret = xfer->ret;
979-
dw_i3c_master_free_xfer(xfer);
980979

981980
pm_runtime_put_autosuspend(master->dev);
982981
return ret;

0 commit comments

Comments
 (0)