Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2973674rwo; Mon, 24 Jul 2023 04:31:40 -0700 (PDT) X-Google-Smtp-Source: APBJJlFTACkTeEekDOXb/vydGuwYp9pfqH6r2Ed7xtKrwOzg7dSYsbf5XXazerEK4A6v/Q7g6nCo X-Received: by 2002:a05:6a20:1446:b0:132:c07c:f042 with SMTP id a6-20020a056a20144600b00132c07cf042mr9382777pzi.15.1690198300533; Mon, 24 Jul 2023 04:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690198300; cv=none; d=google.com; s=arc-20160816; b=ZIXZJsM7YnQlKIZ0mTdWBhCjul/d2czORJWILYVH8l2V1gK/1FuP8oaBcrq8Ajf38P VTyxdNnPrb3Hz87T1EtATlaEEPc7bcjfMOBLx8mbjPTRDy7WhDLtblJcjdk8TequFaJW QPP4CyeT3njjIqATOm7N5j00z/cJ6LHmPStrByGBhAQ0+zG1iOWUtqP3uXYg3MdIU7fZ fxk3Vdp7XoQWhJhQ1axONchscBIQL+hHkaXhNKBpN43S5AvwxVhA/2P87y0eThcnZCNa ziBuT3U9Il1+ybeKns+hg0Y3oXnbc9oHzSK9VERf5F0U0Yy6uvXL5Ms7wxP2FyjnQ7h4 gGLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=/gSMx8bho4YSmLnW1ROtZYTcGFlHotAzV8LWEb5rLvA=; fh=5t410Yf+Y365YbL/Q0PHWhA2z53NL+lkdD1seh27+ow=; b=LYGOfVr55MGRlIsiSoAQJzSf938oYxZ88bTzWhk+fFDGLh8SF4vAdaARA0UCqJKOM6 8L3VDeci21Pzs8/gBu+Sv6Ho6tB2VUUEFMuOrc+ltBZhK8o9PX34bge+fkmzReIda8F1 yDzDfa3PkkXJd4Z2SXhtEqxkJ5YpbQYBVIWOwYvYjhedwj4F/zUxs0HEYdzIDocKaHLM cu/g4Fip4USPrQpkWVJz26QwO0gnfdcedLoC+Ul5SON//aRCReTM6RYpHtV0m5gNsdal OsB1ZPkES18Xr5cz+bnUc4yCiwv3lbaGztbmVWm5qoKfwa3hi1oV6x6S2MerP/kTVSwr zSmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZzHiABt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c10-20020a63d14a000000b0055c872b768fsi8604675pgj.531.2023.07.24.04.31.26; Mon, 24 Jul 2023 04:31:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZzHiABt9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230140AbjGXLRa (ORCPT + 99 others); Mon, 24 Jul 2023 07:17:30 -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 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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