Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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: 62fe9d06f570 ("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>

authored by

Felix Gu and committed by
Alexandre Belloni
256cc1f1 57c91ca3

+2 -3
+2 -3
drivers/i3c/master/dw-i3c-master.c
··· 7 7 8 8 #include <linux/bitfield.h> 9 9 #include <linux/bitops.h> 10 + #include <linux/cleanup.h> 10 11 #include <linux/clk.h> 11 12 #include <linux/completion.h> 12 13 #include <linux/err.h> ··· 925 924 struct i3c_master_controller *m = i3c_dev_get_master(dev); 926 925 struct dw_i3c_master *master = to_dw_i3c_master(m); 927 926 unsigned int nrxwords = 0, ntxwords = 0; 928 - struct dw_i3c_xfer *xfer; 929 927 int i, ret = 0; 930 928 931 929 if (!i3c_nxfers) ··· 944 944 nrxwords > master->caps.datafifodepth) 945 945 return -EOPNOTSUPP; 946 946 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); 948 948 if (!xfer) 949 949 return -ENOMEM; 950 950 ··· 995 995 } 996 996 997 997 ret = xfer->ret; 998 - dw_i3c_master_free_xfer(xfer); 999 998 1000 999 pm_runtime_put_autosuspend(master->dev); 1001 1000 return ret;