Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3938638imm; Mon, 8 Oct 2018 12:01:01 -0700 (PDT) X-Google-Smtp-Source: ACcGV63AKenkPMBKAi11hYAET0b85LT02BrET2iJtQHWECQ7M9X7Tb/EhaVpuz+aL7JOVUnAeoR7 X-Received: by 2002:a17:902:a40e:: with SMTP id p14-v6mr25200897plq.338.1539025261364; Mon, 08 Oct 2018 12:01:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539025261; cv=none; d=google.com; s=arc-20160816; b=mKdvGKUfAKpsdu+BrfagnG2s/BzI0eM/VhBsejSeYRPaLladf8T6MNojUojkqzYqU7 0HgqPCLUq6EUk9r38ywxZV6BbB5sEUQpESwBW73SDrhJgQurSkh0ddLBZfQRjzD8ONFM h+ZLMmRF7Yg58qIA01tZfc3GbzhO64M1Uy1Xxsk1qr9RuBKQN7qRZ6hWoSlxLzKy3gSM vjHHsdXs5vVy+uPEFT4IAvx00AOH9dErPfOXlxeBR3MRaolBlS4GqysmsPYKkb5K+Jbb e8sx5RQxZmCfRThr0wQ/+MEOubEqB6PDWfy2u5wctoitm9IdiH/pFZK/N7iQZfSFsdLy +Yuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0EmK1vj2nfPXJA4u5jgfkiTagpeYIj06mWsFWUmMGRs=; b=nAzBRzwt1ONu+W3EXgq0GkQcRH+LZp2VsJ444qoGVj7dB68T6NdcyVL8IgBqlDi2CB d6wRD9WXVE+xy8k81Zrl461F2LeLbGCL78+s5yUCUjgzv7ySkmrosTewJ7t+rJ8oATOT USNdgR9sOpOhxspsOk5qUDZ0FIZGhrsFTN/plACdgf763icQop7dBiYu7U0S860Y1Eo8 tUIX5+EVyxO6dxXs8i9FU3GJjDBlHMNJEMhICMhcN+vdlsXbNfxbTCF3oFGdzqSxwPbz yY3zyAcI8e5Fb0+YgpvjGNRrmdh1WdV2/LglSPND2QzuQ5RnTPA3KoTs9WkTMUxud1S0 rD5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mMdbQBwi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11-v6si18068928pgf.66.2018.10.08.12.00.46; Mon, 08 Oct 2018 12:01:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mMdbQBwi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731891AbeJICCj (ORCPT + 99 others); Mon, 8 Oct 2018 22:02:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:51948 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727374AbeJICCi (ORCPT ); Mon, 8 Oct 2018 22:02:38 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (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 4308B204FD; Mon, 8 Oct 2018 18:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024570; bh=YWHCzJEK/RllNZgjapNhYMKKEPGUEE+H0xpzlsoa/EU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mMdbQBwiWAIpU8sdbz+Hw9ylaCNZ81SUoG74vWTR/cEnF1sLB0L+KE1cRsgMeu2hz Q6MfUoz42jfU8irkDcA2hB3LibIY0Tb8v8LXSPMAZ30fAu6O4QU3PSrfP8IZtFmHai sSBqO9/jMOMxqF8mzYECWiCfhJJvl7RmuyEkk1OE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anton Vasilyev , Felipe Balbi , Sasha Levin Subject: [PATCH 4.18 083/168] usb: gadget: fotg210-udc: Fix memory leak of fotg210->ep[i] Date: Mon, 8 Oct 2018 20:31:03 +0200 Message-Id: <20181008175623.219386946@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Anton Vasilyev [ Upstream commit c37bd52836296ecc9a0fc8060b819089aebdbcde ] There is no deallocation of fotg210->ep[i] elements, allocated at fotg210_udc_probe. The patch adds deallocation of fotg210->ep array elements and simplifies error path of fotg210_udc_probe(). Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Anton Vasilyev Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/udc/fotg210-udc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -1063,12 +1063,15 @@ static const struct usb_gadget_ops fotg2 static int fotg210_udc_remove(struct platform_device *pdev) { struct fotg210_udc *fotg210 = platform_get_drvdata(pdev); + int i; usb_del_gadget_udc(&fotg210->gadget); iounmap(fotg210->reg); free_irq(platform_get_irq(pdev, 0), fotg210); fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); + for (i = 0; i < FOTG210_MAX_NUM_EP; i++) + kfree(fotg210->ep[i]); kfree(fotg210); return 0; @@ -1099,7 +1102,7 @@ static int fotg210_udc_probe(struct plat /* initialize udc */ fotg210 = kzalloc(sizeof(struct fotg210_udc), GFP_KERNEL); if (fotg210 == NULL) - goto err_alloc; + goto err; for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { _ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); @@ -1111,7 +1114,7 @@ static int fotg210_udc_probe(struct plat fotg210->reg = ioremap(res->start, resource_size(res)); if (fotg210->reg == NULL) { pr_err("ioremap error.\n"); - goto err_map; + goto err_alloc; } spin_lock_init(&fotg210->lock); @@ -1159,7 +1162,7 @@ static int fotg210_udc_probe(struct plat fotg210->ep0_req = fotg210_ep_alloc_request(&fotg210->ep[0]->ep, GFP_KERNEL); if (fotg210->ep0_req == NULL) - goto err_req; + goto err_map; fotg210_init(fotg210); @@ -1187,12 +1190,14 @@ err_req: fotg210_ep_free_request(&fotg210->ep[0]->ep, fotg210->ep0_req); err_map: - if (fotg210->reg) - iounmap(fotg210->reg); + iounmap(fotg210->reg); err_alloc: + for (i = 0; i < FOTG210_MAX_NUM_EP; i++) + kfree(fotg210->ep[i]); kfree(fotg210); +err: return ret; }