* [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers()
@ 2026-04-02 14:52 Felix Gu
2026-04-03 2:53 ` Frank Li
2026-04-03 8:14 ` Tommaso Merciai
0 siblings, 2 replies; 3+ messages in thread
From: Felix Gu @ 2026-04-02 14:52 UTC (permalink / raw)
To: Wolfram Sang, Tommaso Merciai, Alexandre Belloni, Frank Li
Cc: linux-i3c, linux-kernel, Felix Gu
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")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
Changes in v2:
- Add cleanup header file to fix Frank's comment.
- Link to v1: https://lore.kernel.org/r/20260402-renesas-v1-1-369a7d867502@gmail.com
---
drivers/i3c/master/renesas-i3c.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
index d9f5b30a4b2f..a8a9e89a9710 100644
--- a/drivers/i3c/master/renesas-i3c.c
+++ b/drivers/i3c/master/renesas-i3c.c
@@ -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;
---
base-commit: bd0f139e5fc11182777b81cefc3893ea508544ec
change-id: 20260402-renesas-c6afdaf9bc2e
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers()
2026-04-02 14:52 [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers() Felix Gu
@ 2026-04-03 2:53 ` Frank Li
2026-04-03 8:14 ` Tommaso Merciai
1 sibling, 0 replies; 3+ messages in thread
From: Frank Li @ 2026-04-03 2:53 UTC (permalink / raw)
To: Felix Gu
Cc: Wolfram Sang, Tommaso Merciai, Alexandre Belloni, linux-i3c,
linux-kernel
On Thu, Apr 02, 2026 at 10:52:26PM +0800, Felix Gu wrote:
> 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")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Changes in v2:
> - Add cleanup header file to fix Frank's comment.
> - Link to v1: https://lore.kernel.org/r/20260402-renesas-v1-1-369a7d867502@gmail.com
> ---
> drivers/i3c/master/renesas-i3c.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
> index d9f5b30a4b2f..a8a9e89a9710 100644
> --- a/drivers/i3c/master/renesas-i3c.c
> +++ b/drivers/i3c/master/renesas-i3c.c
> @@ -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;
>
>
> ---
> base-commit: bd0f139e5fc11182777b81cefc3893ea508544ec
> change-id: 20260402-renesas-c6afdaf9bc2e
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers()
2026-04-02 14:52 [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers() Felix Gu
2026-04-03 2:53 ` Frank Li
@ 2026-04-03 8:14 ` Tommaso Merciai
1 sibling, 0 replies; 3+ messages in thread
From: Tommaso Merciai @ 2026-04-03 8:14 UTC (permalink / raw)
To: Felix Gu; +Cc: Wolfram Sang, Alexandre Belloni, Frank Li, linux-i3c,
linux-kernel
Hi Felix,
Thanks for your patch!
On Thu, Apr 02, 2026 at 10:52:26PM +0800, Felix Gu wrote:
> 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.
>
Tested on RZ/G3E + NXP P3T1085UK board.
Tested-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Reviewed-by: Tommaso Merciai <tommaso.merciai.xr@bp.renesas.com>
Kind Regards,
Tommaso
> Fixes: d028219a9f14 ("i3c: master: Add basic driver for the Renesas I3C controller")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
> ---
> Changes in v2:
> - Add cleanup header file to fix Frank's comment.
> - Link to v1: https://lore.kernel.org/r/20260402-renesas-v1-1-369a7d867502@gmail.com
> ---
> drivers/i3c/master/renesas-i3c.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/i3c/master/renesas-i3c.c b/drivers/i3c/master/renesas-i3c.c
> index d9f5b30a4b2f..a8a9e89a9710 100644
> --- a/drivers/i3c/master/renesas-i3c.c
> +++ b/drivers/i3c/master/renesas-i3c.c
> @@ -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;
>
>
> ---
> base-commit: bd0f139e5fc11182777b81cefc3893ea508544ec
> change-id: 20260402-renesas-c6afdaf9bc2e
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-03 8:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 14:52 [PATCH v2] i3c: master: renesas: Fix memory leak in renesas_i3c_i3c_xfers() Felix Gu
2026-04-03 2:53 ` Frank Li
2026-04-03 8:14 ` Tommaso Merciai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox