Linux USB
 help / color / mirror / Atom feed
From: Zongmin Zhou <min_halo@163.com>
To: nikolayof23@gmail.com, david-b@pacbell.net,
	gregkh@linuxfoundation.org, kees@kernel.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: [PATCH v2] usb: host: sl811_cs: fix memory leak on probe failure
Date: Tue,  1 Sep 2026 10:03:52 +0800	[thread overview]
Message-ID: <20260901020352.20252-1-min_halo@163.com> (raw)
In-Reply-To: <apWWnyGbVFJ8SbiG@archlinux>

From: Zongmin Zhou <zhouzongmin@kylinos.cn>

sl811_cs_probe() leaks the local_info_t allocated into link->priv when
sl811_cs_config() fails: the only kfree() lives in the remove callback
sl811_cs_detach(), which the PCMCIA core never calls for a device whose
probe failed.

Free the private data when sl811_cs_config() fails.

Fixes: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config() functions")
Reviewed-by: Nikolay Kulikov <nikolayof23@gmail.com>
Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
Changes in v2:
- Fix the Fixes tag to 15b99ac17295, the commit that made
  sl811_cs_config() failures observable as probe failures.
- Add Reviewed-by from Nikolay Kulikov.

 drivers/usb/host/sl811_cs.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index ada91ca33f65..fd0cd541bf53 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -177,6 +177,7 @@ failed:
 static int sl811_cs_probe(struct pcmcia_device *link)
 {
 	local_info_t *local;
+	int ret;

 	local = kzalloc_obj(local_info_t);
 	if (!local)
@@ -184,7 +185,11 @@ static int sl811_cs_probe(struct pcmcia_device *link)
 	local->p_dev = link;
 	link->priv = local;

-	return sl811_cs_config(link);
+	ret = sl811_cs_config(link);
+	if (ret)
+		kfree(local);
+
+	return ret;
 }

 static const struct pcmcia_device_id sl811_ids[] = {
--
2.34.1

No virus found
		Checked by Hillstone Network AntiVirus


      reply	other threads:[~2026-09-01  2:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27  7:41 [PATCH] usb: host: sl811_cs: fix memory leak on probe failure Zongmin Zhou
2026-08-28 17:36 ` Nikolay Kulikov
2026-08-31  6:11   ` Zongmin Zhou
2026-08-31 14:58     ` Nikolay Kulikov
2026-09-01  2:03       ` Zongmin Zhou [this message]

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=20260901020352.20252-1-min_halo@163.com \
    --to=min_halo@163.com \
    --cc=david-b@pacbell.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kees@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nikolayof23@gmail.com \
    --cc=zhouzongmin@kylinos.cn \
    /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