Some clean up with helper fucntion

Merge series from Zhang Zekun <zhangzekun11@huawei.com>:

There are some helper functions which can be used to simplify the code.
So, let's use these functions to make code more simple.
This commit is contained in:
Mark Brown 2024-09-04 20:09:26 +01:00
commit e328ab3de4
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
2 changed files with 3 additions and 20 deletions

View File

@ -361,7 +361,6 @@ static int __graph_for_each_link(struct simple_util_priv *priv,
struct device *dev = simple_priv_to_dev(priv); struct device *dev = simple_priv_to_dev(priv);
struct device_node *node = dev->of_node; struct device_node *node = dev->of_node;
struct device_node *cpu_port; struct device_node *cpu_port;
struct device_node *cpu_ep;
struct device_node *codec_ep; struct device_node *codec_ep;
struct device_node *codec_port; struct device_node *codec_port;
struct device_node *codec_port_old = NULL; struct device_node *codec_port_old = NULL;
@ -371,14 +370,9 @@ static int __graph_for_each_link(struct simple_util_priv *priv,
/* loop for all listed CPU port */ /* loop for all listed CPU port */
of_for_each_phandle(&it, rc, node, "dais", NULL, 0) { of_for_each_phandle(&it, rc, node, "dais", NULL, 0) {
cpu_port = it.node; cpu_port = it.node;
cpu_ep = NULL;
/* loop for all CPU endpoint */ /* loop for all CPU endpoint */
while (1) { for_each_child_of_node_scoped(cpu_port, cpu_ep) {
cpu_ep = of_get_next_child(cpu_port, cpu_ep);
if (!cpu_ep)
break;
/* get codec */ /* get codec */
codec_ep = of_graph_get_remote_endpoint(cpu_ep); codec_ep = of_graph_get_remote_endpoint(cpu_ep);
codec_port = ep_to_port(codec_ep); codec_port = ep_to_port(codec_ep);
@ -408,10 +402,8 @@ static int __graph_for_each_link(struct simple_util_priv *priv,
of_node_put(codec_ep); of_node_put(codec_ep);
of_node_put(codec_port); of_node_put(codec_port);
if (ret < 0) { if (ret < 0)
of_node_put(cpu_ep);
return ret; return ret;
}
codec_port_old = codec_port; codec_port_old = codec_port;
} }

View File

@ -1139,21 +1139,12 @@ static int graph_counter(struct device_node *lnk)
*/ */
if (graph_lnk_is_multi(lnk)) { if (graph_lnk_is_multi(lnk)) {
struct device_node *ports = port_to_ports(lnk); struct device_node *ports = port_to_ports(lnk);
struct device_node *port = NULL;
int cnt = 0;
/* /*
* CPU/Codec = N:M case has many endpoints. * CPU/Codec = N:M case has many endpoints.
* We can't use of_graph_get_endpoint_count() here * We can't use of_graph_get_endpoint_count() here
*/ */
while(1) { return of_get_child_count(ports) - 1;
port = of_get_next_child(ports, port);
if (!port)
break;
cnt++;
}
return cnt - 1;
} }
/* /*
* Single CPU / Codec * Single CPU / Codec