From patchwork Mon Nov 16 12:17:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Qilong X-Patchwork-Id: 325032 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=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 06EB8C844F7 for ; Mon, 16 Nov 2020 12:38:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B9AF220855 for ; Mon, 16 Nov 2020 12:38:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729342AbgKPMNu (ORCPT ); Mon, 16 Nov 2020 07:13:50 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:7920 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728400AbgKPMNu (ORCPT ); Mon, 16 Nov 2020 07:13:50 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4CZSdv06fzz6v6S; Mon, 16 Nov 2020 20:13:23 +0800 (CST) Received: from huawei.com (10.175.127.227) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.487.0; Mon, 16 Nov 2020 20:13:31 +0800 From: Zhang Qilong To: , CC: Subject: [PATCH 2/2] usb: gadget: Fix memleak in gadgetfs_fill_super Date: Mon, 16 Nov 2020 20:17:10 +0800 Message-ID: <20201116121710.1546690-3-zhangqilong3@huawei.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20201116121710.1546690-1-zhangqilong3@huawei.com> References: <20201116121710.1546690-1-zhangqilong3@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.127.227] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Signed-off-by: Zhang Qilong --- drivers/usb/gadget/legacy/inode.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index 1b430b36d0a6..3cefc27be098 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -2039,6 +2039,9 @@ gadgetfs_fill_super (struct super_block *sb, struct fs_context *fc) return 0; Enomem: + free(CHIP); + CHIP = NULL; + return -ENOMEM; }