From patchwork Sat Sep 4 15:34:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Faber X-Patchwork-Id: 507203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 38841C433EF for ; Sat, 4 Sep 2021 15:41:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09D2D60F90 for ; Sat, 4 Sep 2021 15:41:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232532AbhIDPmN (ORCPT ); Sat, 4 Sep 2021 11:42:13 -0400 Received: from informare.org ([217.11.52.70]:40644 "EHLO informare.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230312AbhIDPmN (ORCPT ); Sat, 4 Sep 2021 11:42:13 -0400 Received: (qmail 13932 invoked from network); 4 Sep 2021 15:34:29 -0000 Received: from unknown (HELO ?192.168.2.105?) (faber@faberman.de@87.133.154.214) by 0 with ESMTPA; 4 Sep 2021 15:34:29 -0000 To: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org From: Florian Faber Subject: [PATCH] usb: core: Fix possible memleak in usb_add_gadget Message-ID: <311d64c6-f0e2-da42-5619-1efe46df0007@faberman.de> Date: Sat, 4 Sep 2021 17:34:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The memory for the udc structure allocated via kzalloc in line 1295 is not freed in the error handling code, leading to a memory leak in case of an error. Singed-off-by: Florian Faber --- drivers/usb/gadget/udc/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index 14fdf918ecfe..a1270a44855a 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -1346,6 +1346,8 @@ int usb_add_gadget(struct usb_gadget *gadget) err_put_udc: put_device(&udc->dev); + kfree(udc); + gadget->udc = NULL; error: return ret;