From patchwork Tue Dec 1 08:54:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 335780 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable 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 849E0C64E7A for ; Tue, 1 Dec 2020 09:24:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1291D206CB for ; Tue, 1 Dec 2020 09:24:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bpzWUsgU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389077AbgLAJG0 (ORCPT ); Tue, 1 Dec 2020 04:06:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:43026 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389072AbgLAJGZ (ORCPT ); Tue, 1 Dec 2020 04:06:25 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AF0FE21D7F; Tue, 1 Dec 2020 09:06:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606813570; bh=flPZjbh2BeNlKedo7Gb7xPO/fGv5DVJFD3xLc1JOyR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bpzWUsgUmMULMrEF+y7lipb7HMaFVCkPYgxlfpa0cwhI9gFbzCyV0LoR/8MYqjVCe wnCmh3KzwTVKhVlETVyMyiZ9430LRE8LQ5wocvOxcvoupDnXmUYR4foNIsSktD1Wkv fuzm2TTl+WldtibE+gqCsIQC/DGUh1De5kKyBkYY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hulk Robot , Alan Stern , Zhang Qilong Subject: [PATCH 5.4 84/98] usb: gadget: Fix memleak in gadgetfs_fill_super Date: Tue, 1 Dec 2020 09:54:01 +0100 Message-Id: <20201201084659.164581499@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084652.827177826@linuxfoundation.org> References: <20201201084652.827177826@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Zhang Qilong commit 87bed3d7d26c974948a3d6e7176f304b2d41272b upstream. usb_get_gadget_udc_name will alloc memory for CHIP in "Enomem" branch. we should free it before error returns to prevent memleak. Fixes: 175f712119c57 ("usb: gadget: provide interface for legacy gadgets to get UDC name") Reported-by: Hulk Robot Acked-by: Alan Stern Signed-off-by: Zhang Qilong Link: https://lore.kernel.org/r/20201117021629.1470544-3-zhangqilong3@huawei.com Cc: stable Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/legacy/inode.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -2040,6 +2040,9 @@ gadgetfs_fill_super (struct super_block return 0; Enomem: + kfree(CHIP); + CHIP = NULL; + return -ENOMEM; }