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 9155CC0015E for ; Mon, 24 Jul 2023 11:17:43 +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 737F5204; Mon, 24 Jul 2023 13:16:51 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 737F5204 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1690197461; bh=qrAfN4pFwmKEkCyDG2aU1NgUas7wKrBSvcRpy76R1jI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=u+8ebUXK2sEXH1F2pHaGLHqhpNFBZS6chF2nFg5MY1cl62v7ySzlRmrNW58eV5K7I kZvz90z+RNUpLfD1g/kDYs/Rb73ZDSVYK28GUBsshn5pdHgoIqHmLoPgYcl4FUNf0T IhyQrzoxVeAQ4TzhGS2MCy2CNahoso8AI5u1O2ds= Received: by alsa1.perex.cz (Postfix, from userid 50401) id DBC98F80535; Mon, 24 Jul 2023 13:16:43 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 0C5D5F801F5; Mon, 24 Jul 2023 13:16:42 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 8FE4EF8019B; Mon, 24 Jul 2023 13:16:37 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (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 7D132F80153 for ; Mon, 24 Jul 2023 13:16:31 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 7D132F80153 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=lXUfPz3n DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690197393; x=1721733393; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qrAfN4pFwmKEkCyDG2aU1NgUas7wKrBSvcRpy76R1jI=; b=lXUfPz3nq1RxBelKOMte0msTgF8hkjnenJcI/2i7IfBkb/YiPLi0bNYl HJfhjfgE1CuAA9TsDUMNnf8nKJesJUY6ZIPPXXGSU1QqCJu6lkAyXa06N pbkr7dAUVIb2B8AWDONO2cV/I13FjBb6P3byNfXiTNod5Ko5z2oA6GRKY Vh0G//53yiKLWR4II0ExoQvgONfFvnpQ49PqX0PGDIzMvmkTGxcIjOSJ+ C2OM+vKVVM9/uyybAq62OqbLEMzHudUyzipgNnoBWY4WINqkv7GjFLEi0 GVPt4VJfOa/vymPberqCKwhOJtmNjQsNINvn12ZG4ghQ9TnhYZp6wIWQk g==; X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="371012551" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="371012551" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Jul 2023 04:16:29 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="728873056" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="728873056" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga007.fm.intel.com with ESMTP; 24 Jul 2023 04:16:25 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qNtY7-00AGs2-0G; Mon, 24 Jul 2023 14:16:23 +0300 Date: Mon, 24 Jul 2023 14:16:22 +0300 From: Andy Shevchenko To: "Lu, Brent" Cc: Pierre-Louis Bossart , "alsa-devel@alsa-project.org" , "Rojewski, Cezary" , Liam Girdwood , Peter Ujfalusi , Bard Liao , Ranjani Sridharan , Kai Vehmanen , Mark Brown , Jaroslav Kysela , Takashi Iwai , "linux-kernel@vger.kernel.org" , "Zhi, Yong" , Ajye Huang , "Bhat, Uday M" , Terry Cheong , "Chiang, Mac" , "R, Dharageswari" , Kuninori Morimoto Subject: Re: [PATCH 1/2] ASoC: Intel: maxim-common: get codec number from ACPI Message-ID: References: <20230720092628.758834-1-brent.lu@intel.com> <20230720092628.758834-2-brent.lu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Message-ID-Hash: DTWPJJ2A4ST63XKZ5VR3FYRZJZN75R7D X-Message-ID-Hash: DTWPJJ2A4ST63XKZ5VR3FYRZJZN75R7D X-MailFrom: andriy.shevchenko@linux.intel.com 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 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: On Mon, Jul 24, 2023 at 11:06:02AM +0000, Lu, Brent wrote: > > > > +/* helper function to get the number of specific codec */ > > > > ...and leak a lot of reference counts... > > > > > > +static int get_num_codecs(const char *hid) { > > > > + struct acpi_device *adev = NULL; > > > > + int dev_num = 0; > > > > + > > > > + do { > > > > + adev = acpi_dev_get_next_match_dev(adev, hid, NULL, -1); > > > > > > Humm, I am a bit worried about reference counts. > > > > > > See > > > https://elixir.bootlin.com/linux/latest/source/drivers/acpi/utils.c#L9 > > > 16, it's not clear to me where the get() is done. > > > > > > Adding Andy to make sure this is done right. > > > > Thank you for Cc'ing. > > > > Yes, the above code is problematic. One has to use the respective for_each macro > > (defined nearby the used API). > > > > > > + if (adev) > > > > + dev_num++; > > > > + } while (adev != NULL); > > > > + > > > > + return dev_num; > > > > +} > Each invocation of acpi_dev_get_next_match_dev() calls acpi_dev_put() to release the > adev from previous call. And the last call returns NULL. It seems to me the reference count > should be fine. Is my understanding correct? Ah, right. sorry for the confusion. That's why we have a macro to not think about these details :-) > I saw the macro for_each_acpi_dev_match and re-write the function as follow. Thanks for > suggesting using the macro. > > /* helper function to get the number of specific codec */ > static int get_num_codecs(const char *hid) { > struct acpi_device *adev; > int dev_num = 0; size_t here or at least unsigned int is more correct. > for_each_acpi_dev_match(adev, hid, NULL, -1) > dev_num++; > > return dev_num; > } Otherwise, yes, that's what I have in mind. > Will test it in next few days. -- With Best Regards, Andy Shevchenko