[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240529135205.GP1436@pendragon.ideasonboard.com>
Date: Wed, 29 May 2024 16:52:05 +0300
From: Laurent Pinchart <laurent.pinchart@...asonboard.com>
To: James Clark <james.clark@....com>
Cc: coresight@...ts.linaro.org, suzuki.poulose@....com,
Mike Leach <mike.leach@...aro.org>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] coresight: Fix ref leak when
of_coresight_parse_endpoint() fails
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 <laurent.pinchart+renesas@...asonboard.com>
> Fixes: d375b356e687 ("coresight: Fix support for sparsely populated ports")
> Signed-off-by: James Clark <james.clark@....com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@...asonboard.com>
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
Powered by blists - more mailing lists