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 66BCBC001B0 for ; Mon, 24 Jul 2023 11:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjGXLRb (ORCPT ); Mon, 24 Jul 2023 07:17:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230317AbjGXLR0 (ORCPT ); Mon, 24 Jul 2023 07:17:26 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EE4810EC for ; Mon, 24 Jul 2023 04:17:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1690197425; x=1721733425; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=qrAfN4pFwmKEkCyDG2aU1NgUas7wKrBSvcRpy76R1jI=; b=ZzHiABt9YWTtMif2RtNG00UVLGNbRTmBbelQS6MubjOwBAH+70339eGd 0bfLEX7MgmyCq+B/OyDmfAIcmdaf0oMjc2EwtMJFIajz4yWHytAd1njaa DoH+uP/xfjfu1d0utQLb5EkFjo4txZ5aC/4tsUP2VGWzEKBh0LBAFIOl/ UQKEB0+ucGahUhtnbQzjO+CWb1UgMV9TeJMmRuhVMXxyyiXUBUKrH+H4l wALCQtLwnBBZNqt/Xg0AlP1cB1joRd7e1ZzfSVw5eMR239tHT1A43qbC/ vPfyCuJTgBbKq+lFehDEhCNl3xGHgZZfv7zPLoMOmSc3SUJeIHClznaPS g==; X-IronPort-AV: E=McAfee;i="6600,9927,10780"; a="371012552" X-IronPort-AV: E=Sophos;i="6.01,228,1684825200"; d="scan'208";a="371012552" 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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