Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEA8AC4727E for ; Wed, 30 Sep 2020 09:40:08 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9EBA42075F for ; Wed, 30 Sep 2020 09:40:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="SkfiBzR9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9EBA42075F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 05A7617C0; Wed, 30 Sep 2020 11:39:16 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 05A7617C0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1601458806; bh=2iBURT3bkUoZYEVeCFxMQrz+DrwlFqJXzhSCVFILoUQ=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=SkfiBzR9eI73w27YKOJihDCa0qVsKHLeoYOAWp08vHDHugUjwkRXcY1xjUloThaqi v8ljAYl+y4HzXTuxYMGsBI4aGML8+ScC0DLshMxR1aBCm/32+0fkOz+Ys7+v78YNAO 8yETk59SfqU3AOb8jBt/b8wnvRb1f54JFZDtnbDg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 924E3F800DF; Wed, 30 Sep 2020 11:39:15 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id BA047F800AB; Wed, 30 Sep 2020 11:39:14 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id D77E6F800AB for ; Wed, 30 Sep 2020 11:39:04 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz D77E6F800AB X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8B2A0AF21; Wed, 30 Sep 2020 09:39:04 +0000 (UTC) Date: Wed, 30 Sep 2020 11:39:04 +0200 Message-ID: From: Takashi Iwai To: Jaroslav Kysela Subject: Re: [PATCH] ALSA: hda - Don't register a cb func if it is registered already In-Reply-To: <8da67a4f-d9a4-14a0-a4b0-d93f7cb649ce@perex.cz> References: <20200930055146.5665-1-hui.wang@canonical.com> <8da67a4f-d9a4-14a0-a4b0-d93f7cb649ce@perex.cz> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: Hui Wang , alsa-devel@alsa-project.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Wed, 30 Sep 2020 11:28:59 +0200, Jaroslav Kysela wrote: > > Dne 30. 09. 20 v 11:21 Takashi Iwai napsal(a): > > On Wed, 30 Sep 2020 09:19:50 +0200, > > Jaroslav Kysela wrote: > >> > >> Dne 30. 09. 20 v 7:51 Hui Wang napsal(a): > >>> If the caller of enable_callback_mst() passes a cb func, the callee > >>> function will malloc memory and link this cb func to the list > >>> unconditionally. This will introduce problem if caller is in the > >>> hda_codec_ops.init() since the init() will be repeatedly called in the > >>> codec rt_resume(). > >>> > >>> So far, the patch_hdmi.c and patch_ca0132.c call enable_callback_mst() > >>> in the hda_codec_ops.init(). > >> > >> Won't be better to handle this double invocation at the callback call time? I > >> believe that some refcounting and pointing to one allocated callback structure > >> for all instances is better. > > > > IMO, Hui's fix is correct in this case; otherwise it'll result in > > endless number of allocations at each time the runtime resume is > > performed. So I'm going to take it as is. > > I meant to allocate the structure only once with refcounting and multiple > invocation protection. In the proposed change, you lose the > bindings. AFAIUC, it won't lose any functionality. snd_hda_jack_detect_enable_callback() would chain the callback function if a jack object has been already created, and this additional check will just prevent the doubly registration of the very same callback when called multiple times. thanks, Takashi