Received: by 2002:a05:7412:8598:b0:f9:33c2:5753 with SMTP id n24csp250979rdh; Mon, 18 Dec 2023 19:09:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7phXIGpIsa4INO0x0oSB5pasW8NHBno3NEEBXINeLnKn9TDJdHdvzeHiTkxoSACPzgVfm X-Received: by 2002:a05:6402:2156:b0:54a:f8e9:a9a8 with SMTP id bq22-20020a056402215600b0054af8e9a9a8mr8926274edb.20.1702955339871; Mon, 18 Dec 2023 19:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702955339; cv=none; d=google.com; s=arc-20160816; b=dw8P1Vg2FHiUUygyv1/GRBGr/VIwX0ZC793ZCkYnzsy6jf7uiaEuydPGJpQPIfLlTu c7vMJm4lH9dOEn2j7sLqZuA/HHQrxFzcN8rBb1fn+ZMdwnCZnjt7wWI5UpoSPupukRMF PYOz8SAf5cS5z10RjKIUqT/KGFBZH1Q40OeUPKxg2aF46greVr/IZOa4RZr3E+EDaIcQ IsfxPk2S6i10KR/7IHB5s9LfjzGHHWgdslvYA8Q+IGViQFLZm9JSTQUq7KWx2C7sgArW pM0FiKZr1GN2ltDPcGOjrzMjhDHzEnPvCsBpUU2JwaYHKcAQFVd18rqWEaBeOeKW0b8y 2Dxw== ARC-Message-Signature: i=1; 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=Qev23Lt9WpEQIFs4IEaCedE0NjMmJU5nc+/e/CJZYUg=; fh=h70dJO8c/kQzBx5G08DNBGLpC0OGfeXZuzZObLFqbr4=; b=MUp3x4Mx5wueKX3IRtZUDu9UfXLn7/pl+exV48/noqwbyUDvj3zn/48TXci5nNJEDs LJSwSxUX5Bd0njp6rujapo+9XnJYpIMHFq50SoG7NH0o5n4f8Bk7e7a12MRJ20rAT4NU KWNvK5RJ4odmGSB4c8E4iqrjtaB+ne3YD+n/eSkTXd0fuUSi745JazvkTQcXPOPZwBiM jTvTY3cwIfDcu/F+SSpu0kEDKzgnOeLHyhbax/Yf9/ZcBnyKmJWowGq2+b29qTTYBc08 GdVty4SLPjRydSrbbRZFGwOxdMwWKPK3rolz8Wl+i1mcaqEMKCU8RhT9jL4BKHqNGYD/ xLUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=5WoaJT75; spf=pass (google.com: domain of linux-kernel+bounces-4627-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b8-20020a056402084800b0054c82b4cbeesi10282553edz.147.2023.12.18.19.08.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Dec 2023 19:08:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-4627-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=5WoaJT75; spf=pass (google.com: domain of linux-kernel+bounces-4627-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-4627-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com 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 9BFA21F243C1 for ; Tue, 19 Dec 2023 03:08:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E341E54E; Tue, 19 Dec 2023 03:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="5WoaJT75" X-Original-To: linux-kernel@vger.kernel.org Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (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 2A6CA8BFD; Tue, 19 Dec 2023 03:07:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1702955266; bh=NedD0CsTyD06CZpoZGygoYeaj43j/jCPYz4qI72jJJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=5WoaJT75SqIPQPy5/Vc2rZUoXCIC4RzpQyyp6Ho42tU6BgZB4x1XCgcBNWWE5Bx9+ HUFr5J41WF4dw/v29/aq27nYcOmCvFz6T4VouDc/lCs2cIft+/t6TwyDDXTPnkMSHj 9NCzmDgAZwtahf0GcetOTsDVg1zSInRRKCECHaX53ml183fg2O/EFhyPYxTBQWsL3h u1PYwZKubok48pIqLiWEFWniCbwpYS765u9zgSaQCH+57GhOsaMiyIoqukmqZQMy9b q6uBEn4pM4OGerlmrZMEr6PKQgCys9B8EK++E9ra4UlqVlSBhHo0oOGv4IUg4O1ytU qQzUcla1XKeXQ== Received: from localhost (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: cristicc) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 42AB237814AF; Tue, 19 Dec 2023 03:07:46 +0000 (UTC) From: Cristian Ciocaltea To: Liam Girdwood , Mark Brown , Jaroslav Kysela , Takashi Iwai , Pierre-Louis Bossart , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Daniel Baluta , Kai Vehmanen , Venkata Prasad Potturu , Emil Velikov , Syed Saba Kareem , Kuninori Morimoto , Alper Nebi Yasak , Vijendar Mukunda , V sujith kumar Reddy , Mastan Katragadda , Ajit Kumar Pandey Cc: linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org, sound-open-firmware@alsa-project.org, kernel@collabora.com Subject: [PATCH v2 5/8] ASoC: SOF: amd: Fix memory leak in amd_sof_acp_probe() Date: Tue, 19 Dec 2023 05:07:23 +0200 Message-ID: <20231219030728.2431640-6-cristian.ciocaltea@collabora.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231219030728.2431640-1-cristian.ciocaltea@collabora.com> References: <20231219030728.2431640-1-cristian.ciocaltea@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 603ea5fc0d0d..c6f637f29847 100644 --- a/sound/soc/sof/amd/acp.c +++ b/sound/soc/sof/amd/acp.c @@ -547,17 +547,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