All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@kernel.org>
To: changbin.du@intel.com
Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, "Du\,
	Changbin" <changbin.du@intel.com>
Subject: Re: [PATCH v3] usb: dwc3: fix memory leak of dwc->regset
Date: Tue, 12 Apr 2016 13:09:36 +0300	[thread overview]
Message-ID: <87h9f7kujj.fsf@intel.com> (raw)
In-Reply-To: <1460449474-26540-1-git-send-email-changbin.du@intel.com>

[-- Attachment #1: Type: text/plain, Size: 2336 bytes --]


Hi,

changbin.du@intel.com writes:
> From: "Du, Changbin" <changbin.du@intel.com>
>
> dwc->regset is allocated on dwc3_debugfs_init, and should
> be released on init failure or dwc3_debugfs_exit. Btw,
> The line "dwc->root = NULL" is unnecessary, so remove it.
>
> Signed-off-by: Du, Changbin <changbin.du@intel.com>
> ---

I've modifed the patch a little bit just to make sure the error labels
are easy to follow:

commit c7232c5fdcc5e1b6fc39b498b58573553ebb43da
Author: Du, Changbin <changbin.du@intel.com>
Date:   Tue Apr 12 16:24:34 2016 +0800

    usb: dwc3: fix memory leak of dwc->regset
    
    dwc->regset is allocated on dwc3_debugfs_init, and should
    be released on init failure or dwc3_debugfs_exit. Btw,
    The line "dwc->root = NULL" is unnecessary, so remove it.
    
    Signed-off-by: Du, Changbin <changbin.du@intel.com>
    
    [ felipe.balbi@linux.intel.com : add another err label for the new
    	error condition ]
    
    Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>

diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c
index 9ac37fe1b6a7..cebf9e38b60a 100644
--- a/drivers/usb/dwc3/debugfs.c
+++ b/drivers/usb/dwc3/debugfs.c
@@ -645,7 +645,7 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 	file = debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset);
 	if (!file) {
 		ret = -ENOMEM;
-		goto err1;
+		goto err2;
 	}
 
 	if (IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)) {
@@ -653,7 +653,7 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 				dwc, &dwc3_mode_fops);
 		if (!file) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 	}
 
@@ -663,19 +663,22 @@ int dwc3_debugfs_init(struct dwc3 *dwc)
 				dwc, &dwc3_testmode_fops);
 		if (!file) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 
 		file = debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root,
 				dwc, &dwc3_link_state_fops);
 		if (!file) {
 			ret = -ENOMEM;
-			goto err1;
+			goto err2;
 		}
 	}
 
 	return 0;
 
+err2:
+	kfree(dwc->regset);
+
 err1:
 	debugfs_remove_recursive(root);
 
@@ -686,5 +689,5 @@ err0:
 void dwc3_debugfs_exit(struct dwc3 *dwc)
 {
 	debugfs_remove_recursive(dwc->root);
-	dwc->root = NULL;
+	kfree(dwc->regset);
 }

patch is longer but functionally equivalent.

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

      reply	other threads:[~2016-04-12 10:11 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-08  9:42 [PATCH] usb: dwc3: free dwc->regset on dwc3_debugfs_exit changbin.du
2016-04-11  8:06 ` Felipe Balbi
2016-04-11 11:09   ` Du, Changbin
2016-04-11 11:13     ` Felipe Balbi
2016-04-11 11:38       ` Du, Changbin
2016-04-11 12:09         ` Felipe Balbi
2016-04-12  2:10           ` Du, Changbin
2016-04-12  6:18             ` Felipe Balbi
2016-04-12  6:52               ` Du, Changbin
2016-04-12  8:06                 ` Felipe Balbi
2016-04-12  8:14               ` [PATCH v2] usb: dwc3: fix memory leak of dwc->regset changbin.du
2016-04-12  8:26                 ` Felipe Balbi
2016-04-12  8:24                   ` [PATCH v3] " changbin.du
2016-04-12 10:09                     ` Felipe Balbi [this message]

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=87h9f7kujj.fsf@intel.com \
    --to=balbi@kernel.org \
    --cc=changbin.du@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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 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.