Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4620345imm; Tue, 7 Aug 2018 04:46:48 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcCUd1k5bE9olxqZ/UGe+Hd276iZXHjJNEr6swt0Z3Pwebh3+WlPOcaZdDXlXDxXyuiwVXN X-Received: by 2002:a62:5f82:: with SMTP id t124-v6mr21618189pfb.223.1533642408264; Tue, 07 Aug 2018 04:46:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533642408; cv=none; d=google.com; s=arc-20160816; b=d+l1e3C4c268s+ZqLWEM8uYIIp95V4/FqpUur/Y0EmzE03dZSAbOTjzkthqLhYy30u 80CZabzt9+2WfTpBeqqSEScG3AiWpu6Nds40q5EppLI+Z4zYvn6kyZO1uBji4kLMUUkA vENYWm02r/YGKqzmWDJHDw2okaWZAnI/L5XuzQ6zyUSQohMFMZ7pL3M3yIoJGRx3Jl6g ivXdavwOKRQRwvm796anGbHTta6X8bcvwSY39z9zeTujksqnAEK2+NH8pgcM+PMVcdVr TZg5iRRUMIB0wCx39Tb3xyfxpFaMUVmdrSXw2GJBR1Iy6W8jb7QGKIqmG5UPTnS7aCtU yOMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=NvZctoqF/bpNJlelSfthDxck9bhkmYtPbTxIoCDY5/c=; b=Ibs3UYaRVcYdlyz1w9EjTiIqMyw8WqXFf2Jz85vUbcFdtsrcustNOh+DKsktvpJ8IJ LxlaPOiqc1LGyz/Z8fD1a6iN72un//7+IY4CMQg5RR2d8fK/zoAMs0kQTv5eUsvu9m/9 zmOQPcv60smZJXrFsxxbX9m/vMv2LMioEiu0FJBIRUf9+GfNIuSERhNFvoS4f5EIFHk0 mRY3xwM0VZhoUtE1XlNWUIVVtZxGneE6uj2QT5Ygg+LSCuluJnBgQ25G9/v1T834Ks7y nmMJkQ40ViCxMhZGMdQgirVcnfntDE4uPxxajmMSR08GAXGfigdt1PSDxm01gAPB0BD6 KsWg== ARC-Authentication-Results: i=1; mx.google.com; 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 7-v6si1257086pgf.687.2018.08.07.04.46.33; Tue, 07 Aug 2018 04:46:48 -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; 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 S2389126AbeHGN7B (ORCPT + 99 others); Tue, 7 Aug 2018 09:59:01 -0400 Received: from bran.ispras.ru ([83.149.199.196]:28308 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726902AbeHGN7B (ORCPT ); Tue, 7 Aug 2018 09:59:01 -0400 Received: from myklebust.intra.ispras.ru (unknown [10.10.2.207]) by smtp.ispras.ru (Postfix) with ESMTP id 9558E203C9; Tue, 7 Aug 2018 14:45:01 +0300 (MSK) From: Anton Vasilyev To: Felipe Balbi Cc: Anton Vasilyev , Greg Kroah-Hartman , Li Yang , Robert Jarzmik , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, ldv-project@linuxtesting.org Subject: [PATCH] usb: gadget: fotg210-udc: Fix memory leak of fotg210->ep[i] Date: Tue, 7 Aug 2018 14:44:48 +0300 Message-Id: <20180807114448.28065-1-vasilyev@ispras.ru> X-Mailer: git-send-email 2.18.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/usb/gadget/udc/fotg210-udc.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index 53a48f561458..587c5037ff07 100644 --- 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 fotg210_gadget_ops = { 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 platform_device *pdev) /* 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 platform_device *pdev) 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 platform_device *pdev) 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 @@ static int fotg210_udc_probe(struct platform_device *pdev) 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; } -- 2.18.0