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 63A11C05027 for ; Thu, 9 Feb 2023 11:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231363AbjBILYc (ORCPT ); Thu, 9 Feb 2023 06:24:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231311AbjBILXn (ORCPT ); Thu, 9 Feb 2023 06:23:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A51E05C487; Thu, 9 Feb 2023 03:19:04 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 51DBA619F6; Thu, 9 Feb 2023 11:18:44 +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 Cc: Cezary Rojewski , Takashi Iwai , Takashi Iwai , Sasha Levin , perex@perex.cz, pierre-louis.bossart@linux.intel.com, kai.vehmanen@linux.intel.com, mkumard@nvidia.com, alsa-devel@alsa-project.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 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 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