]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers()
authorFelix Gu <ustc.gu@gmail.com>
Mon, 6 Apr 2026 12:43:16 +0000 (20:43 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Sun, 12 Apr 2026 14:47:13 +0000 (16:47 +0200)
The xfer structure allocated by renesas_i3c_alloc_xfer() was never freed
in the renesas_i3c_i3c_xfers() function. Use the __free(kfree) cleanup
attribute to automatically free the memory when the variable goes out of
scope.

Fixes: d028219a9f14 ("i3c: master: Add basic driver for the Renesas I3C controller")
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Reviewed-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
Link: https://patch.msgid.link/20260406-renesas-v3-1-4b724d7708f4@gmail.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/i3c/master/renesas-i3c.c

index d9f5b30a4b2f3a561f6ef3aed5dace08e0b93dfd..a8a9e89a9710ab70c6a8717c9cf2d3d961201d24 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/bitfield.h>
 #include <linux/bitops.h>
+#include <linux/cleanup.h>
 #include <linux/clk.h>
 #include <linux/completion.h>
 #include <linux/err.h>
@@ -817,13 +818,12 @@ static int renesas_i3c_i3c_xfers(struct i3c_dev_desc *dev, struct i3c_xfer *i3c_
        struct i3c_master_controller *m = i3c_dev_get_master(dev);
        struct renesas_i3c *i3c = to_renesas_i3c(m);
        struct renesas_i3c_i2c_dev_data *data = i3c_dev_get_master_data(dev);
-       struct renesas_i3c_xfer *xfer;
        int i;
 
        /* Enable I3C bus. */
        renesas_i3c_bus_enable(m, true);
 
-       xfer = renesas_i3c_alloc_xfer(i3c, 1);
+       struct renesas_i3c_xfer *xfer __free(kfree) = renesas_i3c_alloc_xfer(i3c, 1);
        if (!xfer)
                return -ENOMEM;