Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932766AbcDLIZk (ORCPT ); Tue, 12 Apr 2016 04:25:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:16652 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932410AbcDLIZj (ORCPT ); Tue, 12 Apr 2016 04:25:39 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,473,1455004800"; d="scan'208";a="930579124" From: changbin.du@intel.com To: balbi@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, "Du, Changbin" Subject: [PATCH v2] usb: dwc3: fix memory leak of dwc->regset Date: Tue, 12 Apr 2016 16:14:43 +0800 Message-Id: <1460448883-25337-1-git-send-email-changbin.du@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <877fg3mjti.fsf@intel.com> References: <877fg3mjti.fsf@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 926 Lines: 39 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 = NULL" is unnecessary, so remove it. Signed-off-by: Du, Changbin --- v2: Title changed; free dwc->regset on failure path. --- drivers/usb/dwc3/debugfs.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/debugfs.c b/drivers/usb/dwc3/debugfs.c index 9ac37fe..abd8889 100644 --- a/drivers/usb/dwc3/debugfs.c +++ b/drivers/usb/dwc3/debugfs.c @@ -678,7 +678,8 @@ int dwc3_debugfs_init(struct dwc3 *dwc) err1: debugfs_remove_recursive(root); - + if (!dwc->regset) + kfree(dwc->regset); err0: return ret; } @@ -686,5 +687,5 @@ err0: void dwc3_debugfs_exit(struct dwc3 *dwc) { debugfs_remove_recursive(dwc->root); - dwc->root = NULL; + kfree(dwc->regset); } -- 2.5.0