Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7607740ybi; Tue, 9 Jul 2019 01:13:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqXNmTYvAkVr/m6aUq7hc6/tVXQH6OY566PwTGarkzsLmzbMa92XeCHHEAoTix4T/o7d2u X-Received: by 2002:a63:f44a:: with SMTP id p10mr29380023pgk.148.1562660037729; Tue, 09 Jul 2019 01:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562660037; cv=none; d=google.com; s=arc-20160816; b=KNI3rylxrNiFybauOFAbnYQGGt7uasv9TkLNHcJ3gzy7J/M+DV/OUvDm39ODDFwGAz /j0edKBOIdJc2V+8pSxAV+ugUf6N9I7pqNZtlVQgI2nWeKosFdIeesF5qbdxp1NRZ+1B WAoe5xXIFvYUl4a2wkUyLVz4FTco1OpCgO1IDPLmTJZf9Sv8kGRjoaDkd4LacLatvmyt wJLFRf3OFvPTOCcQQVO06/dqcYkZkxR+2UsVdd8stUEZTmEswZCuo37Md8/auyC6O4Xg x+jWGnFnpkTpD2pfjaMsPnM63mLnC/Y3+wBSetgnRRC37OjL+Q3KmaZ8PmZGDtOqdxPq opGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=hYiBKY4xgg2SD4Ukzaw2SlpNiCHzVRjRoyxP1/C4n9k=; b=ysdTZkkLE8qfBHnmF1LdtjSqy4OsIRsbbGtdb614lhMV8cVxOV/DbfxgNxEM5/mpiq 3JQSDIULPiM53c3lJqcXG6mjELumyro2FeGIMFmd//Ft8B/p1MEuuCSPK9RZW8xjJLx6 0MTmLuEgpj8giUS5gFm5F4D82u++GE3+fheJGhmIrlzJwV6jyqXdScDcL8IFJHi3tML1 R0F/G1EZofZsV/fhVTjV9cWHNnvhXlxCVRSP1OWM+jywlWAwcVWJPgGrY0KXoyJfJaEJ V1PetC9Wf4vL8SKWfUuyn8YoRgEX5ooQ+0K14l4gNHtnkDaRg6ic3W/rcBncDaIGDOVp 1mYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ba9si16255324plb.308.2019.07.09.01.13.42; Tue, 09 Jul 2019 01:13:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726282AbfGIINH (ORCPT + 99 others); Tue, 9 Jul 2019 04:13:07 -0400 Received: from atrey.karlin.mff.cuni.cz ([195.113.26.193]:36893 "EHLO atrey.karlin.mff.cuni.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725895AbfGIINH (ORCPT ); Tue, 9 Jul 2019 04:13:07 -0400 Received: by atrey.karlin.mff.cuni.cz (Postfix, from userid 512) id D81498057F; Tue, 9 Jul 2019 10:12:53 +0200 (CEST) Date: Tue, 9 Jul 2019 10:13:04 +0200 From: Pavel Machek To: pavel@ucw.cz Cc: linux-kernel@vger.kernel.org, Young Xiao <92siuyang@gmail.com>, Felipe Balbi , Sasha Levin Subject: Re: [PATCH 4.19 22/90] usb: gadget: fusb300_udc: Fix memory leak of fusb300->ep[i] Message-ID: <20190709081304.GA11574@amd> References: <20190708150521.829733162@linuxfoundation.org> <20190708150523.753501550@linuxfoundation.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="LQksG6bCIzRHxTLp" Content-Disposition: inline In-Reply-To: <20190708150523.753501550@linuxfoundation.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --LQksG6bCIzRHxTLp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi! > There is no deallocation of fusb300->ep[i] elements, allocated at > fusb300_probe. >=20 > The patch adds deallocation of fusb300->ep array elements. =2E..=20 > diff --git a/drivers/usb/gadget/udc/fusb300_udc.c b/drivers/usb/gadget/ud= c/fusb300_udc.c > index 263804d154a7..00e3f66836a9 100644 > --- a/drivers/usb/gadget/udc/fusb300_udc.c > +++ b/drivers/usb/gadget/udc/fusb300_udc.c > @@ -1342,12 +1342,15 @@ static const struct usb_gadget_ops fusb300_gadget= _ops =3D { > static int fusb300_remove(struct platform_device *pdev) > { > struct fusb300 *fusb300 =3D platform_get_drvdata(pdev); > + int i; > =20 > usb_del_gadget_udc(&fusb300->gadget); > iounmap(fusb300->reg); > free_irq(platform_get_irq(pdev, 0), fusb300); > =20 > fusb300_free_request(&fusb300->ep[0]->ep, fusb300->ep0_req); > + for (i =3D 0; i < FUSB300_MAX_NUM_EP; i++) > + kfree(fusb300->ep[i]); > kfree(fusb300); > =20 > return 0; > @@ -1491,6 +1494,8 @@ clean_up: > if (fusb300->ep0_req) > fusb300_free_request(&fusb300->ep[0]->ep, > fusb300->ep0_req); > + for (i =3D 0; i < FUSB300_MAX_NUM_EP; i++) > + kfree(fusb300->ep[i]); > kfree(fusb300); > } > if (reg) Maybe it would be worth it to have a common function doing the cleanup at this point? Alternatively consider using devm_ function family; that deallocates memory automatically. Pavel --=20 (english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blo= g.html --LQksG6bCIzRHxTLp Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAl0kTJAACgkQMOfwapXb+vIp7QCggP3RXuMOj8CtICSqJ6ZdFZkz CGQAoKm38YqmF4jSyu01AO2QaxCAvDbq =ILf2 -----END PGP SIGNATURE----- --LQksG6bCIzRHxTLp--