* [PATCH] firmware: Fix memory leak in error path
@ 2015-06-05 16:38 Firo Yang
2015-06-05 16:43 ` Julia Lawall
2015-06-06 3:13 ` Firo Yang
0 siblings, 2 replies; 3+ messages in thread
From: Firo Yang @ 2015-06-05 16:38 UTC (permalink / raw)
To: kernel-janitors
In error path, we forgot to free fw_work alloced by kzalloc.
This will make a memory leak. So just free it before return.
Signed-off-by: Firo Yang <firogm@gmail.com>
---
drivers/base/firmware_class.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 8c3aa3c..9c42883 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1307,8 +1307,10 @@ request_firmware_nowait(
fw_work->module = module;
fw_work->name = kstrdup_const(name, gfp);
- if (!fw_work->name)
+ if (!fw_work->name) {
+ kfree(fw_work);
return -ENOMEM;
+ }
fw_work->device = device;
fw_work->context = context;
fw_work->cont = cont;
--
2.4.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] firmware: Fix memory leak in error path
2015-06-05 16:38 [PATCH] firmware: Fix memory leak in error path Firo Yang
@ 2015-06-05 16:43 ` Julia Lawall
2015-06-06 3:13 ` Firo Yang
1 sibling, 0 replies; 3+ messages in thread
From: Julia Lawall @ 2015-06-05 16:43 UTC (permalink / raw)
To: kernel-janitors
On Sat, 6 Jun 2015, Firo Yang wrote:
> In error path, we forgot to free fw_work alloced by kzalloc.
> This will make a memory leak. So just free it before return.
>
> Signed-off-by: Firo Yang <firogm@gmail.com>
> ---
> drivers/base/firmware_class.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 8c3aa3c..9c42883 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1307,8 +1307,10 @@ request_firmware_nowait(
>
> fw_work->module = module;
> fw_work->name = kstrdup_const(name, gfp);
> - if (!fw_work->name)
> + if (!fw_work->name) {
> + kfree(fw_work);
> return -ENOMEM;
> + }
Maybe it would be better to unify the error handling code at the end of
the function, if things are being forgotten.
julia
> fw_work->device = device;
> fw_work->context = context;
> fw_work->cont = cont;
> --
> 2.4.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] firmware: Fix memory leak in error path
2015-06-05 16:38 [PATCH] firmware: Fix memory leak in error path Firo Yang
2015-06-05 16:43 ` Julia Lawall
@ 2015-06-06 3:13 ` Firo Yang
1 sibling, 0 replies; 3+ messages in thread
From: Firo Yang @ 2015-06-06 3:13 UTC (permalink / raw)
To: kernel-janitors
On Fri, Jun 05, 2015 at 06:43:33PM +0200, Julia Lawall wrote:
>On Sat, 6 Jun 2015, Firo Yang wrote:
>
>> In error path, we forgot to free fw_work alloced by kzalloc.
>> This will make a memory leak. So just free it before return.
>>
>> Signed-off-by: Firo Yang <firogm@gmail.com>
>> ---
>> drivers/base/firmware_class.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
>> index 8c3aa3c..9c42883 100644
>> --- a/drivers/base/firmware_class.c
>> +++ b/drivers/base/firmware_class.c
>> @@ -1307,8 +1307,10 @@ request_firmware_nowait(
>>
>> fw_work->module = module;
>> fw_work->name = kstrdup_const(name, gfp);
>> - if (!fw_work->name)
>> + if (!fw_work->name) {
>> + kfree(fw_work);
>> return -ENOMEM;
>> + }
>
>Maybe it would be better to unify the error handling code at the end of
>the function, if things are being forgotten.
Thanks Julia!
I will reconstruct the code.
Firo
>
>julia
>
>> fw_work->device = device;
>> fw_work->context = context;
>> fw_work->cont = cont;
>> --
>> 2.4.2
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>>
--
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-06 3:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-05 16:38 [PATCH] firmware: Fix memory leak in error path Firo Yang
2015-06-05 16:43 ` Julia Lawall
2015-06-06 3:13 ` Firo Yang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox