Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4868137pjb; Mon, 27 Jul 2020 07:12:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQvHkjAFjeBRF6FGRTk/n+zHHy3HCLLlio9UGGH6c5guKh9fyEf5Ht6yKDnPpqws8LMiTK X-Received: by 2002:a17:906:3b01:: with SMTP id g1mr22112720ejf.353.1595859177853; Mon, 27 Jul 2020 07:12:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595859177; cv=none; d=google.com; s=arc-20160816; b=iBNK/CGqYRAqYl9pQLWd5cNj6Bc20k85QSQlVyfddxW74BD29uFSbaJJxjb6jrbcCj 4npOwqf95hbTClHmyn7rAyJ/ioFVkEIIj/jq6Ix4ekaZk9CosOAVhmAO0R7HdXGJMWJr oyBWSQfkrNwwX9wec+qQtZVjfhPJ7ZVptpneKbzQjIz2Hdla3RNvVg9uJt0E5WNp8Wvh eHVeVAL/9X37A7YVdB+ZnWmMuBcX7XD6BbBgyBB4SKcxLaZRQmrfkEX7XeMV1nWkzDsT s5dci4xSsfvtkbBbbAm1IbC6e7QdUaWT9GG4mUpmL+OlZQcBzfJWdVY5un4dvM7W99N1 PtxA== 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=VR1lIyIgoAX7NLSrDxbYVnEwzy45lZ/n34BpMEwny4Y=; b=K5ACS1gtPiMdnenG9KWIa81hzJwrNp0QAGlKymXb755JLRo/mo0/p1WwJkT3P3y8Rs f9e3dD8KTMmhNxZkBjM/0TBmgAoFfw+B0nLRZPKxF4mSmXp0hUtuNIEbU3yjQs/gFmTK THbuenIemyuhaiFsiqlNA/5g0FjHnk8LkYhW04xyRy/hXnPwql8xPowzeUZUVrx/w19l 2CTgh0p3KUNoww7cl5AztXM+5fAmunxGuiRJ8UEu7B7+DO5caV7SFmmv80l+Kg04lTzL GYI00Mfv/QE7Cv1CYpHPLjEF6YPQkZAWhxqogyzMNcYW/PHrQP0OdTQpBXf2zzoXJyFy musA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lLPa6eMv; 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 mj22si2814280ejb.738.2020.07.27.07.12.35; Mon, 27 Jul 2020 07:12:57 -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=lLPa6eMv; 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 S1729987AbgG0OLM (ORCPT + 99 others); Mon, 27 Jul 2020 10:11:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:34624 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729299AbgG0OLL (ORCPT ); Mon, 27 Jul 2020 10:11:11 -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 6D88C2173E; Mon, 27 Jul 2020 14:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595859071; bh=/n45QYFcbxAEw47FM3WmH2IEHFCAqBv9oDcfilT76/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lLPa6eMvEHOe6SDHO9VlLcYzPq6z2tVadmbOhnkieoEyV9yYbmnsXlUZ/uCLg1Pq5 OJgzBPByXlc19bLjQMnilO9BPPYpjVJ/BeRMvql0pJu7Kf1yEMbfsxitSr7NKo5OQ4 Zc4Oty02nPvCU1M7GpU3ebFVIq1BSQ64lFhpitn8= 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 4.19 55/86] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Date: Mon, 27 Jul 2020 16:04:29 +0200 Message-Id: <20200727134917.173467637@linuxfoundation.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200727134914.312934924@linuxfoundation.org> References: <20200727134914.312934924@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 e50108f9a374e..e0b2fb33ed0d8 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; } -- 2.25.1