Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2381566lqp; Sun, 24 Mar 2024 16:55:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXIGu2JQmN4XoytOUQun60MOh9AfmRU36NgxEB75dZl2nN91AR0yexG/qkyhko79PejRUISY1qyxWMLZ+8Zrx5tR2crDz1A4upLVOV8g== X-Google-Smtp-Source: AGHT+IHhY0cIudxKWGlKpEoBWpr3PjYhE2PJpdwiJ+/Chbf1bSI3hn0GKmXptQopT27UI4xMWvlF X-Received: by 2002:a50:d508:0:b0:56b:defa:57b0 with SMTP id u8-20020a50d508000000b0056bdefa57b0mr3692166edi.10.1711324547133; Sun, 24 Mar 2024 16:55:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324547; cv=pass; d=google.com; s=arc-20160816; b=y+/4gPY9BdwDx87BXtPmz6p1FVA+FvCCRvxaCL62zapRDVHYlU72RaStPfRc6xrajn pL/opQPpw1odJ8S/6keZMAoighQ2FIXDZBNRbTGyoVyUi+PDevXA7RIBDFM5Q9maF0k2 0R/nErD1d7WB/+6WEi50NUO1Py/qsM2NXtRqNkOlc9W/VRsfxWGCtzH7+q1Rz9TQDnyL HTNQjeSpYLNw5N7OyIyrMogCvl1Rui4nX89seIx6m+z691UW3fIg+suM28ZdJJctFUY0 NgjQK/9M53upuzxyulB11iF+EZ9g1XZZQldEVBI1Ypj/dQ0HG1KXtm7772mfeZmLZjJ/ Bjhw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pXo5OFPeXi/ojPjx4oGQIqz2Nf6s9x6B+3khAp7xmCs=; fh=xyO+CIbliXzkv7pjU3CTq5wABV/8CvRtuix89WvW5bY=; b=DQcETuiQV2r8tBYRDV0UReVRRSPRmIcLMyyMw09lx9mfX6A+QfxwEL0qi46Iue9ELL R7aiBohYcG7cXx+6NKXIAaMX3zOSyrpNZUalYwaR+OJKbV7LWROvxPs+s/Au5z4L1KLN kwBCIuL+x06A2s4dwIF7F20rx3+WCZl5xrF6yi4MKvIV4hH21BDa9pDPS79vry5PkTCf rQaLrncCRwQRVP4HawIP7VPLjc4zqpw3FnfH6ATX6Y6wzAl2renmPtY2h/1QA0EgaF2b WG2h/K6mYfZpr0Q0W9eRktUZ2JF6oFrqqbFvZ1J1g8K6zVPEPl/qf/OUwi/gG2w/aOwj tM9g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AND2Jkym; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z4-20020a056402274400b0056b9eb5124dsi2122144edd.371.2024.03.24.16.55.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 16:55:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AND2Jkym; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113258-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113258-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D8FAB1F22330 for ; Sun, 24 Mar 2024 23:55:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2B8CB13CABA; Sun, 24 Mar 2024 22:40:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="AND2Jkym" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D88613CA95; Sun, 24 Mar 2024 22:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320058; cv=none; b=L5d4qDt1y5cD3OxeB+qrrRfHM4EcmoaCrCHPHr6r9TFKQXcFHMapBtaFNfUj4GtuPlmWUT4WHzpzhG9JWSnLcAzNcPsMF0KYk1Xs5dYJ/ugTChtL1GMc4QDRKCjekVsg0Zfgb5jV0V1snh/PcVl0MgMDTLwr9FbTdyDCORjMxAI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320058; c=relaxed/simple; bh=w1lzHvGXBX3ANXxLc/UUheMyGtodUzRmiK0aL41bvzY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K4VTwAF5TRk6MCNADBk1VTf6vp0LuWFSrAAxHSDypX5kxs/0p3Rimcm25yVb/DxuKsF8W/y+G7U945IhVOOE8DAvPTiDJTYb/UUCHA0tXIZZFMGsDwkd5EzzwhgLz4qqI/88nGDl+UhR+te/QM/5hR/frUMlBmFZckPc/OgJOng= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AND2Jkym; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0A38FC433B1; Sun, 24 Mar 2024 22:40:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320057; bh=w1lzHvGXBX3ANXxLc/UUheMyGtodUzRmiK0aL41bvzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AND2Jkym4RL0FL5PTFi6rjAGi+ft6Z+mFR/ehD2NM1dh/G1b2B+Kpln9pLAwsw5oF yNFKkvqOTdLffvUxbpzBxt4OU2mgvkY3t0y48EJnEkuyZG/axo8AAsImXIhzy+xoTR 8Lxd+GC9jcJRBB4/8kSAp8vEqPuSZmA3/SmuDtICXWXbjDOelGbMW8EoufRI/HTYvc NUNNUmEnnSN6TiBEtmiZkFy2h0PxlcqI//mfOTtKqN4Mz8JSZT6qevT/WOSOaUmDrJ f75f1Uar19KypU3Ap7C6A9Jcv63PO+53rpxijILgWHzPpA579N1+9sHPS2YH32Zk4U g9NH3cKQUhOpg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cristian Ciocaltea , Emil Velikov , Mark Brown , Sasha Levin Subject: [PATCH 6.8 367/715] ASoC: SOF: amd: Fix memory leak in amd_sof_acp_probe() Date: Sun, 24 Mar 2024 18:29:06 -0400 Message-ID: <20240324223455.1342824-368-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Cristian Ciocaltea [ Upstream commit 222be59e5eed1554119294edc743ee548c2371d0 ] Driver uses kasprintf() to initialize fw_{code,data}_bin members of struct acp_dev_data, but kfree() is never called to deallocate the memory, which results in a memory leak. Fix the issue by switching to devm_kasprintf(). Additionally, ensure the allocation was successful by checking the pointer validity. Fixes: f7da88003c53 ("ASoC: SOF: amd: Enable signed firmware image loading for Vangogh platform") Signed-off-by: Cristian Ciocaltea Reviewed-by: Emil Velikov Link: https://msgid.link/r/20231219030728.2431640-6-cristian.ciocaltea@collabora.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/sof/amd/acp.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/sound/soc/sof/amd/acp.c b/sound/soc/sof/amd/acp.c index 07632ae6ccf5e..9aa9600c05d61 100644 --- a/sound/soc/sof/amd/acp.c +++ b/sound/soc/sof/amd/acp.c @@ -560,17 +560,27 @@ int amd_sof_acp_probe(struct snd_sof_dev *sdev) adata->signed_fw_image = false; dmi_id = dmi_first_match(acp_sof_quirk_table); if (dmi_id && dmi_id->driver_data) { - adata->fw_code_bin = kasprintf(GFP_KERNEL, "%s/sof-%s-code.bin", - plat_data->fw_filename_prefix, - chip->name); - adata->fw_data_bin = kasprintf(GFP_KERNEL, "%s/sof-%s-data.bin", - plat_data->fw_filename_prefix, - chip->name); - adata->signed_fw_image = dmi_id->driver_data; + adata->fw_code_bin = devm_kasprintf(sdev->dev, GFP_KERNEL, + "%s/sof-%s-code.bin", + plat_data->fw_filename_prefix, + chip->name); + if (!adata->fw_code_bin) { + ret = -ENOMEM; + goto free_ipc_irq; + } + + adata->fw_data_bin = devm_kasprintf(sdev->dev, GFP_KERNEL, + "%s/sof-%s-data.bin", + plat_data->fw_filename_prefix, + chip->name); + if (!adata->fw_data_bin) { + ret = -ENOMEM; + goto free_ipc_irq; + } - dev_dbg(sdev->dev, "fw_code_bin:%s, fw_data_bin:%s\n", adata->fw_code_bin, - adata->fw_data_bin); + adata->signed_fw_image = dmi_id->driver_data; } + adata->enable_fw_debug = enable_fw_debug; acp_memory_init(sdev); -- 2.43.0