Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp211799ybh; Mon, 20 Jul 2020 14:42:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzC/+bkQwYgTv5bFS5PqG2GgWa+NNhr1UOlBSCNsCozpmzzfit77wXis3LHtvEu6itksgte X-Received: by 2002:a50:d908:: with SMTP id t8mr22559827edj.373.1595281376530; Mon, 20 Jul 2020 14:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595281376; cv=none; d=google.com; s=arc-20160816; b=Avz9vN0V0zy4srczlVGwAK3ne0SOU6Xi32R9PFMx8oBr7gqm2RF25q7l7Ki0ioei2e TcZ9lRxVEZO2TN5SaK+9PAvqblPi15mqzEVCAortPbxmQ1nzTsxW1tDYGM5VhSmE+GNC qhzhAiX1bk2MK9f7KAvLu7WvwVHEHefn3xdkhoW6LitlVqGsAMU60/Rfq4ZlCPSxNI24 bRfxwhgLiWQ3COASBEbBRb3WLLe49j1xn2uV9ybMuCQdjvQc7clQwE1w4yCEMcaTyH0/ AcVKjEn/IxzO6FO4MKsbhEUVD5OdM8bS6XdNdGZIX676cA0pCjLpcCNUdUuwRnSFFuoX FWxA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VR1lIyIgoAX7NLSrDxbYVnEwzy45lZ/n34BpMEwny4Y=; b=PiuS0MQHsbEC0b9ZR8IL+aZEREhAfAKuF5ISHHQF5edNnsGCvLDbDYgplEObmePng5 eeSQREzJ1ZDSefSnQRLys4FsfCjs2xjb/X3EcjjNV7eANw00KuxOAAxzZMNGdWp2+SZ7 pC3JsnBQi/VBrPndyQ48xABAm/JcDvv/IhSO+/idiKBnKNqDKUw6n/Jh9jQQK5n7PnLC 71gmtc0y0JaRb8J4vAtr+jVkwKvCoe5PB1XSEaiIu4OV3q9uvo058EJpbKOTGz3Lgqzr JkqeVQb58vLlhDJhg3rd/jPMZdquOGg+7kOEmgUqSbxjdVdhyA2wJ4VCXPJ8JLnyo+fb 4DIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cYp943o3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e10si8573406ejt.626.2020.07.20.14.42.33; Mon, 20 Jul 2020 14:42:56 -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=cYp943o3; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728505AbgGTVjf (ORCPT + 99 others); Mon, 20 Jul 2020 17:39:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:58280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726888AbgGTVjH (ORCPT ); Mon, 20 Jul 2020 17:39:07 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B15FB22C9D; Mon, 20 Jul 2020 21:39:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595281147; bh=/n45QYFcbxAEw47FM3WmH2IEHFCAqBv9oDcfilT76/M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cYp943o3PHvq3QWIG7TJEAGk918eH0lhe2tpgvYQP81Z6v0FgmovbUEM8hRe+7etT rFmmm8HwuY8s+eJy0ISNXorKEPvzavFFukXiXuhUf48Nq+Bl3n//ru1+YqP9Jhshso GGS+Kn6Qba5KUf7OwuyGRGuYQlLe2GmCxGLk4w8Y= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Evgeny Novikov , Felipe Balbi , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 13/19] usb: gadget: udc: gr_udc: fix memleak on error handling path in gr_ep_init() Date: Mon, 20 Jul 2020 17:38:44 -0400 Message-Id: <20200720213851.407715-13-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200720213851.407715-1-sashal@kernel.org> References: <20200720213851.407715-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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