Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55274EFB810 for ; Tue, 24 Feb 2026 08:33:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C36F10E50E; Tue, 24 Feb 2026 08:33:28 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=acm.org header.i=@acm.org header.b="EFVELKUC"; dkim-atps=neutral Received: from 013.lax.mailroute.net (013.lax.mailroute.net [199.89.1.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id 989BE10E44D for ; Mon, 23 Feb 2026 21:57:11 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by 013.lax.mailroute.net (Postfix) with ESMTP id 4fKZK20fTXzlfl89; Mon, 23 Feb 2026 21:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=acm.org; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=mr01; t=1771883412; x= 1774475413; bh=fwAOd1ujkWk5Wg47tjqI1LopMAuDLIx8SW3w8NZ6/A4=; b=E FVELKUCOJr6ft9awQW5fRReH+S1xaJxyFX4zQr+E6hPDME2RC1mDv1kpT7mf/42J IuT6Olmd3CsqGO9y+LaecTqd2f+mMj3AVNFgIyRHxfU6WMCoRy1o2sM47NTkb2n0 Mle6DYiBXZfp9klwJ53Vd1iouOrRycVMi272swXctCcAO3hF+BkDq8WSNdZ/Rf4+ zFnBgY5g79A2pYnQHHlcM2MZbxzoKGvglU6ngRrAmI7AxMCbcjFZEYTQx48BYbp2 BD54x/FQWC/2rbuLJS/BXtmXXUaElco8sjXqxOcsSsDdOvS8wNUWt60CjzZCCWiK eVq2LiVnZ3Y/io8ATnmng== X-Virus-Scanned: by MailRoute Received: from 013.lax.mailroute.net ([127.0.0.1]) by localhost (013.lax [127.0.0.1]) (mroute_mailscanner, port 10029) with LMTP id HIUWPQBRkRXn; Mon, 23 Feb 2026 21:50:12 +0000 (UTC) Received: from bvanassche.mtv.corp.google.com (unknown [104.135.180.219]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bvanassche@acm.org) by 013.lax.mailroute.net (Postfix) with ESMTPSA id 4fKZJz1Gjqzlfl7s; Mon, 23 Feb 2026 21:50:10 +0000 (UTC) From: Bart Van Assche To: Peter Zijlstra Cc: Bart Van Assche , Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= , YiPeng Chai , Hawking Zhang , amd-gfx@lists.freedesktop.org Subject: [PATCH 08/62] drm/amdgpu: Fix locking bugs in error paths Date: Mon, 23 Feb 2026 13:48:56 -0800 Message-ID: <20260223214950.2153735-9-bvanassche@acm.org> X-Mailer: git-send-email 2.53.0.371.g1d285c8824-goog In-Reply-To: <20260223214950.2153735-1-bvanassche@acm.org> References: <20260223214950.2153735-1-bvanassche@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Tue, 24 Feb 2026 08:33:26 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" Do not unlock psp->ras_context.mutex if it has not been locked. This has been detected by the Clang thread-safety analyzer. Cc: Alex Deucher Cc: Christian K=C3=B6nig Cc: YiPeng Chai Cc: Hawking Zhang Cc: amd-gfx@lists.freedesktop.org Fixes: b3fb79cda568 ("drm/amdgpu: add mutex to protect ras shared memory"= ) Signed-off-by: Bart Van Assche --- drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c b/drivers/gpu/drm= /amd/amdgpu/amdgpu_psp_ta.c index 6e8aad91bcd3..0d3c18f04ac3 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp_ta.c @@ -332,13 +332,13 @@ static ssize_t ta_if_invoke_debugfs_write(struct fi= le *fp, const char *buf, size if (!context || !context->initialized) { dev_err(adev->dev, "TA is not initialized\n"); ret =3D -EINVAL; - goto err_free_shared_buf; + goto free_shared_buf; } =20 if (!psp->ta_funcs || !psp->ta_funcs->fn_ta_invoke) { dev_err(adev->dev, "Unsupported function to invoke TA\n"); ret =3D -EOPNOTSUPP; - goto err_free_shared_buf; + goto free_shared_buf; } =20 context->session_id =3D ta_id; @@ -346,7 +346,7 @@ static ssize_t ta_if_invoke_debugfs_write(struct file= *fp, const char *buf, size mutex_lock(&psp->ras_context.mutex); ret =3D prep_ta_mem_context(&context->mem_context, shared_buf, shared_b= uf_len); if (ret) - goto err_free_shared_buf; + goto unlock; =20 ret =3D psp_fn_ta_invoke(psp, cmd_id); if (ret || context->resp_status) { @@ -354,15 +354,17 @@ static ssize_t ta_if_invoke_debugfs_write(struct fi= le *fp, const char *buf, size ret, context->resp_status); if (!ret) { ret =3D -EINVAL; - goto err_free_shared_buf; + goto unlock; } } =20 if (copy_to_user((char *)&buf[copy_pos], context->mem_context.shared_bu= f, shared_buf_len)) ret =3D -EFAULT; =20 -err_free_shared_buf: +unlock: mutex_unlock(&psp->ras_context.mutex); + +free_shared_buf: kfree(shared_buf); =20 return ret;