Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4878997pjb; Mon, 27 Jul 2020 07:26:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvfd0TcfKcH/tGaj+q5vn5LrZJujvefrIA/uCxbKRodH+N+k9QdRRxO2yy6qPp04wXNySF X-Received: by 2002:a05:6402:559:: with SMTP id i25mr21232416edx.35.1595860015135; Mon, 27 Jul 2020 07:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595860015; cv=none; d=google.com; s=arc-20160816; b=B7o9ZErPlUVI/B5Nw4TH0fPW3REiMBbzQ8hmSduYWJI42eZrur3LBVLlr0FGHXYSk6 L5Tn1/TvdDvffUZBx8BAh3wgJThD5T2sNSYrn1M5cMxF131TrySUCy7dXjB/op8zln1Z 2XcAOdr4H//zOGaF/62zp6xpvLEV4lE3jBCazS8pT6WlKWd1ZmrpnKsoTr+U90MN8EVG J6B0aXmoYPe0lRcZc1vzDUQJpePmtSrori8P9CfAQWFI2M6aaw//SVsFstLS2bHrjdZE KSz6KTTLAwrriOuEb/kq4Z/xGLENm79Wn252f9Z9XHQwJ4RgUbBEX55EiIIFFK/CZdt9 qUYA== 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=bbzFHtd0xkoYQkiKtlyg7mH+L75PTDnVJSz0J99vvbo=; b=Nzcxn35Gc71sEEQVuw3bRV8n9LHt/VXY8bRg0snHp7/HgRxMNPeNnBQ7FQsGdBFW60 En1cgein9TgcbHDonpwfhJtP4M3y8C1WW7dwV4Ob43+r5zXTSVTj96XzB80RaaAXHPuw kUb8KO/n/CdMxJIHWgv0/qtzFCfvUauH7zkEgtZO1kkq2BIC7DgHU2meJwbtATXsRV6K VODEvGtqYPpFM3BjBHKstpm8vA/mEiOc8piEEzH8toNMxLSaKhIjx+n/dP2KxA6oN+9g iKO+vPXfRAEzeq9Me0rxp/77yE4qWTyrD3pqCLUN2Yc4b4/NjLyIzTaWS6LSJDN7YaJQ qchA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hunCbWGc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id si28si2550420ejb.157.2020.07.27.07.26.33; Mon, 27 Jul 2020 07:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=hunCbWGc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732369AbgG0OZI (ORCPT + 99 others); Mon, 27 Jul 2020 10:25:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:54888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728714AbgG0OZG (ORCPT ); Mon, 27 Jul 2020 10:25:06 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 395272075A; Mon, 27 Jul 2020 14:25:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859905; bh=pBCEpIsQiRekA4vnt2b8rokKyLIuLA/AXJIiJvcGErQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hunCbWGc+V/cu7OWHdHfD6mLPUOTIz8MPUqSJ2SF0lDExVVb17nC5JtFA0FqrlsGz 9VG6U9D50foq2WweTZgGVmkdEWdsv5k6uOY3hU1vOCy1H39SMD6C4PbBHqFucGmKIN nPuIk5hBVl4aF85lyZCeXCG9lupk9HYTbqG5PxTI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Evgeny Novikov , Felipe Balbi , Sasha Levin Subject: [PATCH 5.7 121/179] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Date: Mon, 27 Jul 2020 16:04:56 +0200 Message-Id: <20200727134938.545524911@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134932.659499757@linuxfoundation.org> References: <20200727134932.659499757@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Evgeny Novikov [ Upstream commit c8f8529e2c4141afa2ebb487ad48e8a6ec3e8c99 ] 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 Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- 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 aaf975c809bf9..ecf874dee9962 100644 --- a/drivers/usb/gadget/udc/gr_udc.c +++ b/drivers/usb/gadget/udc/gr_udc.c @@ -1981,9 +1981,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; } -- 2.25.1