Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756666AbcDLKLi (ORCPT ); Tue, 12 Apr 2016 06:11:38 -0400 Received: from mga14.intel.com ([192.55.52.115]:18232 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752008AbcDLKLg (ORCPT ); Tue, 12 Apr 2016 06:11:36 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,473,1455004800"; d="asc'?scan'208";a="943377867" From: Felipe Balbi To: changbin.du@intel.com Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Du\, Changbin" Subject: Re: [PATCH v3] usb: dwc3: fix memory leak of dwc->regset In-Reply-To: <1460449474-26540-1-git-send-email-changbin.du@intel.com> References: <87k2k3kzbe.fsf@intel.com> <1460449474-26540-1-git-send-email-changbin.du@intel.com> User-Agent: Notmuch/0.21+96~g9bbc54b (http://notmuchmail.org) Emacs/25.0.90.3 (x86_64-pc-linux-gnu) Date: Tue, 12 Apr 2016 13:09:36 +0300 Message-ID: <87h9f7kujj.fsf@intel.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3301 Lines: 118 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi, changbin.du@intel.com writes: > From: "Du, Changbin" > > dwc->regset is allocated on dwc3_debugfs_init, and should > be released on init failure or dwc3_debugfs_exit. Btw, > The line "dwc->root =3D NULL" is unnecessary, so remove it. > > Signed-off-by: Du, Changbin > --- I've modifed the patch a little bit just to make sure the error labels are easy to follow: commit c7232c5fdcc5e1b6fc39b498b58573553ebb43da Author: Du, Changbin Date: Tue Apr 12 16:24:34 2016 +0800 usb: dwc3: fix memory leak of dwc->regset =20=20=20=20 dwc->regset is allocated on dwc3_debugfs_init, and should be released on init failure or dwc3_debugfs_exit. Btw, The line "dwc->root =3D NULL" is unnecessary, so remove it. =20=20=20=20 Signed-off-by: Du, Changbin =20=20=20=20 [ felipe.balbi@linux.intel.com : add another err label for the new error condition ] =20=20=20=20 Signed-off-by: Felipe Balbi diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index 9ac37fe1b6a7..cebf9e38b60a 100644 =2D-- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -645,7 +645,7 @@ int dwc3_debugfs_init(struct dwc3 *dwc) file =3D debugfs_create_regset32("regdump", S_IRUGO, root, dwc->regset); if (!file) { ret =3D -ENOMEM; =2D goto err1; + goto err2; } =20 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 =3D -ENOMEM; =2D goto err1; + goto err2; } } =20 @@ -663,19 +663,22 @@ int dwc3_debugfs_init(struct dwc3 *dwc) dwc, &dwc3_testmode_fops); if (!file) { ret =3D -ENOMEM; =2D goto err1; + goto err2; } =20 file =3D debugfs_create_file("link_state", S_IRUGO | S_IWUSR, root, dwc, &dwc3_link_state_fops); if (!file) { ret =3D -ENOMEM; =2D goto err1; + goto err2; } } =20 return 0; =20 +err2: + kfree(dwc->regset); + err1: debugfs_remove_recursive(root); =20 @@ -686,5 +689,5 @@ err0: void dwc3_debugfs_exit(struct dwc3 *dwc) { debugfs_remove_recursive(dwc->root); =2D dwc->root =3D NULL; + kfree(dwc->regset); } patch is longer but functionally equivalent. =2D-=20 balbi --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXDMlgAAoJEIaOsuA1yqREpDMP/ApcL3qNrG8XbdXKjGEI4T+/ S2GaQTgaiYXGjlz/ow4/ohYlbE39RWkxxpeRuaddIaP7rL2b+MrjYrgfqYIUMfqb WeSDz6WbSkjhZeACnNKreC0JhFW89GnIi7DTuvNQTwaY89ETfLVqxufQc2nfueE4 Ii6qg8Is+TPLKPf/u15P18+tM57hq/KoxG0VUWPZooGXdEmcPS+SxECQseejrEdx 6MzX9L2XeMMeXFD+iTCNOhIODj4y3cn+ybvaO5LvS67sLkuZJNy/6ljAdD+LMQGc YSu3vBZj4lWuX6DJpXEiarfBJwA935dhGBb/SizeEWfK8LwDjGGBEaL/hrWrgUGZ UwUj+hv30NVYNn/KO/K+hRrw+zvtIn0xh4h1obPrDUeTAaPUTaKCGzX698efnUCl QdxE1VDWZ0tbM+US5KJdotv8GAVN5B1MlgYAUQyvMkMgKvY2+bgGgYCNXFXIq5xi +tdL2mvXESMXMrZ1m1P3agtm9ElJaaxDKNojoI9MwflQz3079TU0Q/DeGMVaQe7d /xX4bXIxTYGR2yOtEDqRIy9Xa6pGsspp0YjTVhsKF1FC3knBJ/WiFXI/bposKmE/ ItztpLoRzusqHNgsGCKaUc72DaFr/3PHyw01WlUhRojIt2WvKNiU0B3W4007d5rV rEkfsvEqR+/ZftmBCIlJ =rcvu -----END PGP SIGNATURE----- --=-=-=--