Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965425AbeALVpu (ORCPT + 1 other); Fri, 12 Jan 2018 16:45:50 -0500 Received: from smtp09.smtpout.orange.fr ([80.12.242.131]:54407 "EHLO smtp.smtpout.orange.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965209AbeALVo5 (ORCPT ); Fri, 12 Jan 2018 16:44:57 -0500 X-ME-Helo: localhost.localdomain X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Fri, 12 Jan 2018 22:44:56 +0100 X-ME-IP: 90.107.118.99 From: Christophe JAILLET To: balbi@kernel.org, gregkh@linuxfoundation.org, bhumirks@gmail.com, leoyang.li@nxp.com Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET Subject: [PATCH 2/4] usb: gadget: fotg210-udc: Fix a memory leak Date: Fri, 12 Jan 2018 22:44:31 +0100 Message-Id: <74fd44ce7000aa0da44c1004ff08c75060a48b70.1515791144.git.christophe.jaillet@wanadoo.fr> X-Mailer: git-send-email 2.14.1 In-Reply-To: <0c3925c9ee4e56cd819347ab9ec515011b54d0ae.1515791144.git.christophe.jaillet@wanadoo.fr> References: <0c3925c9ee4e56cd819347ab9ec515011b54d0ae.1515791144.git.christophe.jaillet@wanadoo.fr> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: The memory referenced by the 'fotg210->ep[]' array, is never freed. So there is a memory leak in the error handling path of the probe function and when the driver is unloaded. Use 'devm_kzalloc()' to fix these leaks. Signed-off-by: Christophe JAILLET --- drivers/usb/gadget/udc/fotg210-udc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/udc/fotg210-udc.c b/drivers/usb/gadget/udc/fotg210-udc.c index 2fea32a153b7..a4d46b9759be 100644 --- a/drivers/usb/gadget/udc/fotg210-udc.c +++ b/drivers/usb/gadget/udc/fotg210-udc.c @@ -1101,7 +1101,8 @@ static int fotg210_udc_probe(struct platform_device *pdev) goto err_alloc; for (i = 0; i < FOTG210_MAX_NUM_EP; i++) { - fotg210->ep[i] = kzalloc(sizeof(struct fotg210_ep), GFP_KERNEL); + fotg210->ep[i] = devm_kzalloc(&pdev->dev, + sizeof(struct fotg210_ep), GFP_KERNEL); if (!fotg210->ep[i]) goto err_alloc; } -- 2.14.1