[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <91853ea9-888c-4062-8d90-98627a0ce8d7@quicinc.com>
Date: Thu, 20 Jun 2024 19:56:45 +0800
From: quic_zijuhu <quic_zijuhu@...cinc.com>
To: Greg KH <gregkh@...uxfoundation.org>
CC: <rafael@...nel.org>, <davem@...emloft.net>, <madalin.bucur@....com>,
<linux-kernel@...r.kernel.org>, <stable@...r.kernel.org>
Subject: Re: [PATCH v1] devres: Fix memory leakage due to driver API
devm_free_percpu()
On 6/19/2024 10:53 PM, Greg KH wrote:
> 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@...r.kernel.org
>> Signed-off-by: Zijun Hu <quic_zijuhu@...cinc.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?
>
find them by reading code.😀
> thanks,
>
> greg k-h
Powered by blists - more mailing lists