From: "Vivekanandan, Balasubramani" <balasubramani.vivekanandan@intel.com>
To: Shuicheng Lin <shuicheng.lin@intel.com>,
<intel-xe@lists.freedesktop.org>
Cc: Matt Roper <matthew.d.roper@intel.com>
Subject: Re: [PATCH] drm/xe/reg_sr: Fix leak on xa_store failure
Date: Wed, 4 Feb 2026 21:42:20 +0530 [thread overview]
Message-ID: <aYNv5BDjgbOPqOJD@bvivekan-mob1> (raw)
In-Reply-To: <20260203173639.1399354-2-shuicheng.lin@intel.com>
On 03.02.2026 17:36, Shuicheng Lin wrote:
> Free the newly allocated entry when xa_store() fails to avoid a memory
> leak on the error path.
>
> Fixes: e5283bd4dfec ("drm/xe/reg_sr: Remove register pool")
> Cc: Matt Roper <matthew.d.roper@intel.com>
> Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
> ---
> drivers/gpu/drm/xe/xe_reg_sr.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/gpu/drm/xe/xe_reg_sr.c b/drivers/gpu/drm/xe/xe_reg_sr.c
> index d3e13ea33123..ce3dab8a0f47 100644
> --- a/drivers/gpu/drm/xe/xe_reg_sr.c
> +++ b/drivers/gpu/drm/xe/xe_reg_sr.c
> @@ -74,6 +74,7 @@ int xe_reg_sr_add(struct xe_reg_sr *sr,
> {
> unsigned long idx = e->reg.addr;
> struct xe_reg_sr_entry *pentry = xa_load(&sr->xa, idx);
> + bool allocated = false;
> int ret;
>
> if (pentry) {
> @@ -94,6 +95,7 @@ int xe_reg_sr_add(struct xe_reg_sr *sr,
> ret = -ENOMEM;
> goto fail;
> }
> + allocated = true;
>
> *pentry = *e;
> ret = xa_err(xa_store(&sr->xa, idx, pentry, GFP_KERNEL));
> @@ -103,6 +105,8 @@ int xe_reg_sr_add(struct xe_reg_sr *sr,
> return 0;
>
I would suggest create a new label above *fail:* which does kfree and
jump to it whenever pentry has to freed.
fail_free:
kfree(pentry);
Regards,
Bala
> fail:
> + if (allocated)
> + kfree(pentry);
> xe_gt_err(gt,
> "discarding save-restore reg %04lx (clear: %08x, set: %08x, masked: %s, mcr: %s): ret=%d\n",
> idx, e->clr_bits, e->set_bits,
> --
> 2.50.1
>
next prev parent reply other threads:[~2026-02-04 16:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-03 17:36 [PATCH] drm/xe/reg_sr: Fix leak on xa_store failure Shuicheng Lin
2026-02-03 18:09 ` ✓ CI.KUnit: success for " Patchwork
2026-02-03 19:00 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-02-03 23:13 ` ✓ CI.KUnit: success for drm/xe/reg_sr: Fix leak on xa_store failure (rev2) Patchwork
2026-02-03 23:46 ` ✗ Xe.CI.BAT: failure " Patchwork
2026-02-04 13:43 ` ✗ Xe.CI.FULL: " Patchwork
2026-02-04 16:12 ` Vivekanandan, Balasubramani [this message]
2026-02-04 17:35 ` [PATCH] drm/xe/reg_sr: Fix leak on xa_store failure Matt Roper
2026-02-04 17:56 ` Lin, Shuicheng
2026-02-04 18:15 ` Matt Roper
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=aYNv5BDjgbOPqOJD@bvivekan-mob1 \
--to=balasubramani.vivekanandan@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=matthew.d.roper@intel.com \
--cc=shuicheng.lin@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.