From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 280D8C25B75 for ; Wed, 29 May 2024 13:52:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HZ/RNT9M71WHZVtUG6q2y3fHvJq3UfDQ9A6wtKf/aBA=; b=laKjdqmWzXefY9 2pvxReZPqtQ/rWlRb+OOMNR7HgeYrwTnAgwmhHOcGrUm/5CZkTZF2hhVIPHlYyrFjMxQmKii9tHGV p9XsLObwpXiTIPQftgUgaYYi/NhiRap4SgXobyczFfevUnMJzhCfhpqw4GjilryfmF6IidC5pCYdo /BQhsdDV4REyo+2nFEg6aSgJOCCBqPv0rUGo2Z4lDBJAun1L3GBEjBU8DOpIEbQUYr3eBbL1AabGM pdqCWBscd1/0xRc0lFmBVbcFa/Y/nbZNZrd2Pq/VXbM5JWiK73N3FyeS1+NG0wyEH4tsVCPcGGS7M 3pYZT6el3qOH/H1p8tmA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCJj5-00000004MQx-37XM; Wed, 29 May 2024 13:52:23 +0000 Received: from perceval.ideasonboard.com ([213.167.242.64]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sCJj2-00000004MQ2-43Od for linux-arm-kernel@lists.infradead.org; Wed, 29 May 2024 13:52:22 +0000 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> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20240529133626.90080-1-james.clark@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240529_065221_171111_1CC59C0E X-CRM114-Status: GOOD ( 22.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel