mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tang Bin <tangbin@cmss.chinamobile.com>
To: Srinivas Kandagatla <srinivas.kandagatla@oss.qualcomm.com>,
	srini@kernel.org, lgirdwood@gmail.com, broonie@kernel.org,
	perex@perex.cz, tiwai@suse.com
Cc: linux-sound@vger.kernel.org, linux-arm-msm@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Tang Bin <tangbin@cmss.chinamobile.com>
Subject: [PATCH v2] ASoC: qdsp6: q6routing: Fix memory leak on probe failure
Date: Wed, 28 Oct 2026 09:57:31 +0800	[thread overview]
Message-ID: <20261028015732.1985-1-tangbin@cmss.chinamobile.com> (raw)
In-Reply-To: <6078ca7f-a511-48d9-b5fb-a7b3339c8569@oss.qualcomm.com>

routing_data is allocated with kzalloc() and stored in a global static
pointer. If devm_snd_soc_register_component() fails, the probe function
returns directly without freeing routing_data. Since the remove callback
is not invoked on probe failure, this leads to a memory leak. On a probe
retry, a new routing_data overwrites the global pointer, permanently
losing the previous allocation.

Fix this by switching to devm_kzalloc_obj() for the allocation. This
ensures the memory is automatically freed by the device core if probe
fails or when the driver is unbound. Consequently, the manual kfree()
in the remove callback is no longer needed and must be removed to avoid
a double-free.

Fixes: e3a33673e845 ("ASoC: qdsp6: q6routing: Add q6routing driver")
Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com>
---
Changes in v2:
- Use devm_kzalloc_obj() to let the device core manage the memory
  lifecycle, as suggested by Srinivas Kandagatla. This eliminates the
  need for manual error handling and prevents a double-free in remove.

 sound/soc/qcom/qdsp6/q6routing.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sound/soc/qcom/qdsp6/q6routing.c b/sound/soc/qcom/qdsp6/q6routing.c
index d076c99f1..4816d4b9a 100644
--- a/sound/soc/qcom/qdsp6/q6routing.c
+++ b/sound/soc/qcom/qdsp6/q6routing.c
@@ -1209,7 +1209,7 @@ static int q6pcm_routing_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 
-	routing_data = kzalloc_obj(*routing_data);
+	routing_data = devm_kzalloc_obj(dev, *routing_data);
 	if (!routing_data)
 		return -ENOMEM;
 
@@ -1224,7 +1224,6 @@ static int q6pcm_routing_probe(struct platform_device *pdev)
 
 static void q6pcm_routing_remove(struct platform_device *pdev)
 {
-	kfree(routing_data);
 	routing_data = NULL;
 }
 
-- 
2.52.0.windows.1




  reply	other threads:[~2026-10-28  1:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  8:02 [PATCH] " Tang Bin
2026-10-27 14:44 ` Srinivas Kandagatla
2026-10-28  1:57   ` Tang Bin [this message]
2026-10-28 10:25     ` [PATCH v2] " Srinivas Kandagatla

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=20261028015732.1985-1-tangbin@cmss.chinamobile.com \
    --to=tangbin@cmss.chinamobile.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=srini@kernel.org \
    --cc=srinivas.kandagatla@oss.qualcomm.com \
    --cc=tiwai@suse.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

all inboxes | Powered by JetHome®