lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 24 Jul 2023 11:06:02 +0000
From:   "Lu, Brent" <brent.lu@...el.com>
To:     Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
        Pierre-Louis Bossart <pierre-louis.bossart@...ux.intel.com>
CC:     "alsa-devel@...a-project.org" <alsa-devel@...a-project.org>,
        "Rojewski, Cezary" <cezary.rojewski@...el.com>,
        Liam Girdwood <liam.r.girdwood@...ux.intel.com>,
        Peter Ujfalusi <peter.ujfalusi@...ux.intel.com>,
        Bard Liao <yung-chuan.liao@...ux.intel.com>,
        Ranjani Sridharan <ranjani.sridharan@...ux.intel.com>,
        Kai Vehmanen <kai.vehmanen@...ux.intel.com>,
        Mark Brown <broonie@...nel.org>,
        "Jaroslav Kysela" <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Zhi, Yong" <yong.zhi@...el.com>,
        Ajye Huang <ajye_huang@...pal.corp-partner.google.com>,
        "Bhat, Uday M" <uday.m.bhat@...el.com>,
        Terry Cheong <htcheong@...omium.org>,
        "Chiang, Mac" <mac.chiang@...el.com>,
        "R, Dharageswari" <dharageswari.r@...el.com>,
        Kuninori Morimoto <kuninori.morimoto.gx@...esas.com>
Subject: RE: [PATCH 1/2] ASoC: Intel: maxim-common: get codec number from ACPI


> > > +/* 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;
> > > +}
> 
> --
> With Best Regards,
> Andy Shevchenko
> 
Hi Andy,

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?

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;

	for_each_acpi_dev_match(adev, hid, NULL, -1)
		dev_num++;

	return dev_num;
}

Will test it in next few days.

Regards,
Brent


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ