Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4292436pxu; Tue, 1 Dec 2020 01:01:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJxYGeifvu4Jc+O4VZqj8RwCj1dkSlAhiBhsUtLwxJwE5afMikB8RjNEfxXwUVgOweF9sfOU X-Received: by 2002:a17:907:210b:: with SMTP id qn11mr2024276ejb.41.1606813267573; Tue, 01 Dec 2020 01:01:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606813267; cv=none; d=google.com; s=arc-20160816; b=0kKKFa+qpDCukXKyej3goNVwlWaEDUvImZH401eDmuEvfkqWeTsMXE0EgRH+jV2VES ufioYgofHK4kxVKXKE6u2vn5qOSiSTmhj4bUtYIxtMkk3DEXvMYz3i0skFk/67GGEni7 eUCdvNULjamJ3EI8Fl6kmH+mmdKzYdt3m7cr02xR/sgNVB9YP/57dDZpyYyhJUbZeXSb Q/3v8fkiWwWK2XRXnVe/c92zUHwnaj8Lvv2GZV2ns3yn9b8bXv8XlTef5TYT5n2FYIWe 1kt/sBXPlLdcuz1XnApuDBSB13XpYF5x+f4dlvI7AqPPwhKW9NJojiqlb8nRoY1oFvtN zgJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=l+7pZ6GLQnIKWmSLA/+0xJFlAgwSdBK58CZwVosp57I=; b=atde8e47Y2pqEYjgyQNDiOJa07C311P0FRctPqqW7y4N+LelAlwwFO4QlOxbY77DkW zfwb8TSVaNRV2KU4paT6ms+22QvZolIO6B9qJ/T7+FCLsCQqF0Fd/lHObrGKOuJ5BtaQ hQY33pCrV2TyHP/V6qOQtJ0P7JPcCF3NisuYKT8vaVXzcjCVa7fIli50x88W4PMf6Pf7 T85uZeTh6vzQrQ1annVKj5fLuZr5UbZDkPWGf7Nx07D56Lc2d4hMiUy1X3YWPg4guXL9 JPT3ucXlxckdB1lF5iGOOEHjVGLqolYZtwmNva0Sf8szSOZ53zPIuBERdkleCvYfYbmi 6OYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jJ/uLmqg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u11si739706edr.4.2020.12.01.01.00.45; Tue, 01 Dec 2020 01:01:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="jJ/uLmqg"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387740AbgLAI47 (ORCPT + 99 others); Tue, 1 Dec 2020 03:56:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:59972 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387722AbgLAI4w (ORCPT ); Tue, 1 Dec 2020 03:56:52 -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 9FF7221D7A; Tue, 1 Dec 2020 08:56:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606812966; bh=fjdm9nEuyx3eUE4CIIz03DRjZavEIKOwneaHpAD36cs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jJ/uLmqg2Tb++Ldc5XsS4FqwniJ3ug0g8ZsXiCUbIgwHR+FwNjtU0zma69kL5dwDo fFiHNVuAQr15Y161w//LZVQhd9/9ddow+S6br/Vpj6IGLb54aGXk2TH7evC+E0lOaE 8z1LYKuDK07/QNlAhywmbSw8qrteqPPfEmAVADkg= 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 4.9 37/42] usb: gadget: Fix memleak in gadgetfs_fill_super Date: Tue, 1 Dec 2020 09:53:35 +0100 Message-Id: <20201201084645.477134828@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201201084642.194933793@linuxfoundation.org> References: <20201201084642.194933793@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 @@ -2045,6 +2045,9 @@ gadgetfs_fill_super (struct super_block return 0; Enomem: + kfree(CHIP); + CHIP = NULL; + return -ENOMEM; }