From: Nikolay Kulikov <nikolayof23@gmail.com>
To: Zongmin Zhou <min_halo@163.com>
Cc: gregkh@linuxfoundation.org, kees@kernel.org, david-b@pacbell.net,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
Zongmin Zhou <zhouzongmin@kylinos.cn>
Subject: Re: [PATCH] usb: host: sl811_cs: fix memory leak on probe failure
Date: Mon, 31 Aug 2026 17:58:39 +0300 [thread overview]
Message-ID: <apWWnyGbVFJ8SbiG@archlinux> (raw)
In-Reply-To: <a4e969d7-4601-407e-a4ee-beb85846d711@163.com>
On Mon, Aug 31, 2026 at 02:11:16PM +0800, Zongmin Zhou wrote:
>
> 在 2026/8/29 01:36, Nikolay Kulikov 写道:
> > On Thu, Aug 27, 2026 at 03:41:20PM +0800, Zongmin Zhou wrote:
> > > 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: c6de2b64eb57 ("[PATCH] USB: add sl811_cs support")
> > The code looks good to me, but I have a question regarding the Fixes
> > tag.
> >
> > In the commit you cited, a failure triggered a call to
> > sl811_cs_detach(), which freed that memory. However, that behavior was
> > changed in commit
> >
> > f8cfa618dccb ("[PATCH] pcmcia: unify attach, EVENT_CARD_INSERTION handlers into one probe callback")
> >
> > where the call was removed, leaving the memory unfreed. Shouldn't that
> > be the commit referenced in the Fixes?
> Hi Nikolay,
>
> You're right that c6de2b64eb57 did not introduce the leak -- but neither did
> f8cfa618dccb.
> The leak was introduced by 15b99ac17295 ("[PATCH] pcmcia: add return value
> to _config() functions")
>
> f8cfa618dccb dropped the detach-on-failure path because registration
> moved into the core, and its probe ended with
> sl811_cs_config(link);
> return 0;
> A config failure was never propagated, so probe() always succeeded
> after the allocation and it remained paired with the kfree() in
> remove(). No leak either.
>
> 15b99ac17295 made sl811_cs_config() return -ENODEV and the probe return
> that value -- the first time probe could fail after the allocation.
> Since the core never calls ->remove() for a failed probe, link->priv
> leaked from then on.
>
> If you agree, I'll send a v2 with
> Fixes: 15b99ac17295 ("[PATCH] pcmcia: add return value to _config()
> functions")
Yes, it really should be 15b99ac17295.
In v2, you can add my
Reviewed-by: Nikolay Kulikov <nikolayof23@gmail.com>
>
> Thanks,
> Zongmin
> >
> >
> > Thanks,
> > Nikolay
>
>
next prev parent reply other threads:[~2026-08-31 14:58 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 [this message]
2026-09-01 2:03 ` [PATCH v2] " Zongmin Zhou
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=apWWnyGbVFJ8SbiG@archlinux \
--to=nikolayof23@gmail.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=min_halo@163.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