* [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
@ 2026-01-26 8:11 Zilin Guan
2026-01-26 10:22 ` Markus Elfring
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Zilin Guan @ 2026-01-26 8:11 UTC (permalink / raw)
To: alexandre.belloni
Cc: Frank.Li, aniketmaurya, linux-i3c, linux-kernel, jianhao.xu,
Zilin Guan
The dw_i3c_master_i2c_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.
Add a dw_i3c_master_free_xfer() call to the error path to ensure the
allocated memory is properly freed.
Compile tested only. Issue found using a prototype static analysis tool
and code review.
Fixes: 62fe9d06f570 ("i3c: dw: Add power management support")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
drivers/i3c/master/dw-i3c-master.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
index 889e2ed5bc83..3e6f66dff2ec 100644
--- a/drivers/i3c/master/dw-i3c-master.c
+++ b/drivers/i3c/master/dw-i3c-master.c
@@ -1099,6 +1099,7 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
dev_err(master->dev,
"<%s> cannot resume i3c bus master, err: %d\n",
__func__, ret);
+ dw_i3c_master_free_xfer(xfer);
return ret;
}
--
2.34.1
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
2026-01-26 8:11 [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers() Zilin Guan
@ 2026-01-26 10:22 ` Markus Elfring
2026-01-26 17:01 ` Frank Li
2026-01-30 23:08 ` Alexandre Belloni
2 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-01-26 10:22 UTC (permalink / raw)
To: Zilin Guan, linux-i3c, Alexandre Belloni
Cc: LKML, Aniket, Frank Li, Jianhao Xu
…
> Add a dw_i3c_master_free_xfer() call to the error path to ensure the
> allocated memory is properly freed.
…
https://elixir.bootlin.com/linux/v6.19-rc5/source/drivers/i3c/master/dw-i3c-master.c#L1065-L1137
* Would you like to complete the exception handling by using another goto chain?
* How do you think about to increase the application of scope-based resource management?
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19-rc7#n34
Regards,
Markus
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
2026-01-26 8:11 [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers() Zilin Guan
2026-01-26 10:22 ` Markus Elfring
@ 2026-01-26 17:01 ` Frank Li
2026-01-30 23:08 ` Alexandre Belloni
2 siblings, 0 replies; 4+ messages in thread
From: Frank Li @ 2026-01-26 17:01 UTC (permalink / raw)
To: Zilin Guan
Cc: alexandre.belloni, aniketmaurya, linux-i3c, linux-kernel,
jianhao.xu
On Mon, Jan 26, 2026 at 08:11:21AM +0000, Zilin Guan wrote:
> The dw_i3c_master_i2c_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.
>
> Add a dw_i3c_master_free_xfer() call to the error path to ensure the
> allocated memory is properly freed.
>
> Compile tested only. Issue found using a prototype static analysis tool
> and code review.
>
> Fixes: 62fe9d06f570 ("i3c: dw: Add power management support")
> Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
> ---
Reviewed-by: Frank Li <Frank.Li@nxp.com>
After https://lore.kernel.org/linux-i3c/176840902682.1305594.13987931108275156748.b4-ty@bootlin.com/T/#t
driver's runtime pm get code can be removed.
Frank
> drivers/i3c/master/dw-i3c-master.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index 889e2ed5bc83..3e6f66dff2ec 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -1099,6 +1099,7 @@ static int dw_i3c_master_i2c_xfers(struct i2c_dev_desc *dev,
> dev_err(master->dev,
> "<%s> cannot resume i3c bus master, err: %d\n",
> __func__, ret);
> + dw_i3c_master_free_xfer(xfer);
> return ret;
> }
>
> --
> 2.34.1
>
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
2026-01-26 8:11 [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers() Zilin Guan
2026-01-26 10:22 ` Markus Elfring
2026-01-26 17:01 ` Frank Li
@ 2026-01-30 23:08 ` Alexandre Belloni
2 siblings, 0 replies; 4+ messages in thread
From: Alexandre Belloni @ 2026-01-30 23:08 UTC (permalink / raw)
To: Zilin Guan; +Cc: Frank.Li, aniketmaurya, linux-i3c, linux-kernel, jianhao.xu
On Mon, 26 Jan 2026 08:11:21 +0000, Zilin Guan wrote:
> The dw_i3c_master_i2c_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.
>
> Add a dw_i3c_master_free_xfer() call to the error path to ensure the
> allocated memory is properly freed.
>
> [...]
Applied, thanks!
[1/1] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers()
https://git.kernel.org/i3c/c/253708941351
Best regards,
--
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
--
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-01-30 23:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-26 8:11 [PATCH] i3c: dw: Fix memory leak in dw_i3c_master_i2c_xfers() Zilin Guan
2026-01-26 10:22 ` Markus Elfring
2026-01-26 17:01 ` Frank Li
2026-01-30 23:08 ` Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox