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 34877C6379F for ; Tue, 17 Jan 2023 15:49:24 +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 AAA6869DD; Tue, 17 Jan 2023 16:48:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz AAA6869DD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1673970562; bh=aQNnCgCTCv7oYi79GibXtLZZMfELsbt+tuXGwSNhq/s=; h=Date:Subject:To:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: Cc:From; b=mJt8Q+KGgUzSQ5jpXGYIi7KOxs4IekSQNpVqf5rQt8CDcLYWr13LrXotS6L+0v6kG kOWSRB0WkI+HXQvy36eWtCXO9L3b9VP/0ah8yuBZLV82uY7vW3Z/p0f+FChFGgoJtE s84IGP2C2EIj8fCjlxiRz2mLJU//gP8qsblTjOxo= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 58585F8047B; Tue, 17 Jan 2023 16:48:32 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 123ABF8047B; Tue, 17 Jan 2023 16:48:30 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 16B6DF8023A for ; Tue, 17 Jan 2023 16:48:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 16B6DF8023A Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=J8pXYJ2m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673970509; x=1705506509; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=aQNnCgCTCv7oYi79GibXtLZZMfELsbt+tuXGwSNhq/s=; b=J8pXYJ2mzKgxXTZrtYPH6dEk0aPswYRKiqgxjgsOb1SV1gYcd3xuYKSU BoYIA1rsO4MQ3ARSBwPHBCCtFCutblpVhh31DQQKFVDn4SJVccZZvGBlw PICQc4UUKltUSewAfy5BFNL4jupHoT8aVWlC7uPiyqaR8QURciPtzLIjC 5+QwFkTJjj4hCR78boz5wrKVakZ9zxPI7OlZIWZoSZQJ6/3LvxxCV+BMm YLU67ileSy3wYsDcUAO1dihEZcu9/2tjmHWJMWztk54i6MIwsxBKGvltO LNvd5y91+/aRjByrSudOAWHboHvCiqfK1ys7CRficzWjkVIjJ8X4WuSlo Q==; X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="351972898" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="351972898" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 07:48:20 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10592"; a="801780631" X-IronPort-AV: E=Sophos;i="5.97,224,1669104000"; d="scan'208";a="801780631" Received: from tdnguye2-mobl.amr.corp.intel.com (HELO [10.212.127.230]) ([10.212.127.230]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jan 2023 07:48:20 -0800 Message-ID: Date: Tue, 17 Jan 2023 09:48:19 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.4.2 Subject: Re: [PATCH] ALSA: hda: Do not unset preset when cleaning up codec Content-Language: en-US To: Cezary Rojewski , alsa-devel@alsa-project.org, tiwai@suse.com References: <20230117154734.950487-1-cezary.rojewski@intel.com> From: Pierre-Louis Bossart In-Reply-To: <20230117154734.950487-1-cezary.rojewski@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hdegoede@redhat.com, broonie@kernel.org, amadeuszx.slawinski@linux.intel.com Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On 1/17/23 09:47, Cezary Rojewski wrote: > 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 struct snd_card pointer > what cannot be fulfilled on ASoC side until a card is attempted to be very hard to follow. Is there a spurious 'what' to be removed? Or is there missing text? Please consider rewording with simpler sentences. > bound and its component probing is triggered. > > 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. > > Signed-off-by: Cezary Rojewski > --- > > This is a continuation of a discussion that begun in the middle of 2022 > [1] and was part of a larger series addressing several HDAudio topics. > > Single rmmod on ASoC's codec driver module is enough to cause a panic. > Given our results, no regression shows up with modprobe/rmmod on > snd_hda_intel side with this patch applied. > > [1]: https://lore.kernel.org/alsa-devel/20220706120230.427296-2-cezary.rojewski@intel.com/ > > sound/pci/hda/hda_codec.c | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c > index edd653ece70d..ac1cc7c5290e 100644 > --- a/sound/pci/hda/hda_codec.c > +++ b/sound/pci/hda/hda_codec.c > @@ -795,7 +795,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);