From patchwork Thu May 24 14:22:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grigor Tovmasyan X-Patchwork-Id: 10424879 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 275156053B for ; Thu, 24 May 2018 14:22:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 217AB295CE for ; Thu, 24 May 2018 14:22:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 154D9295DA; Thu, 24 May 2018 14:22:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CF63295CE for ; Thu, 24 May 2018 14:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030986AbeEXOWp (ORCPT ); Thu, 24 May 2018 10:22:45 -0400 Received: from smtprelay6.synopsys.com ([198.182.37.59]:59426 "EHLO smtprelay.synopsys.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030742AbeEXOWp (ORCPT ); Thu, 24 May 2018 10:22:45 -0400 Received: from mailhost.synopsys.com (mailhost3.synopsys.com [10.12.238.238]) by smtprelay.synopsys.com (Postfix) with ESMTP id 9D5F11E044A for ; Thu, 24 May 2018 16:22:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1527171763; bh=BIELpst+ogDkCeh7k1ENffcQYx2m2M4hQ9zHdvJewsI=; h=Date:From:Subject:To:CC:From; b=dsG2Qi6ZK5ERQaepKD/lYt3/16v4YYnu+jfFRPS0eATvVOfoLEI5KoV6x30vBJlPz R8g4sjTZsiLflH5eVgSbWFZU7oA2C+kn7j89Gkhaxogv3c8taQUgIQPOLAT7e7dF1G 68L99NxhBQNyDUPDM0UbWogRIZcEFngZ4NhBlH1j30ogGHlhcmrFHX/zcJoZ/887E5 B2PUrzeUA569O7hl1HKLfHku7yLFw2jl2taARjEAtjUiqkA30yn9zxszrY8UC7SrS7 ainIjUWI4LAB/XiOS1mms+Ag3tXJx88defTM1yzgrY8zzIELe1nhVwUliFFsQGObof Kblffw9acFHOA== Received: from US01WEHTC3.internal.synopsys.com (us01wehtc3.internal.synopsys.com [10.15.84.232]) by mailhost.synopsys.com (Postfix) with ESMTP id B405D3ACC; Thu, 24 May 2018 07:22:42 -0700 (PDT) Received: from US01WEHTC1.internal.synopsys.com (10.12.239.235) by US01WEHTC3.internal.synopsys.com (10.15.84.232) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 24 May 2018 07:22:42 -0700 Received: from tovmasya (10.13.184.19) by us01wehtc1.internal.synopsys.com (10.12.239.236) with Microsoft SMTP Server (TLS) id 14.3.361.1; Thu, 24 May 2018 07:22:41 -0700 Received: by tovmasya (sSMTP sendmail emulation); Thu, 24 May 2018 18:22:30 +0400 Date: Thu, 24 May 2018 18:22:30 +0400 Message-ID: <446e4dd2ab44f91ef1899240c9e3b6aed3cff6c5.1527171716.git.tovmasya@synopsys.com> From: Grigor Tovmasyan Subject: [PATCH] usb: gadget: dwc2: fix memory leak in gadget_init() To: Felipe Balbi , Greg Kroah-Hartman , Minas Harutyunyan , CC: John Youn , Grigor Tovmasyan , Stefan Wahren , "Marek Szyprowski" MIME-Version: 1.0 X-Originating-IP: [10.13.184.19] Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Freed allocated request for ep0 to prevent memory leak in case when dwc2_driver_probe() failed. Signed-off-by: Grigor Tovmasyan Cc: Stefan Wahren Cc: Marek Szyprowski Tested-by: Marek Szyprowski Tested-by: Stefan Wahren Acked-by: Minas Harutyunyan --- drivers/usb/dwc2/gadget.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c index f0d9ccf1d665..7ccf56da1e50 100644 --- a/drivers/usb/dwc2/gadget.c +++ b/drivers/usb/dwc2/gadget.c @@ -4739,9 +4739,11 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg) } ret = usb_add_gadget_udc(dev, &hsotg->gadget); - if (ret) + if (ret) { + dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, + hsotg->ctrl_req); return ret; - + } dwc2_hsotg_dump(hsotg); return 0; @@ -4755,6 +4757,7 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg) int dwc2_hsotg_remove(struct dwc2_hsotg *hsotg) { usb_del_gadget_udc(&hsotg->gadget); + dwc2_hsotg_ep_free_request(&hsotg->eps_out[0]->ep, hsotg->ctrl_req); return 0; }