[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YgOz6K55Oi2Si4pU@smile.fi.intel.com>
Date: Wed, 9 Feb 2022 14:30:32 +0200
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Bjorn Andersson <bjorn.andersson@...aro.org>
Cc: Rob Herring <robh+dt@...nel.org>,
Daniel Scally <djrscally@...il.com>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
"Rafael J. Wysocki" <rafael@...nel.org>,
Hans de Goede <hdegoede@...hat.com>,
linux-usb@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
Dmitry Baryshkov <dmitry.baryshkov@...aro.org>
Subject: Re: [PATCH v2 1/6] device property: Helper to match multiple
connections
On Mon, Feb 07, 2022 at 07:19:39PM -0800, Bjorn Andersson wrote:
> In some cases multiple connections with the same connection id
> needs to be resolved from a fwnode graph.
>
> One such example is when separate hardware is used for performing muxing
> and/or orientation switching of the SuperSpeed and SBU lines in a USB-C
USB Type-C ?
> connector. In this case the connector needs to belong to a graph with
> multiple matching remote endpoints, and the TypeC controller needs to be
Type-C ?
> able to resolve them both.
>
> Add a new API that allows this kind of lookup.
>
> Given that the match() callback returns an opaque reference to something
> provided by the client it's not possible for the implementation to
> release the returned object and as such it's not possible to handle
> errors, which in turn means that it's not possible to query the number
> of elements or dynamically grow the results array. It's however expected
> that the number of matches will be reasonably low and that the worst
> case is known by the caller before hand.
...
> + fwnode_graph_for_each_endpoint(fwnode, ep) {
> + if (count >= matches_len) {
> + fwnode_handle_put(ep);
> + return count;
> + }
> +
> + node = fwnode_graph_get_remote_port_parent(ep);
> + if (!fwnode_device_is_available(node)) {
> + fwnode_handle_put(node);
> + continue;
> + }
> +
> + ret = match(node, con_id, data);
> + fwnode_handle_put(node);
> +
Redundant blank line (it seems the current style w/o this).
Ditto for the below function.
> + if (ret)
> + matches[count++] = ret;
> + }
...
> +/**
> + * fwnode_connection_find_matches - Find connections from a device node
> + * @fwnode: Device node with the connection
> + * @con_id: Identifier for the connection
> + * @data: Data for the match function
> + * @match: Function to check and convert the connection description
> + * @matches: Array of pointers to fill with matches
> + * @matches_len: Length of @matches
> + *
> + * Find up to @matches_len connections with unique identifier @con_id between
> + * @fwnode and other device nodes. @match will be used to convert the
> + * connection description to data the caller is expecting to be returned
> + * through the @matches array.
> + *
> + * Return: Number of matches resolved, of negative errno.
s/of/or/ ?
> + */
> +int fwnode_connection_find_matches(struct fwnode_handle *fwnode,
> + const char *con_id, void *data,
> + devcon_match_fn_t match,
> + void **matches, unsigned int matches_len)
> +{
> + unsigned int count;
> +
> + if (!fwnode || !match || !matches)
!matches case may be still useful to get the count and allocate memory by
caller. Please, consider this case.
> + return -EINVAL;
> +
> + count = fwnode_graph_devcon_matches(fwnode, con_id, data, match,
> + matches, matches_len);
> +
> + return count + fwnode_devcon_matches(fwnode, con_id, data, match,
> + matches + count,
> + matches_len - count);
I haven't found any explanation what the difference between two counts. Also
can you define two count variables with distinct names and do something like
count_A = ...
matches += count;
matches_len -= count;
count_B = ...
return count_A + count_B;
?
> +}
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists