From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752787AbdK3Mu0 (ORCPT ); Thu, 30 Nov 2017 07:50:26 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:40211 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751817AbdK3MuY (ORCPT ); Thu, 30 Nov 2017 07:50:24 -0500 Date: Thu, 30 Nov 2017 15:50:02 +0300 From: Dan Carpenter To: Frank Rowand , Geert Uytterhoeven Cc: Colin King , Pantelis Antoniou , Rob Herring , devicetree@vger.kernel.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] of: overlay: fix memory leak of ovcs on error exit path Message-ID: <20171130125002.wlnnev5pjih6d5bz@mwanda> References: <20171129191750.25254-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 30, 2017 at 07:14:45AM -0500, Frank Rowand wrote: > On 11/29/17 14:17, Colin King wrote: > > From: Colin Ian King > > > > Currently if the call to of_resolve_phandles fails then then ovcs > > is not kfree'd on the error exit path. Rather than try and make > > the clean up exit path more convoluted, fix this by just kfree'ing > > ovcs at the point of error detection and exit via the same exit > > path. > > > > Detected by CoverityScan, CID#1462296 ("Resource Leak") > > > > Fixes: f948d6d8b792 ("of: overlay: avoid race condition between applying multiple overlays") The Fixes tag is wrong. It should be: Fixes: bd80e2555c5c ("of: overlay: Fix cleanup order in of_overlay_apply()") > > Signed-off-by: Colin Ian King > > --- > > drivers/of/overlay.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c > > index 53bc9e3f0b98..6c8efe7d8cbb 100644 > > --- a/drivers/of/overlay.c > > +++ b/drivers/of/overlay.c > > @@ -708,8 +708,10 @@ int of_overlay_apply(struct device_node *tree, int *ovcs_id) > > of_overlay_mutex_lock(); > > > > ret = of_resolve_phandles(tree); > > - if (ret) > > + if (ret) { > > + kfree(ovcs); > > goto err_overlay_unlock; > > + } > > > > mutex_lock(&of_mutex); > > > > > > False coverity warning. ovcs is freed in free_overlay_changeset(). You're looking at an older version of the code and Colin is looking at linux-next. regards, dan carpenter