Skip to content

Commit 256cc1f

Browse files
outman119alexandrebelloni
authored andcommitted
i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers()
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>
1 parent 57c91ca commit 256cc1f

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
@@ -7,6 +7,7 @@
77

88
#include <linux/bitfield.h>
99
#include <linux/bitops.h>
10+
#include <linux/cleanup.h>
1011
#include <linux/clk.h>
1112
#include <linux/completion.h>
1213
#include <linux/err.h>
@@ -924,7 +925,6 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
924925
struct i3c_master_controller *m = i3c_dev_get_master(dev);
925926
struct dw_i3c_master *master = to_dw_i3c_master(m);
926927
unsigned int nrxwords = 0, ntxwords = 0;
927-
struct dw_i3c_xfer *xfer;
928928
int i, ret = 0;
929929

930930
if (!i3c_nxfers)
@@ -944,7 +944,7 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
944944
nrxwords > master->caps.datafifodepth)
945945
return -EOPNOTSUPP;
946946

947-
xfer = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
947+
struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
948948
if (!xfer)
949949
return -ENOMEM;
950950

@@ -995,7 +995,6 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
995995
}
996996

997997
ret = xfer->ret;
998-
dw_i3c_master_free_xfer(xfer);
999998

1000999
pm_runtime_put_autosuspend(master->dev);
10011000
return ret;

0 commit comments

Comments
 (0)