Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp647730lqb; Wed, 29 May 2024 06:52:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUScmtnGPpE2/AdDjzI3jLmfZRk0U3oiQQ/Jewul8P4Hrc5IasK2kvpT8gpuiJlLK+hnUUuXXcIXr9LcGx58uzIYC7KYT/9Nmc2s7v1ow== X-Google-Smtp-Source: AGHT+IFZPAf4hun8OplpmC6rYBcz8Pd5DookEoR3sQ9kDYd4jZwd0aq9M4YXj6D6/0AtlzMNwajz X-Received: by 2002:a05:6808:1a09:b0:3d1:d115:2ee9 with SMTP id 5614622812f47-3d1d1152f4fmr5059506b6e.32.1716990749559; Wed, 29 May 2024 06:52:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716990749; cv=pass; d=google.com; s=arc-20160816; b=zwgLtQIdytSCfOZt0TC+E62RZmGka1ZMW/oj0PCecq0wP3MOUKG1hAAg1Dh6VVgZdj YrPL3EpsruBVUYVvJGq2A9x5+sX5L8OBBmh1aQ/eNYtWwqez7BYe+Jlpf6BLGhoMGnw3 ihab7erohBWV9oc4SaxMLb8hiAayTuuhWCSlUvmAvELaME1qp7Pj7r/ZixEmYAOh3d63 jxh119GBvYJJ7ygXB2xCn/vZZciXOOmJIzHY2x7Njq42Nex83Z6T7Hz66eG2VRi000IT y4+0tOPwKtO4epMMCQOQnOr3LvBeXZ95zB9542r33BUHKZ9Yca3LJ0GMYrz5AMeTaT2v vfnA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hrcnewjRfrdjPBIlGdIQ5hPGLNnnD3B7STKmaEg7grI=; fh=MkM5P4aVjschH4zTo1MliAVRmPYovuP98XSr1orfOv8=; b=H1SgKTV3y4759WeMAwRiNvbwRxzNlqVzJ7Z+tDDNDDtiJGQ5o9o+BfVPV9Vzr8JIks ZKi323kSFhLVwpBaiG8ZrpTbJ2G+A3lR8sI4Ftd9JFeVLxoerwRV/tz71/eSuPglKeCJ lSuw/VH8TnFIyvO1sEKWycNYEhf6pyScFzR077A4O5Y1gcV3bjg+wk4KVDMYfnLX/Ucg MAcPgd6mx+dvky081W1ooVljMmWuxFfZYrcE+/EaKOsEbIQDrSvW162dsSjn7CZa+MFV Lx4nC25WlUIieqDjEPAv0pfpS8Fx2mF+mYHKB5MQhxn94H63qNHKXU0qeW0vs5OuYRNw 2BGg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZyeIVmHW; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-194208-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194208-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac1625f172si127810976d6.376.2024.05.29.06.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:52:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-194208-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=ZyeIVmHW; arc=pass (i=1 spf=pass spfdomain=ideasonboard.com dkim=pass dkdomain=ideasonboard.com); spf=pass (google.com: domain of linux-kernel+bounces-194208-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-194208-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A204A1C24461 for ; Wed, 29 May 2024 13:52:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 79FDB1BC3F; Wed, 29 May 2024 13:52:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ZyeIVmHW" Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40C6E18EA8 for ; Wed, 29 May 2024 13:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990740; cv=none; b=sDsLeE/G9iGsQR41D4fD/2ExePEPHpdUsfNozSvKkqMUoKrWDCqaAkQze9L9SDmL15uIxXH+HPD8arUYd4aQxPFFGxDIzI8FkU9AzP2t7PgrxoSLY5Z6tgFFcnHBodUg3HNimS4vvvL2fkinqEVeDXLY8PzxbeL6/UkMuXgweHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716990740; c=relaxed/simple; bh=scmYIIWiBUtvQ1/aYgr+xepSrRZem2K/QRx8v/oipBg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bFR4liR02oZhoYtyjwMMnzVKedU+KhE3p0SZUls++DY6StB1jcx5vPQ6gPmARz9wdRlUp/vowJqdnWKf73N4QnuGpGeAXMZJOF5TI0KosUEpovgpMECAc6RnLsffVtAkfwUfLJxhCSr5cSjOma5z/CrdvnfQSMA+lHbSpLh7l6k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ZyeIVmHW; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Received: from pendragon.ideasonboard.com (81-175-209-231.bb.dnainternet.fi [81.175.209.231]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id BFDDDB53; Wed, 29 May 2024 15:52:13 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1716990734; bh=scmYIIWiBUtvQ1/aYgr+xepSrRZem2K/QRx8v/oipBg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ZyeIVmHW8cSGunAdNU9/7blJ1ax6ZQ72xxzu4qjvu5VNVSKL0uFGxNSKF5QKo7U1H 7IBrqODJ/X55S+azimJKWoBY3/gPLzIiTTdaRnsSWfapQ4OBfgxb200/zi9m7FhhIb b6LsWkydmckd8ik6kv0IKMYxH0pZ5z8POjYZT48I= Date: Wed, 29 May 2024 16:52:05 +0300 From: Laurent Pinchart To: James Clark Cc: coresight@lists.linaro.org, suzuki.poulose@arm.com, Mike Leach , Alexander Shishkin , Mathieu Poirier , Greg Kroah-Hartman , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] coresight: Fix ref leak when of_coresight_parse_endpoint() fails Message-ID: <20240529135205.GP1436@pendragon.ideasonboard.com> References: <20240529133626.90080-1-james.clark@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20240529133626.90080-1-james.clark@arm.com> Hi James, Thank you for the patch. On Wed, May 29, 2024 at 02:36:26PM +0100, James Clark wrote: > of_graph_get_next_endpoint() releases the reference to the previous > endpoint on each iteration, but when parsing fails the loop exits > early meaning the last reference is never dropped. > > Fix it by dropping the refcount in the exit condition. You can add Reported-by: Laurent Pinchart > Fixes: d375b356e687 ("coresight: Fix support for sparsely populated ports") > Signed-off-by: James Clark Reviewed-by: Laurent Pinchart One a side note, maybe it would be nice to add a new version of the for_each_endpoint_of_node() macro that would declare the iterator as a local variable scoped to the loop, making sure the reference always gets released when we exit the loop. And now that I've written that, it sounds we could as well have a version of the macro that doesn't take a new reference to the iterator. That may be simpler and less error-prone in the end. > --- > drivers/hwtracing/coresight/coresight-platform.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwtracing/coresight/coresight-platform.c > index 9d550f5697fa..57a009552cc5 100644 > --- a/drivers/hwtracing/coresight/coresight-platform.c > +++ b/drivers/hwtracing/coresight/coresight-platform.c > @@ -297,8 +297,10 @@ static int of_get_coresight_platform_data(struct device *dev, > continue; > > ret = of_coresight_parse_endpoint(dev, ep, pdata); > - if (ret) > + if (ret) { > + of_node_put(ep); > return ret; > + } > } > > return 0; -- Regards, Laurent Pinchart