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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 290DAC05027 for ; Thu, 9 Feb 2023 11:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229836AbjBILWy (ORCPT ); Thu, 9 Feb 2023 06:22:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbjBILWG (ORCPT ); Thu, 9 Feb 2023 06:22:06 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C3BF5FB6E; Thu, 9 Feb 2023 03:18:22 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id 09655CE246B; Thu, 9 Feb 2023 11:17:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4CF5FC433EF; Thu, 9 Feb 2023 11:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675941466; bh=oePXfbpF/+zX1IsYlzhJ0N2jEXssdJojoV7L75QJXMQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WhpbqDuMwZPCDyMbBFa2EcZrCxpaPPhCH5GnYPnxqwXuePfs9H8iwkECcJyeXMKy3 l7U0dVP2CvpEtMBwYz00m7d0M5dhkPOnjGyViNhrMMoTvbOBjPhpbv3zNCDVY86vDs SUoOcpVSh/3+qZ4z96i1m6o6wzPV2MJQv34/tuanx2wztsPdYtJVW5yVg26twX+DgD N6cgsqzmvnVBQWa27/QZ221I3Zgkxb1pLkg3JkOSFKAlnp7cFDH5KKHCl1w8cXt/DH /qBlqyy+MT2acPF/9fDfQ0HURhjXIm5HqYAGl6jbWpC0JvvKKz2LiLvHiUP8W1sywE H9bm0bIucN4/A== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Cezary Rojewski , Takashi Iwai , Takashi Iwai , Sasha Levin , perex@perex.cz, kai.vehmanen@linux.intel.com, pierre-louis.bossart@linux.intel.com, mkumard@nvidia.com, alsa-devel@alsa-project.org Subject: [PATCH AUTOSEL 5.15 04/17] ALSA: hda: Do not unset preset when cleaning up codec Date: Thu, 9 Feb 2023 06:17:16 -0500 Message-Id: <20230209111731.1892569-4-sashal@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230209111731.1892569-1-sashal@kernel.org> References: <20230209111731.1892569-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 7af2515735957..8e35009ec25cb 100644 --- a/sound/pci/hda/hda_bind.c +++ b/sound/pci/hda/hda_bind.c @@ -144,6 +144,7 @@ static int hda_codec_driver_probe(struct device *dev) error: snd_hda_codec_cleanup_for_unbind(codec); + codec->preset = NULL; return err; } @@ -166,6 +167,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 f552785d301e0..19be60bb57810 100644 --- a/sound/pci/hda/hda_codec.c +++ b/sound/pci/hda/hda_codec.c @@ -791,7 +791,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