public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Lu, Brent" <brent.lu@intel.com>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	"Rojewski, Cezary" <cezary.rojewski@intel.com>,
	Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Peter Ujfalusi <peter.ujfalusi@linux.intel.com>,
	Bard Liao <yung-chuan.liao@linux.intel.com>,
	Ranjani Sridharan <ranjani.sridharan@linux.intel.com>,
	Kai Vehmanen <kai.vehmanen@linux.intel.com>,
	Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
	Takashi Iwai <tiwai@suse.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Zhi, Yong" <yong.zhi@intel.com>,
	Ajye Huang <ajye_huang@compal.corp-partner.google.com>,
	"Bhat, Uday M" <uday.m.bhat@intel.com>,
	Terry Cheong <htcheong@chromium.org>,
	"Chiang, Mac" <mac.chiang@intel.com>,
	"R, Dharageswari" <dharageswari.r@intel.com>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Subject: Re: [PATCH 1/2] ASoC: Intel: maxim-common: get codec number from ACPI
Date: Mon, 24 Jul 2023 14:16:22 +0300	[thread overview]
Message-ID: <ZL5dhosg28uIpcFd@smile.fi.intel.com> (raw)
In-Reply-To: <CY5PR11MB62579D3B679BB437017529D79702A@CY5PR11MB6257.namprd11.prod.outlook.com>

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



  reply	other threads:[~2023-07-24 11:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  9:26 [PATCH 0/2] Intel: sof_rt5682: remove quirk flag Brent Lu
2023-07-20  9:26 ` [PATCH 1/2] ASoC: Intel: maxim-common: get codec number from ACPI Brent Lu
2023-07-24  9:08   ` Pierre-Louis Bossart
2023-07-24  9:52     ` Andy Shevchenko
2023-07-24 11:06       ` Lu, Brent
2023-07-24 11:16         ` Andy Shevchenko [this message]
2023-07-26  6:16           ` Lu, Brent
2023-07-26  8:47   ` Liao, Bard
2023-07-26 11:25     ` Liao, Bard
2023-07-27  2:14     ` Lu, Brent
2023-07-27  3:21       ` Liao, Bard
2023-07-27  5:41         ` Pierre-Louis Bossart
2023-07-27 11:36           ` Mark Brown
2023-07-28  6:12         ` Lu, Brent
2023-07-20  9:26 ` [PATCH 2/2] ASoC: Intel: sof_rt5682: remove SOF_MAX98390_TWEETER_SPEAKER_PRESENT flag Brent Lu
2023-07-21  9:53 ` [PATCH 0/2] Intel: sof_rt5682: remove quirk flag Kai Vehmanen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZL5dhosg28uIpcFd@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=ajye_huang@compal.corp-partner.google.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=brent.lu@intel.com \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=dharageswari.r@intel.com \
    --cc=htcheong@chromium.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mac.chiang@intel.com \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=uday.m.bhat@intel.com \
    --cc=yong.zhi@intel.com \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox