From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: Cezary Rojewski <cezary.rojewski@intel.com>,
alsa-devel@alsa-project.org,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
kjlu@umn.edu, Mark Brown <broonie@kernel.org>,
Jie Yang <yang.jie@linux.intel.com>,
Takashi Iwai <tiwai@suse.com>,
Liam Girdwood <liam.r.girdwood@linux.intel.com>,
emamd001@umn.edu, smccaman@umn.edu,
Thomas Gleixner <tglx@linutronix.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Enrico Weigelt <info@metux.net>,
linux-kernel@vger.kernel.org
Subject: Re: [alsa-devel] [PATCH v2] ASoC: Intel: Skylake: prevent memory leak in snd_skl_parse_uuids
Date: Wed, 25 Sep 2019 12:05:28 -0500 [thread overview]
Message-ID: <13f4bd40-dbaa-e24e-edca-4b4acff9d9c5@linux.intel.com> (raw)
In-Reply-To: <20190925161922.22479-1-navid.emamdoost@gmail.com>
On 9/25/19 11:19 AM, Navid Emamdoost wrote:
> In snd_skl_parse_uuids if allocation for module->instance_id fails, the
> allocated memory for module shoulde be released. I changes the
> allocation for module to use devm_kzalloc to be resource_managed
> allocation and avoid the release in error path.
if you use devm_, don't you need to fix the error path as well then, I
see a kfree(uuid) in skl_freeup_uuid_list().
I am not very familiar with this code but the error seems to be that the
list_add_tail() is called after the module->instance_id is allocated, so
there is a risk that the module allocated earlier is not freed (since
it's not yet added to the list). Freeing the module as done in patch 1
works, using devm_ without fixing the error path does not seem correct
to me.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> Changes in v2:
> - Changed the allocation for module from kzalloc to devm_kzalloc
> ---
> sound/soc/intel/skylake/skl-sst-utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
> index d43cbf4a71ef..ac37f04b0eea 100644
> --- a/sound/soc/intel/skylake/skl-sst-utils.c
> +++ b/sound/soc/intel/skylake/skl-sst-utils.c
> @@ -284,7 +284,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
> */
>
> for (i = 0; i < num_entry; i++, mod_entry++) {
> - module = kzalloc(sizeof(*module), GFP_KERNEL);
> + module = devm_kzalloc(ctx->dev, sizeof(*module), GFP_KERNEL);
> if (!module) {
> ret = -ENOMEM;
> goto free_uuid_list;
>
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
WARNING: multiple messages have this Message-ID (diff)
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Navid Emamdoost <navid.emamdoost@gmail.com>
Cc: emamd001@umn.edu, smccaman@umn.edu, kjlu@umn.edu,
Cezary Rojewski <cezary.rojewski@intel.com>,
Liam Girdwood <liam.r.girdwood@linux.intel.com>,
Jie Yang <yang.jie@linux.intel.com>,
Mark Brown <broonie@kernel.org>, Jaroslav Kysela <perex@perex.cz>,
Takashi Iwai <tiwai@suse.com>, Enrico Weigelt <info@metux.net>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Thomas Gleixner <tglx@linutronix.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ASoC: Intel: Skylake: prevent memory leak in snd_skl_parse_uuids
Date: Wed, 25 Sep 2019 12:05:28 -0500 [thread overview]
Message-ID: <13f4bd40-dbaa-e24e-edca-4b4acff9d9c5@linux.intel.com> (raw)
In-Reply-To: <20190925161922.22479-1-navid.emamdoost@gmail.com>
On 9/25/19 11:19 AM, Navid Emamdoost wrote:
> In snd_skl_parse_uuids if allocation for module->instance_id fails, the
> allocated memory for module shoulde be released. I changes the
> allocation for module to use devm_kzalloc to be resource_managed
> allocation and avoid the release in error path.
if you use devm_, don't you need to fix the error path as well then, I
see a kfree(uuid) in skl_freeup_uuid_list().
I am not very familiar with this code but the error seems to be that the
list_add_tail() is called after the module->instance_id is allocated, so
there is a risk that the module allocated earlier is not freed (since
it's not yet added to the list). Freeing the module as done in patch 1
works, using devm_ without fixing the error path does not seem correct
to me.
>
> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
> Changes in v2:
> - Changed the allocation for module from kzalloc to devm_kzalloc
> ---
> sound/soc/intel/skylake/skl-sst-utils.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sound/soc/intel/skylake/skl-sst-utils.c b/sound/soc/intel/skylake/skl-sst-utils.c
> index d43cbf4a71ef..ac37f04b0eea 100644
> --- a/sound/soc/intel/skylake/skl-sst-utils.c
> +++ b/sound/soc/intel/skylake/skl-sst-utils.c
> @@ -284,7 +284,7 @@ int snd_skl_parse_uuids(struct sst_dsp *ctx, const struct firmware *fw,
> */
>
> for (i = 0; i < num_entry; i++, mod_entry++) {
> - module = kzalloc(sizeof(*module), GFP_KERNEL);
> + module = devm_kzalloc(ctx->dev, sizeof(*module), GFP_KERNEL);
> if (!module) {
> ret = -ENOMEM;
> goto free_uuid_list;
>
next prev parent reply other threads:[~2019-09-25 17:06 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 16:19 [PATCH v2] ASoC: Intel: Skylake: prevent memory leak in snd_skl_parse_uuids Navid Emamdoost
2019-09-25 17:05 ` Pierre-Louis Bossart [this message]
2019-09-25 17:05 ` Pierre-Louis Bossart
2019-09-27 2:55 ` Navid Emamdoost
2019-09-27 13:14 ` [alsa-devel] " Pierre-Louis Bossart
2019-09-27 13:14 ` Pierre-Louis Bossart
2019-09-27 15:10 ` [alsa-devel] " Cezary Rojewski
2019-09-27 15:10 ` Cezary Rojewski
2019-09-27 15:33 ` [alsa-devel] " Andy Shevchenko
2019-09-27 15:33 ` Andy Shevchenko
2019-09-27 16:37 ` [alsa-devel] " Pierre-Louis Bossart
2019-09-27 16:37 ` Pierre-Louis Bossart
2019-09-27 20:39 ` Andy Shevchenko
2019-09-27 20:39 ` Andy Shevchenko
2019-09-27 22:25 ` Pierre-Louis Bossart
2019-09-27 22:25 ` Pierre-Louis Bossart
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=13f4bd40-dbaa-e24e-edca-4b4acff9d9c5@linux.intel.com \
--to=pierre-louis.bossart@linux.intel.com \
--cc=alsa-devel@alsa-project.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=broonie@kernel.org \
--cc=cezary.rojewski@intel.com \
--cc=emamd001@umn.edu \
--cc=gregkh@linuxfoundation.org \
--cc=info@metux.net \
--cc=kjlu@umn.edu \
--cc=liam.r.girdwood@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=navid.emamdoost@gmail.com \
--cc=smccaman@umn.edu \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.com \
--cc=yang.jie@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.