All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] firmware: Fix memory leak in error path
@ 2015-06-06  5:48 Firo Yang
  2015-06-06  5:58 ` Ming Lei
  2015-08-05 22:10 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Firo Yang @ 2015-06-06  5:48 UTC (permalink / raw)
  To: kernel-janitors

Eliminate a memory leak by unifying the error handling code
at the end of the function.

Signed-off-by: Firo Yang <firogm@gmail.com>
---
 drivers/base/firmware_class.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 8c3aa3c..5bb098b 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -1299,6 +1299,7 @@ request_firmware_nowait(
 	const char *name, struct device *device, gfp_t gfp, void *context,
 	void (*cont)(const struct firmware *fw, void *context))
 {
+	int rc;
 	struct firmware_work *fw_work;
 
 	fw_work = kzalloc(sizeof(struct firmware_work), gfp);
@@ -1307,8 +1308,11 @@ request_firmware_nowait(
 
 	fw_work->module = module;
 	fw_work->name = kstrdup_const(name, gfp);
-	if (!fw_work->name)
-		return -ENOMEM;
+	if (!fw_work->name) {
+		rc = -ENOMEM;
+		goto free_work;
+	}
+
 	fw_work->device = device;
 	fw_work->context = context;
 	fw_work->cont = cont;
@@ -1316,15 +1320,20 @@ request_firmware_nowait(
 		(uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER);
 
 	if (!try_module_get(module)) {
-		kfree_const(fw_work->name);
-		kfree(fw_work);
-		return -EFAULT;
+		rc = -EFAULT;
+		goto free_name;
 	}
 
 	get_device(fw_work->device);
 	INIT_WORK(&fw_work->work, request_firmware_work_func);
 	schedule_work(&fw_work->work);
 	return 0;
+
+free_name:
+	kfree_const(fw_work->name);
+free_work:
+	kfree(fw_work);
+	return rc;
 }
 EXPORT_SYMBOL(request_firmware_nowait);
 
-- 
2.4.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] firmware: Fix memory leak in error path
  2015-06-06  5:48 [PATCH v3] firmware: Fix memory leak in error path Firo Yang
@ 2015-06-06  5:58 ` Ming Lei
  2015-08-05 22:10 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Ming Lei @ 2015-06-06  5:58 UTC (permalink / raw)
  To: kernel-janitors

On Sat, Jun 6, 2015 at 1:48 PM, Firo Yang <firogm@gmail.com> wrote:
> Eliminate a memory leak by unifying the error handling code
> at the end of the function.
>
> Signed-off-by: Firo Yang <firogm@gmail.com>

Acked-by: Ming Lei <ming.lei@canonical.com>

> ---
>  drivers/base/firmware_class.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
> index 8c3aa3c..5bb098b 100644
> --- a/drivers/base/firmware_class.c
> +++ b/drivers/base/firmware_class.c
> @@ -1299,6 +1299,7 @@ request_firmware_nowait(
>         const char *name, struct device *device, gfp_t gfp, void *context,
>         void (*cont)(const struct firmware *fw, void *context))
>  {
> +       int rc;
>         struct firmware_work *fw_work;
>
>         fw_work = kzalloc(sizeof(struct firmware_work), gfp);
> @@ -1307,8 +1308,11 @@ request_firmware_nowait(
>
>         fw_work->module = module;
>         fw_work->name = kstrdup_const(name, gfp);
> -       if (!fw_work->name)
> -               return -ENOMEM;
> +       if (!fw_work->name) {
> +               rc = -ENOMEM;
> +               goto free_work;
> +       }
> +
>         fw_work->device = device;
>         fw_work->context = context;
>         fw_work->cont = cont;
> @@ -1316,15 +1320,20 @@ request_firmware_nowait(
>                 (uevent ? FW_OPT_UEVENT : FW_OPT_USERHELPER);
>
>         if (!try_module_get(module)) {
> -               kfree_const(fw_work->name);
> -               kfree(fw_work);
> -               return -EFAULT;
> +               rc = -EFAULT;
> +               goto free_name;
>         }
>
>         get_device(fw_work->device);
>         INIT_WORK(&fw_work->work, request_firmware_work_func);
>         schedule_work(&fw_work->work);
>         return 0;
> +
> +free_name:
> +       kfree_const(fw_work->name);
> +free_work:
> +       kfree(fw_work);
> +       return rc;
>  }
>  EXPORT_SYMBOL(request_firmware_nowait);
>
> --
> 2.4.2
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] firmware: Fix memory leak in error path
  2015-06-06  5:48 [PATCH v3] firmware: Fix memory leak in error path Firo Yang
  2015-06-06  5:58 ` Ming Lei
@ 2015-08-05 22:10 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2015-08-05 22:10 UTC (permalink / raw)
  To: kernel-janitors

On Sat, Jun 06, 2015 at 01:48:15PM +0800, Firo Yang wrote:
> Eliminate a memory leak by unifying the error handling code
> at the end of the function.
> 
> Signed-off-by: Firo Yang <firogm@gmail.com>
> Acked-by: Ming Lei <ming.lei@canonical.com>
> ---
>  drivers/base/firmware_class.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)

Doesn't apply :(

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-08-05 22:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-06  5:48 [PATCH v3] firmware: Fix memory leak in error path Firo Yang
2015-06-06  5:58 ` Ming Lei
2015-08-05 22:10 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.