From mboxrd@z Thu Jan 1 00:00:00 1970 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 alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (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 6BB5ECDB47E for ; Wed, 18 Oct 2023 14:14:28 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 9EE23DED; Wed, 18 Oct 2023 16:13:36 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 9EE23DED DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1697638466; bh=lOJ9IO0p1IqYS9u1GlHfb86JxNofqQmR9iLuoYPMvwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=FUMRiTnnoV6hfb2IU2iOW7uos1CnWlfy0dQqYbbRvFQnhT9sXWETBkJQSqXs8shYZ Mtf0+W8cZ+pKyyIaYFzauieQiev6XDQklr3nj4IH94QLXLVjYaM+16Muk28j16EtEk 0NFYBxKut2GrgdeZJd+lB8Gw3IxHWdkkjMgn1/6E= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 53DC7F805A8; Wed, 18 Oct 2023 16:12:27 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 1FA13F805B0; Wed, 18 Oct 2023 16:12:27 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 32FDDF80588; Wed, 18 Oct 2023 16:12:22 +0200 (CEST) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 7F24CF80558 for ; Wed, 18 Oct 2023 16:12:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7F24CF80558 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=jF93VGus Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id 07C21B82393; Wed, 18 Oct 2023 14:12:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B5BBC433C9; Wed, 18 Oct 2023 14:12:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697638333; bh=lOJ9IO0p1IqYS9u1GlHfb86JxNofqQmR9iLuoYPMvwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jF93VGus9M9etw/f0MT9FpbnbBaNZbvuK3HKLU/2E6lV7sLENKrbeXSSsBRhDxhgN 9s9wGoQxgP+sw206mbNok9fxDYuzJVUaQwem0OduvXAW2FBih7Rmm6XzkIekhfwhTP 3fTOTWD2oNHxiywIMAt0TdH/rDggMljIO1NSMV/5BgHqOf5JPxyVyp+nhM/TLJ9i/i zhOWo40wa8OKxp4ynxyPn3JrtgrGnPEZyyEhQqMS6JWVP9jMYZi2W94ulsohZACiNK GYyfpCQY1GFBeCOnceP95C87UCVTqbPQZzd5j6b4wDaH7hFRU2ehGYECzasB1uYzwJ ES9zhRoB8iFzg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Amadeusz=20S=C5=82awi=C5=84ski?= , Cezary Rojewski , Mark Brown , Sasha Levin , lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 6.5 08/31] ASoC: core: Do not call link_exit() on uninitialized rtd objects Date: Wed, 18 Oct 2023 10:11:25 -0400 Message-Id: <20231018141151.1334501-8-sashal@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231018141151.1334501-1-sashal@kernel.org> References: <20231018141151.1334501-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.5.7 Content-Transfer-Encoding: 8bit Message-ID-Hash: Y63JEL7SFDTDXLW62NCRYHXXW3JXEBX6 X-Message-ID-Hash: Y63JEL7SFDTDXLW62NCRYHXXW3JXEBX6 X-MailFrom: sashal@kernel.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Amadeusz Sławiński [ Upstream commit dd9f9cc1e6b9391140afa5cf27bb47c9e2a08d02 ] On init we have sequence: for_each_card_prelinks(card, i, dai_link) { ret = snd_soc_add_pcm_runtime(card, dai_link); ret = init_some_other_things(...); if (ret) goto probe_end: for_each_card_rtds(card, rtd) { ret = soc_init_pcm_runtime(card, rtd); probe_end: while on exit: for_each_card_rtds(card, rtd) snd_soc_link_exit(rtd); If init_some_other_things() step fails due to error we end up with not fully setup rtds and try to call snd_soc_link_exit on them, which depending on contents on .link_exit handler, can end up dereferencing NULL pointer. Reviewed-by: Cezary Rojewski Signed-off-by: Amadeusz Sławiński Link: https://lore.kernel.org/r/20230929103243.705433-2-amadeuszx.slawinski@linux.intel.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- include/sound/soc.h | 2 ++ sound/soc/soc-core.c | 20 +++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/sound/soc.h b/include/sound/soc.h index b27f84580c5b0..cf34810882347 100644 --- a/include/sound/soc.h +++ b/include/sound/soc.h @@ -1125,6 +1125,8 @@ struct snd_soc_pcm_runtime { unsigned int pop_wait:1; unsigned int fe_compr:1; /* for Dynamic PCM */ + bool initialized; + int num_components; struct snd_soc_component *components[]; /* CPU/Codec/Platform */ }; diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c index 1a0bde23f5e6f..2d85164457f73 100644 --- a/sound/soc/soc-core.c +++ b/sound/soc/soc-core.c @@ -1259,7 +1259,7 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card, snd_soc_runtime_get_dai_fmt(rtd); ret = snd_soc_runtime_set_dai_fmt(rtd, dai_link->dai_fmt); if (ret) - return ret; + goto err; /* add DPCM sysfs entries */ soc_dpcm_debugfs_add(rtd); @@ -1284,17 +1284,26 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card, /* create compress_device if possible */ ret = snd_soc_dai_compress_new(cpu_dai, rtd, num); if (ret != -ENOTSUPP) - return ret; + goto err; /* create the pcm */ ret = soc_new_pcm(rtd, num); if (ret < 0) { dev_err(card->dev, "ASoC: can't create pcm %s :%d\n", dai_link->stream_name, ret); - return ret; + goto err; } - return snd_soc_pcm_dai_new(rtd); + ret = snd_soc_pcm_dai_new(rtd); + if (ret < 0) + goto err; + + rtd->initialized = true; + + return 0; +err: + snd_soc_link_exit(rtd); + return ret; } static void soc_set_name_prefix(struct snd_soc_card *card, @@ -1892,7 +1901,8 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card) /* release machine specific resources */ for_each_card_rtds(card, rtd) - snd_soc_link_exit(rtd); + if (rtd->initialized) + snd_soc_link_exit(rtd); /* remove and free each DAI */ soc_remove_link_dais(card); soc_remove_link_components(card); -- 2.40.1