[PATCH v2 02/21] of: extra: Introduce ofnode_phy_is_fixed_link() API

Vladimir Oltean
2021-03-13T13:03:16Z

On Fri, Mar 12, 2021 at 09:35:43PM +0800, Bin Meng wrote:
> +bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node)
> +{
> + bool found = false;
> + ofnode node, subnode;
> + int len;
> +
> + /* new binding */
> + subnode = ofnode_find_subnode(eth_node, "fixed-link");
> + if (ofnode_valid(subnode)) {
> + node = subnode;
> + found = true;
> + }
> +
> + /* old binding */
> + if (ofnode_get_property(eth_node, "fixed-link", &len) &&

Maybe "else if" here? If an old-style and a new-style binding exist, we
should prefer looking at the new one.

And with that "else if", we could remove the "found" variable:

if (ofnode_valid(subnode)) {
} else if (ofnode_get_property(eth_node, "fixed-link", &len) &&
len == (5 * sizeof(__be32))) {
} else {
return false;
}

if (phy_node)
*phy_node = node;

> + len == (5 * sizeof(__be32))) {
> + node = eth_node;
> + found = true;
> + }
> +
> + if (found && phy_node)
> + *phy_node = node;
> +
> + return found;
> +}