Message ID | 20240822112649.58376-3-zhangzekun11@huawei.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Some clean up with helper fucntion | expand |
Hi Zhang Thank you for the patch > - do { > - *port = of_get_next_child(ports, *port); > - if (!*port) > + for_each_child_of_node(ports, *port) { > + if (of_node_name_eq(*port, "port")) { > + ep = port_to_endpoint(*port); > + rep = of_graph_get_remote_endpoint(ep); > break; > - } while (!of_node_name_eq(*port, "port")); > - > - if (*port) { > - ep = port_to_endpoint(*port); > - rep = of_graph_get_remote_endpoint(ep); > + } > } Original code calls (A) first, but this code calls (B) first in for_each_child_of_node(), it breaks logic (A) of_get_next_child(ports, *port); (B) of_get_next_child(ports, NULL); This function try to find next port, not for port loop. Thank you for your help !! Best regards --- Kuninori Morimoto
在 2024/8/26 9:22, Kuninori Morimoto 写道: > > Hi Zhang > > Thank you for the patch > >> - do { >> - *port = of_get_next_child(ports, *port); >> - if (!*port) >> + for_each_child_of_node(ports, *port) { >> + if (of_node_name_eq(*port, "port")) { >> + ep = port_to_endpoint(*port); >> + rep = of_graph_get_remote_endpoint(ep); >> break; >> - } while (!of_node_name_eq(*port, "port")); >> - >> - if (*port) { >> - ep = port_to_endpoint(*port); >> - rep = of_graph_get_remote_endpoint(ep); >> + } >> } > > Original code calls (A) first, but this code calls (B) first in > for_each_child_of_node(), it breaks logic > > (A) of_get_next_child(ports, *port); > (B) of_get_next_child(ports, NULL); > > This function try to find next port, not for port loop. > > Thank you for your help !! > > Best regards > --- > Kuninori Morimoto > Hi, Kuninori Thanks for your review. I have missed that logic broken, and it should not change like that. Best regrads, Zekun
diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c index 56f7f946882e..03f6eb1df84a 100644 --- a/sound/soc/generic/audio-graph-card2.c +++ b/sound/soc/generic/audio-graph-card2.c @@ -351,15 +351,12 @@ static struct device_node *graph_get_next_multi_ep(struct device_node **port) * port@1 { rep1 }; * }; */ - do { - *port = of_get_next_child(ports, *port); - if (!*port) + for_each_child_of_node(ports, *port) { + if (of_node_name_eq(*port, "port")) { + ep = port_to_endpoint(*port); + rep = of_graph_get_remote_endpoint(ep); break; - } while (!of_node_name_eq(*port, "port")); - - if (*port) { - ep = port_to_endpoint(*port); - rep = of_graph_get_remote_endpoint(ep); + } } of_node_put(ep); @@ -1141,21 +1138,8 @@ static int graph_counter(struct device_node *lnk) */ if (graph_lnk_is_multi(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. - * We can't use of_graph_get_endpoint_count() here - */ - while(1) { - port = of_get_next_child(ports, port); - if (!port) - break; - cnt++; - } - return cnt - 1; + return of_get_child_count(ports) - 1; } /* * Single CPU / Codec
for_each_child_of_node can help to iterate through the device_node, and we don't need to use while loop. Besides, use of_get_child_count() to get the num of child directly. No functional change with this conversion. Signed-off-by: Zhang Zekun <zhangzekun11@huawei.com> --- sound/soc/generic/audio-graph-card2.c | 28 ++++++--------------------- 1 file changed, 6 insertions(+), 22 deletions(-)