From: Greg KH <gregkh@linuxfoundation.org>
To: Zijun Hu <quic_zijuhu@quicinc.com>
Cc: rafael@kernel.org, davem@davemloft.net, madalin.bucur@nxp.com,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v1] devres: Fix memory leakage due to driver API devm_free_percpu()
Date: Wed, 19 Jun 2024 16:53:05 +0200 [thread overview]
Message-ID: <2024061949-dullness-snippet-da5a@gregkh> (raw)
In-Reply-To: <1718804281-1796-1-git-send-email-quic_zijuhu@quicinc.com>
On Wed, Jun 19, 2024 at 09:38:01PM +0800, Zijun Hu wrote:
> It will cause memory leakage when use driver API devm_free_percpu()
> to free memory allocated by devm_alloc_percpu(), fixed by using
> devres_release() instead of devres_destroy() within devm_free_percpu().
>
> Fixes: ff86aae3b411 ("devres: add devm_alloc_percpu()")
> Cc: stable@vger.kernel.org
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
> ---
> drivers/base/devres.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/devres.c b/drivers/base/devres.c
> index 3df0025d12aa..082dbb296b6e 100644
> --- a/drivers/base/devres.c
> +++ b/drivers/base/devres.c
> @@ -1222,7 +1222,11 @@ EXPORT_SYMBOL_GPL(__devm_alloc_percpu);
> */
> void devm_free_percpu(struct device *dev, void __percpu *pdata)
> {
> - WARN_ON(devres_destroy(dev, devm_percpu_release, devm_percpu_match,
> + /*
> + * Use devres_release() to prevent memory leakage as
> + * devm_free_pages() does.
> + */
> + WARN_ON(devres_release(dev, devm_percpu_release, devm_percpu_match,
> (__force void *)pdata));
> }
> EXPORT_SYMBOL_GPL(devm_free_percpu);
> --
> 2.7.4
>
>
These are good fixes, how are you finding them? Care to write up some
kunit tests for the devres apis?
thanks,
greg k-h
next prev parent reply other threads:[~2024-06-19 14:53 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-19 13:38 [PATCH v1] devres: Fix memory leakage due to driver API devm_free_percpu() Zijun Hu
2024-06-19 14:53 ` Greg KH [this message]
2024-06-20 11:56 ` quic_zijuhu
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=2024061949-dullness-snippet-da5a@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=madalin.bucur@nxp.com \
--cc=quic_zijuhu@quicinc.com \
--cc=rafael@kernel.org \
--cc=stable@vger.kernel.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