The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Mario Limonciello <superm1@kernel.org>
To: Lizhi Hou <lizhi.hou@amd.com>,
	ogabbay@kernel.org, quic_jhugo@quicinc.com,
	dri-devel@lists.freedesktop.org, karol.wachowski@linux.intel.com
Cc: linux-kernel@vger.kernel.org, max.zhen@amd.com, sonal.santan@amd.com
Subject: Re: [PATCH V1] accel/amdxdna: Check init_srcu_struct() return value
Date: Tue, 7 Jul 2026 12:31:49 -0500	[thread overview]
Message-ID: <49f7d3cd-502d-4c4e-8166-2d1c68d792a0@kernel.org> (raw)
In-Reply-To: <20260707172323.539721-1-lizhi.hou@amd.com>



On 7/7/26 12:23, Lizhi Hou wrote:
> The return value of init_srcu_struct() is currently ignored. If
> initialization fails, subsequent use of hwctx_srcu may result in invalid
> memory accesses.
> 
> Check the return value of init_srcu_struct() and propagate the error to
> the caller.
> 
> Fixes: aac243092b70 ("accel/amdxdna: Add command execution")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
>   drivers/accel/amdxdna/amdxdna_pci_drv.c | 16 +++++++++++++---
>   1 file changed, 13 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/accel/amdxdna/amdxdna_pci_drv.c b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> index 86e9c230875a..bb339e641416 100644
> --- a/drivers/accel/amdxdna/amdxdna_pci_drv.c
> +++ b/drivers/accel/amdxdna/amdxdna_pci_drv.c
> @@ -109,11 +109,16 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
>   {
>   	struct amdxdna_dev *xdna = to_xdna_dev(ddev);
>   	struct amdxdna_client *client;
> +	int ret;
>   
>   	client = kzalloc_obj(*client);
>   	if (!client)
>   		return -ENOMEM;
>   
> +	ret = init_srcu_struct(&client->hwctx_srcu);
> +	if (ret)
> +		goto free_client;
> +
>   	client->pid = pid_nr(rcu_access_pointer(filp->pid));
>   	client->xdna = xdna;
>   	client->pasid = IOMMU_PASID_INVALID;
> @@ -125,13 +130,12 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
>   			XDNA_WARN(xdna, "PASID not available for pid %d", client->pid);
>   			if (!amdxdna_use_carveout(xdna)) {
>   				XDNA_ERR(xdna, "PASID unavailable and carveout not configured");
> -				kfree(client);
> -				return -EINVAL;
> +				ret = -EINVAL;
> +				goto cleanup_srcu;
>   			}
>   		}
>   	}
>   	mmgrab(client->mm);
> -	init_srcu_struct(&client->hwctx_srcu);
>   	xa_init_flags(&client->hwctx_xa, XA_FLAGS_ALLOC);
>   	xa_init_flags(&client->dev_heap_xa, XA_FLAGS_ALLOC);
>   	drm_mm_init(&client->dev_heap_mm, xdna->dev_info->dev_mem_base,
> @@ -149,6 +153,12 @@ static int amdxdna_drm_open(struct drm_device *ddev, struct drm_file *filp)
>   
>   	XDNA_DBG(xdna, "pid %d opened", client->pid);
>   	return 0;
> +
> +cleanup_srcu:
> +	cleanup_srcu_struct(&client->hwctx_srcu);
> +free_client:
> +	kfree(client);
> +	return ret;
>   }
>   
>   static void amdxdna_client_cleanup(struct amdxdna_client *client)


      reply	other threads:[~2026-07-07 17:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 17:23 [PATCH V1] accel/amdxdna: Check init_srcu_struct() return value Lizhi Hou
2026-07-07 17:31 ` Mario Limonciello [this message]

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=49f7d3cd-502d-4c4e-8166-2d1c68d792a0@kernel.org \
    --to=superm1@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karol.wachowski@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizhi.hou@amd.com \
    --cc=max.zhen@amd.com \
    --cc=ogabbay@kernel.org \
    --cc=quic_jhugo@quicinc.com \
    --cc=sonal.santan@amd.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