Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp563367ybt; Fri, 26 Jun 2020 06:19:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwrqrrDul1lzDVq4dQ29NVj6wYRomP8YYmO5bJCYCipPY8uP0MQvUyRejXTijT8p2MY7EI3 X-Received: by 2002:a50:9f8c:: with SMTP id c12mr302193edf.149.1593177590525; Fri, 26 Jun 2020 06:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593177590; cv=none; d=google.com; s=arc-20160816; b=FhMdbmvVfiolHEpvB61SSlPzlDN/u115b/6jQvP2ZhpdgODvStiDgDHIEpenycmBPX PD3YtVq5+bzBFgb5uGsxfk2PptV7gN2+5dqEVMrxOi97aIBfJG161zQvoc6MWJOEIYTx QvMOxtROaf4y/Oryarzplb19kkDxpHR/QFVc/WEnzCibw/yckJYj1OB5qLN9XKeTf53w t4knx3YitmTkw8+HVPeh0S51M1F3dSlDf6vMYHLnfgruZ2EaawSwKXwZwoEFm16uRxfy s00/1ZrIztPV0uINK6ctCha9yCVOf2lK46iWSuOiBs4MMiMxDhJwTMvSFNCi2YBVAlLz /hyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=ng5FQUPq9fg/2RMV97J8dqP34n4zcjJCnbHox6bshBI=; b=C/JcnAYint9YfTjUX04B2xZlC5ZCUuAZHi2L7rRBOisimjSvdfddNdpnKr/bnp+n1P XBTxdSgJvX+dDOOD+Vj3ConrZzzrlqUfGCJuLkrJpDGAgs9Pap/9Ttcz62HNR2qG2B59 Tf1NPnniI8GN62wrzDbNAKYVDwDzltcTwwAEd0CWd42M2cZhhBlpnilBlee37bwlG3+S kC9ob9AgrEsuxJjy9M1m1OMvUbc5iOLdxFwlphg/ltcpXLOv/hj6eQGKM/0UcWmRcYzR Qi9vICdpthSnB/ztNbDRlFY8Ptun4fXLezp12fPaK+MNFt7jxGptn9aq/W/p7xjRtXSf lLNg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h1si843610edv.246.2020.06.26.06.19.22; Fri, 26 Jun 2020 06:19:50 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=ispras.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728205AbgFZNSL (ORCPT + 99 others); Fri, 26 Jun 2020 09:18:11 -0400 Received: from winnie.ispras.ru ([83.149.199.91]:15634 "EHLO smtp.ispras.ru" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725864AbgFZNSL (ORCPT ); Fri, 26 Jun 2020 09:18:11 -0400 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 Cc: Evgeny Novikov , Greg Kroah-Hartman , Matthias Brugger , YueHaibing , Jason Yan , Jia-Ju Bai , Stephen Boyd , Chunfeng Yun , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, ldv-project@linuxtesting.org 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; } -- 2.16.4