linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Curtis Malainey <cujomalainey@google.com>
To: Mark Brown <broonie@kernel.org>
Cc: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	rohkumar@qti.qualcomm.com, alsa-devel@alsa-project.org,
	bgoswami@codeaurora.org, Vinod Koul <vinod.koul@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	plai@codeaurora.org, linux-kernel@vger.kernel.org,
	Ajit Pandey <ajitp@codeaurora.org>,
	tiwai@suse.com, Liam Girdwood <liam.r.girdwood@linux.intel.com>,
	Matthias Reichl <hias@horus.com>,
	Rohit kumar <rohitkr@codeaurora.org>,
	asishb@codeaurora.org,
	Srini Kandagatla <srinivas.kandagatla@linaro.org>,
	Curtis Malainey <cujomalainey@chromium.org>,
	Dylan Reid <dgreid@google.com>
Subject: Re: [alsa-devel] [PATCH] ASoC: soc-core: Fix null pointer dereference in soc_find_component
Date: Fri, 25 Jan 2019 09:32:38 +0800	[thread overview]
Message-ID: <CAOReqxgow+f=LCQ++JM7npFC5nzU_aEhCV72n6A-jhRsJaPybw@mail.gmail.com> (raw)
In-Reply-To: <20190124192652.GK5641@sirena.org.uk>

[-- Attachment #1: Type: text/plain, Size: 1058 bytes --]

I have a patch to fix the memory leak but I haven't been able to test
it yet because I am remote right now and I accidentally bootlooped the
AMD device I am working on. I will have this tested early next week.
Here is the patch for anyone interested.

Curtis Malainey | Software Engineer | cujomalainey@google.com | 650-898-3849


On Fri, Jan 25, 2019 at 3:26 AM Mark Brown <broonie@kernel.org> wrote:
>
> On Thu, Jan 24, 2019 at 01:07:17PM -0600, Pierre-Louis Bossart wrote:
>
> > Thanks for the feedback, will send a formal patch with the helper and
> > machine driver changes after I test more with the legacy drivers. Do you
> > have a preference for one patch that deals with multiple machines drivers in
> > one shot, or individual patches? The latter are nicer for backports (e.g.
> > for Chrome), the former nicer for maintainers...
>
> More patches is good, it doesn't make a huge difference if I get one big
> patch or a series of repetitive patches - big serieses are more of an
> issue if they're all different patches needing individual review.

[-- Attachment #2: 0001-ASoC-soc-core-clear-platform-pointers-on-error.patch --]
[-- Type: application/octet-stream, Size: 2404 bytes --]

From f5a22ae376188ee1ad54efd1274940295245eef3 Mon Sep 17 00:00:00 2001
From: Curtis Malainey <cujomalainey@chromium.org>
Date: Tue, 22 Jan 2019 21:23:21 -0800
Subject: [PATCH] ASoC: soc-core: clear platform pointers on error

Originally snd_soc_init_platform was not cleaning up its pointers, this
was fixed to always reallocate dynamic memory but created a memory leak
when snd_soc_init_platform was called multiple times during the same
probe attempt and also threw away any changes made to the struct between
calls. In order to acoid reallocating memory that is still valid, the
behaviour will be changed to clear the dynamically set pointers on a
probe error and a unregister event and snd_soc_init_platform will go
back to its original behaviour of only allocating null pointers so it will
stop throwing away valid changes.

Change-Id: Ibdeac041868dec095588cd339e2499569e35ef5c
Signed-off-by: Curtis Malainey <cujomalainey@chromium.org>
---
 sound/soc/soc-core.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 8a58fa86675a..b7354ea4725e 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1049,7 +1049,7 @@ static int snd_soc_init_platform(struct snd_soc_card *card,
 	 *	soc.h :: struct snd_soc_dai_link
 	 */
 	/* convert Legacy platform link */
-	if (!platform || dai_link->legacy_platform) {
+	if (!platform) {
 		platform = devm_kzalloc(card->dev,
 				sizeof(struct snd_soc_dai_link_component),
 				GFP_KERNEL);
@@ -1072,6 +1072,24 @@ static int snd_soc_init_platform(struct snd_soc_card *card,
 	return 0;
 }
 
+static void soc_cleanup_platform(struct snd_soc_card *card)
+{
+	struct snd_soc_dai_link *link;
+	int i;
+	/*
+	 * FIXME
+	 *
+	 * this function should be removed with snd_soc_init_platform
+	 */
+
+	for_each_card_prelinks(card, i, link) {
+		if (link->legacy_platform) {
+			link->legacy_platform = 0;
+			link->platforms       = NULL;
+		}
+	}
+}
+
 static int snd_soc_init_multicodec(struct snd_soc_card *card,
 				   struct snd_soc_dai_link *dai_link)
 {
@@ -2016,6 +2034,7 @@ static int soc_cleanup_card_resources(struct snd_soc_card *card)
 	/* remove and free each DAI */
 	soc_remove_dai_links(card);
 	soc_remove_pcm_runtimes(card);
+	soc_cleanup_platform(card);
 
 	/* remove auxiliary devices */
 	soc_remove_aux_devices(card);
-- 
2.20.1.321.g9e740568ce-goog


  reply	other threads:[~2019-01-25  1:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-11  8:14 [PATCH] ASoC: soc-core: Fix null pointer dereference in soc_find_component Rohit kumar
2019-01-11 15:44 ` [alsa-devel] " Pierre-Louis Bossart
2019-01-11 21:49   ` Pierre-Louis Bossart
2019-01-12  6:07     ` Rohit kumar
2019-01-14 15:40       ` Liam Girdwood
2019-01-15  0:06     ` Mark Brown
2019-01-15  3:08       ` Pierre-Louis Bossart
2019-01-15 19:35       ` Pierre-Louis Bossart
2019-01-15 21:07         ` Mark Brown
2019-01-15 21:11         ` Matthias Reichl
2019-01-15 21:16           ` Pierre-Louis Bossart
2019-01-15 21:41             ` Mark Brown
2019-01-15 21:48               ` Matthias Reichl
2019-01-18 23:02             ` Pierre-Louis Bossart
     [not found]               ` <CAOReqxjhZAzOpr-bGcV6uxPsOEid--Ym2Y0YZMHkybgZSePvtQ@mail.gmail.com>
2019-01-19  1:15                 ` Curtis Malainey
2019-01-21 18:30                   ` Mark Brown
2019-01-22 20:11                   ` Pierre-Louis Bossart
2019-01-23  1:36                     ` Curtis Malainey
2019-01-23  2:01                       ` Pierre-Louis Bossart
2019-01-24 18:44                         ` Mark Brown
2019-01-24 19:07                           ` Pierre-Louis Bossart
2019-01-24 19:26                             ` Mark Brown
2019-01-25  1:32                               ` Curtis Malainey [this message]
2019-01-21 19:17               ` Mark Brown
2019-01-14 23:26 ` Mark Brown

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='CAOReqxgow+f=LCQ++JM7npFC5nzU_aEhCV72n6A-jhRsJaPybw@mail.gmail.com' \
    --to=cujomalainey@google.com \
    --cc=ajitp@codeaurora.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=asishb@codeaurora.org \
    --cc=bgoswami@codeaurora.org \
    --cc=broonie@kernel.org \
    --cc=cujomalainey@chromium.org \
    --cc=dgreid@google.com \
    --cc=hias@horus.com \
    --cc=lgirdwood@gmail.com \
    --cc=liam.r.girdwood@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=plai@codeaurora.org \
    --cc=rohitkr@codeaurora.org \
    --cc=rohkumar@qti.qualcomm.com \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    --cc=vinod.koul@linaro.org \
    /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;
as well as URLs for NNTP newsgroup(s).