From patchwork Fri Jun 26 13:17:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Novikov X-Patchwork-Id: 11627611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9E67813B4 for ; Fri, 26 Jun 2020 13:20:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 73E322078D for ; Fri, 26 Jun 2020 13:20:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="BTmcoa6G"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="qIxnoRqr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 73E322078D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ispras.ru Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Owner; bh=IfVItiTBpC+V54kSv2lZ0nNzGxcx6UGQ8Kw0PGWBPH8=; b=BTmcoa6GhI30sRrYNCZFhuzJ0B bcyQSLigKrb15X3iYZ/qrz+Dd6ZJrKFhShGxI26hMgnl9mepeo1BxhytIXtDjrGXfa+zXuu6BwP1b Dv6NrD4A0ETlWIknjBZuPdXovP3k51sDhH4A4OLegqujkF3geKCJdUj1UQAhg6qCYYQ3flhy3FWSy +HQ0gxTapY3BbX63zM1ledN7iXt/dY+GF5Go/PfaFn4WsTw0YxRkKFa4Oi51uwJyzSr5m+k+eUmgi dwsFsVQRpKJFN1KnXb3EA7GAvfiCga8e5GALSCo9SAOBbeWQbB6IesxB8/uRAeH2PItlWzGOvVe7d yIvSe9tg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jooFO-00084N-Lo; Fri, 26 Jun 2020 13:18:26 +0000 Received: from casper.infradead.org ([90.155.50.34]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jooFM-00083w-MV; Fri, 26 Jun 2020 13:18:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:In-Reply-To:References; bh=ng5FQUPq9fg/2RMV97J8dqP34n4zcjJCnbHox6bshBI=; b=qIxnoRqrngS1HmCoCu5mRmIcnq zIFjBq7sCW9XflCA22uR2G2FSRtwEsP17jpMBSjoRkjlBKTTJ88iQ7mZGmG112rGCD0tLRrRAEyak /t7OWJuTsMomHvvrmg0NrB+huJR0gA3o6sTrABp8zolvhF8fY0sW5/p1QsFEdv6vUCwVGiZxG3TK9 zW2KInWVeUEbv82Uo8y83LEaPNmWQWmsYSXaElBvGElz2ONNhzbWlPq5TDf9HRf1iqUuAmS7J0gkB HoXJp3jcDQZ+KX2G/7jDtyLynA53o1LYZTxysPcM61UxT/WxMHeoyZNqa9mPvnGLT126WHB+X2WxB enMHOiUQ==; Received: from winnie.ispras.ru ([83.149.199.91] helo=smtp.ispras.ru) by casper.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jooFG-000652-U3; Fri, 26 Jun 2020 13:18:22 +0000 Received: from home.intra.ispras.ru (unknown [10.10.165.12]) by smtp.ispras.ru (Postfix) with ESMTP id 6A579201D0; Fri, 26 Jun 2020 16:18:06 +0300 (MSK) From: Evgeny Novikov To: Felipe Balbi Subject: [PATCH] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Date: Fri, 26 Jun 2020 16:17:47 +0300 Message-Id: <20200626131747.18276-1-novikov@ispras.ru> X-Mailer: git-send-email 2.16.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200626_141819_850933_FE275E07 X-CRM114-Status: GOOD ( 10.29 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.4.4 on casper.infradead.org summary: Content analysis details: (-1.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ldv-project@linuxtesting.org, Jason Yan , Evgeny Novikov , Greg Kroah-Hartman , linux-usb@vger.kernel.org, YueHaibing , linux-kernel@vger.kernel.org, Stephen Boyd , Chunfeng Yun , Jia-Ju Bai , linux-mediatek@lists.infradead.org, Matthias Brugger , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org gr_ep_init() does not assign the allocated request anywhere if allocation of memory for the buffer fails. This is a memory leak fixed by the given patch. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Evgeny Novikov --- drivers/usb/gadget/udc/gr_udc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/gr_udc.c b/drivers/usb/gadget/udc/gr_udc.c index 7164ad9800f1..7419889ebe9a 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c @@ -1980,9 +1980,12 @@ static int gr_ep_init(struct gr_udc *dev, int num, int is_in, u32 maxplimit) if (num == 0) { _req = gr_alloc_request(&ep->ep, GFP_ATOMIC); + if (!_req) + return -ENOMEM; + buf = devm_kzalloc(dev->dev, PAGE_SIZE, GFP_DMA | GFP_ATOMIC); - if (!_req || !buf) { - /* possible _req freed by gr_probe via gr_remove */ + if (!buf) { + gr_free_request(&ep->ep, _req); return -ENOMEM; }