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 9D7A2C636D4 for ; Thu, 9 Feb 2023 11:21:09 +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 3110BE80; Thu, 9 Feb 2023 12:20:17 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3110BE80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1675941667; bh=FYY88WlPPdVjmmN7DeDJdLHPzDIC2rjCGBFP1s4GUAY=; h=From:To:Subject:Date:In-Reply-To:References:CC:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=S7MU1FFG+IpakO/LBKl9PyktYq9Vz8kKY7Q6uHPjmizc3IpL0sXsr9JQc1D+vLPqD N6+VDw9d4ztxexvbN8HC4vm2schp54Oo5jJ0/3ludPN4bkoOA4VIgPo5TA9ekxeSIs 1D/l22SX8RbL+B/l/UX8EFkCFv11bEWIJ+q4nBiY= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 6E3CEF80579; Thu, 9 Feb 2023 12:18:56 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BF767F80571; Thu, 9 Feb 2023 12:18:48 +0100 (CET) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D24A7F8056F for ; Thu, 9 Feb 2023 12:18:45 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D24A7F8056F 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=qMhbIj+C Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 10404B82107; Thu, 9 Feb 2023 11:18:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B61A9C433D2; Thu, 9 Feb 2023 11:18:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675941523; bh=FYY88WlPPdVjmmN7DeDJdLHPzDIC2rjCGBFP1s4GUAY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMhbIj+CbxJSiw7iWcRFT/e4FNqq+A7pOsoi5RrzCNkhn8xSv1MOh87UGE6rdzmz6 djhkHQB7VXyFp7f4swQRta8lPSJEfeofoWZ55S0/O9NSI0e2CdEgcE5BUGnSXbQqW4 k5K6llIrkC1UzZULXuh3HElh+9sy35C9/fP1RRmBs/O1q5seiIKaCGKo7nfAIfUQiP btNEp5it4Y58/YO0/ddHJYB2ZGMBIk/pk27aKvdgCVKZB6Dy0XaWb8K4kYYd60Bs0o OnzgUbActyL5KsD6BzAdZrOEHXvReXTpDKN68fNJjCXRH8sWGUpKkCEf1wKLSJuo0r IVmzdfDvvt5kA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 03/13] ALSA: hda: Do not unset preset when cleaning up codec Date: Thu, 9 Feb 2023 06:18:21 -0500 Message-Id: <20230209111833.1892896-3-sashal@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209111833.1892896-1-sashal@kernel.org> References: <20230209111833.1892896-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Message-ID-Hash: 3AHQWLFDLLB47O2YARHIJ3BMEY7FBQO3 X-Message-ID-Hash: 3AHQWLFDLLB47O2YARHIJ3BMEY7FBQO3 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 CC: Cezary Rojewski , Takashi Iwai , Takashi Iwai , Sasha Levin , pierre-louis.bossart@linux.intel.com, kai.vehmanen@linux.intel.com, mkumard@nvidia.com, alsa-devel@alsa-project.org 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: Cezary Rojewski [ Upstream commit 87978e6ad45a16835cc58234451111091be3c59a ] Several functions that take part in codec's initialization and removal are re-used by ASoC codec drivers implementations. Drivers mimic the behavior of hda_codec_driver_probe/remove() found in sound/pci/hda/hda_bind.c with their component->probe/remove() instead. One of the reasons for that is the expectation of snd_hda_codec_device_new() to receive a valid pointer to an instance of struct snd_card. This expectation can be met only once sound card components probing commences. As ASoC sound card may be unbound without codec device being actually removed from the system, unsetting ->preset in snd_hda_codec_cleanup_for_unbind() interferes with module unload -> load scenario causing null-ptr-deref. Preset is assigned only once, during device/driver matching whereas ASoC codec driver's module reloading may occur several times throughout the lifetime of an audio stack. Suggested-by: Takashi Iwai Signed-off-by: Cezary Rojewski Link: https://lore.kernel.org/r/20230119143235.1159814-1-cezary.rojewski@intel.com Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/hda/hda_bind.c | 2 ++ sound/pci/hda/hda_codec.c | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c index 4efbcc41fdfb7..0a83afa5f373c 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -143,6 +143,7 @@ static int hda_codec_driver_probe(struct device *dev) error: snd_hda_codec_cleanup_for_unbind(codec); + codec->preset = NULL; return err; } @@ -159,6 +160,7 @@ static int hda_codec_driver_remove(struct device *dev) if (codec->patch_ops.free) codec->patch_ops.free(codec); snd_hda_codec_cleanup_for_unbind(codec); + codec->preset = NULL; module_put(dev->driver->owner); return 0; } diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c index 39281106477eb..fc4a64a83ff2f 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -784,7 +784,6 @@ void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec) snd_array_free(&codec->cvt_setups); snd_array_free(&codec->spdif_out); snd_array_free(&codec->verbs); - codec->preset = NULL; codec->follower_dig_outs = NULL; codec->spdif_status_reset = 0; snd_array_free(&codec->mixers); -- 2.39.0