From: Frank Li <Frank.li@nxp.com>
To: Felix Gu <ustc.gu@gmail.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>,
Aniket <aniketmaurya@google.com>,
linux-i3c@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 1/2] i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers()
Date: Sun, 5 Apr 2026 23:05:51 -0400 [thread overview]
Message-ID: <adMjD5qrfXjtioDJ@lizhi-Precision-Tower-5810> (raw)
In-Reply-To: <20260404-dw-i3c-2-v3-1-8f7d146549c1@gmail.com>
On Sat, Apr 04, 2026 at 06:32:30PM +0800, Felix Gu wrote:
> 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>
> ---
You misssed Tommaso Merciai review tags in v2
Frank
> drivers/i3c/master/dw-i3c-master.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/i3c/master/dw-i3c-master.c b/drivers/i3c/master/dw-i3c-master.c
> index d6bdb32397fb..2e31228b3809 100644
> --- a/drivers/i3c/master/dw-i3c-master.c
> +++ b/drivers/i3c/master/dw-i3c-master.c
> @@ -7,6 +7,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>
> @@ -924,7 +925,6 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
> struct i3c_master_controller *m = i3c_dev_get_master(dev);
> struct dw_i3c_master *master = to_dw_i3c_master(m);
> unsigned int nrxwords = 0, ntxwords = 0;
> - struct dw_i3c_xfer *xfer;
> int i, ret = 0;
>
> if (!i3c_nxfers)
> @@ -944,7 +944,7 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
> nrxwords > master->caps.datafifodepth)
> return -EOPNOTSUPP;
>
> - xfer = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
> + struct dw_i3c_xfer *xfer __free(kfree) = dw_i3c_master_alloc_xfer(master, i3c_nxfers);
> if (!xfer)
> return -ENOMEM;
>
> @@ -995,7 +995,6 @@ static int dw_i3c_master_i3c_xfers(struct i3c_dev_desc *dev,
> }
>
> ret = xfer->ret;
> - dw_i3c_master_free_xfer(xfer);
>
> pm_runtime_put_autosuspend(master->dev);
> return ret;
>
> --
> 2.43.0
>
next prev parent reply other threads:[~2026-04-06 3:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-04 10:32 [PATCH v3 0/2] " Felix Gu
2026-04-04 10:32 ` [PATCH v3 1/2] " Felix Gu
2026-04-06 2:59 ` Frank Li
2026-04-06 3:05 ` Frank Li [this message]
2026-04-06 6:52 ` Felix Gu
2026-04-04 10:32 ` [PATCH v3 2/2] i3c: dw: Simplify xfer cleanup with __free(kfree) Felix Gu
2026-04-06 3:03 ` Frank Li
2026-04-12 14:52 ` [PATCH v3 0/2] i3c: dw: Fix memory leak in dw_i3c_master_i3c_xfers() Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adMjD5qrfXjtioDJ@lizhi-Precision-Tower-5810 \
--to=frank.li@nxp.com \
--cc=alexandre.belloni@bootlin.com \
--cc=aniketmaurya@google.com \
--cc=linux-i3c@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ustc.gu@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®