diff mbox series

[1/7] device property: Fix fwnode_graph_devcon_match() fwnode leak

Message ID 20211130153250.935726-1-sakari.ailus@linux.intel.com
State Superseded
Headers show
Series [1/7] device property: Fix fwnode_graph_devcon_match() fwnode leak | expand

Commit Message

Sakari Ailus Nov. 30, 2021, 3:32 p.m. UTC
For each endpoint it encounters, fwnode_graph_devcon_match() checks
whether the endpoint's remote port parent device is available. If it is
not, it ignores the endpoint but does not put the reference to the remote
endpoint port parent fwnode. For available devices the fwnode handle
reference is put as expected.

Put the reference for unavailable devices now.

Fixes: 637e9e52b185 ("device connection: Find device connections also from device graphs")
Cc: stable@vger.kernel.org # for 5.1 and later
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
 drivers/base/property.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Andy Shevchenko Nov. 30, 2021, 4:01 p.m. UTC | #1
On Tue, Nov 30, 2021 at 05:32:48PM +0200, Sakari Ailus wrote:
> Add fwnode_graph_get_endpoint_count() function to provide generic
> implementation of of_graph_get_endpoint_count(). The former by default
> only counts endpoints to available devices which is consistent with the
> rest of the fwnode graph API. By providing FWNODE_GRAPH_DEVICE_DISABLED
> flag, also unconnected endpoints and endpoints to disabled devices are
> counted.

...

> +	fwnode_graph_for_each_endpoint(fwnode, ep) {
> +		if (!(flags & FWNODE_GRAPH_DEVICE_DISABLED) &&
> +		    !fwnode_graph_remote_available(ep))
> +			continue;

> +		count++;

Can't it be more straightforward to write it as

		if (flags & FWNODE_GRAPH_DEVICE_DISABLED ||
		    fwnode_graph_remote_available(ep))
			count++;

?

> +	}
Sakari Ailus Nov. 30, 2021, 8:21 p.m. UTC | #2
Hi Andy,

Thanks for the comments.

On Tue, Nov 30, 2021 at 06:07:26PM +0200, Andy Shevchenko wrote:
> On Tue, Nov 30, 2021 at 05:32:44PM +0200, Sakari Ailus wrote:
> > For each endpoint it encounters, fwnode_graph_devcon_match() checks
> > whether the endpoint's remote port parent device is available. If it is
> > not, it ignores the endpoint but does not put the reference to the remote
> > endpoint port parent fwnode. For available devices the fwnode handle
> > reference is put as expected.
> > 
> > Put the reference for unavailable devices now.
> 
> I like the series, thanks!
> For non-commented you may take my
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Thanks!

> 
> The rest can gain it if you are okay with my proposals.
> 
> Also, please fix Cc list, it has fancy address in the Cc list.

I forgot to write one more e-mail address before pressing enter...
diff mbox series

Patch

diff --git a/drivers/base/property.c b/drivers/base/property.c
index f1f35b48ab8b9..6df99e526ab0f 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1206,8 +1206,10 @@  fwnode_graph_devcon_match(struct fwnode_handle *fwnode, const char *con_id,
 
 	fwnode_graph_for_each_endpoint(fwnode, ep) {
 		node = fwnode_graph_get_remote_port_parent(ep);
-		if (!fwnode_device_is_available(node))
+		if (!fwnode_device_is_available(node)) {
+			fwnode_handle_put(node);
 			continue;
+		}
 
 		ret = match(node, con_id, data);
 		fwnode_handle_put(node);