[PATCH] ASoC: rsnd: Refactor port handling with helper for endpoint node selection

Prabhakar posted 1 patch 1 month, 2 weeks ago
sound/soc/sh/rcar/core.c | 30 +++++++++++++++++++++---------
1 file changed, 21 insertions(+), 9 deletions(-)
[PATCH] ASoC: rsnd: Refactor port handling with helper for endpoint node selection
Posted by Prabhakar 1 month, 2 weeks ago
From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Refactor the code responsible for selecting the correct device node for
audio endpoint parsing in the rsnd driver. A new helper function
`rsnd_pick_endpoint_node_for_ports()` is introduced to handle the
selection of the endpoint node by checking whether the port is named
'port' or 'ports'.

This change simplifies the logic in both `rsnd_dai_of_node()` and
`rsnd_dai_probe()` functions by replacing repetitive condition checks
with the new helper.

Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
Note, this patch applies on top of [0]
[0] https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
---
 sound/soc/sh/rcar/core.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/sound/soc/sh/rcar/core.c b/sound/soc/sh/rcar/core.c
index eca5ce096e54..c32e88d6a141 100644
--- a/sound/soc/sh/rcar/core.c
+++ b/sound/soc/sh/rcar/core.c
@@ -1233,6 +1233,19 @@ int rsnd_node_count(struct rsnd_priv *priv, struct device_node *node, char *name
 	return i;
 }
 
+static struct device_node*
+	rsnd_pick_endpoint_node_for_ports(struct device_node *e_ports,
+					  struct device_node *e_port)
+{
+	if (of_node_name_eq(e_ports, "ports"))
+		return e_ports;
+
+	if (of_node_name_eq(e_ports, "port"))
+		return e_port;
+
+	return NULL;
+}
+
 static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
 {
 	struct device *dev = rsnd_priv_to_dev(priv);
@@ -1278,12 +1291,10 @@ static int rsnd_dai_of_node(struct rsnd_priv *priv, int *is_graph)
 	 * Audio-Graph-Card
 	 */
 	for_each_child_of_node(np, ports) {
-		if (!of_node_name_eq(ports, "ports") &&
-		    !of_node_name_eq(ports, "port"))
+		node = rsnd_pick_endpoint_node_for_ports(ports, np);
+		if (!node)
 			continue;
-		priv->component_dais[i] =
-			of_graph_get_endpoint_count(of_node_name_eq(ports, "ports") ?
-						    ports : np);
+		priv->component_dais[i] = of_graph_get_endpoint_count(node);
 		nr += priv->component_dais[i];
 		i++;
 		if (i >= RSND_MAX_COMPONENT) {
@@ -1488,15 +1499,16 @@ static int rsnd_dai_probe(struct rsnd_priv *priv)
 	 */
 	dai_i = 0;
 	if (is_graph) {
+		struct device_node *dai_np_port;
 		struct device_node *ports;
 		struct device_node *dai_np;
 
 		for_each_child_of_node(np, ports) {
-			if (!of_node_name_eq(ports, "ports") &&
-			    !of_node_name_eq(ports, "port"))
+			dai_np_port = rsnd_pick_endpoint_node_for_ports(ports, np);
+			if (!dai_np_port)
 				continue;
-			for_each_endpoint_of_node(of_node_name_eq(ports, "ports") ?
-						  ports : np, dai_np) {
+
+			for_each_endpoint_of_node(dai_np_port, dai_np) {
 				__rsnd_dai_probe(priv, dai_np, dai_np, 0, dai_i);
 				if (!rsnd_is_gen1(priv) && !rsnd_is_gen2(priv)) {
 					rdai = rsnd_rdai_get(priv, dai_i);
-- 
2.43.0
Re: [PATCH] ASoC: rsnd: Refactor port handling with helper for endpoint node selection
Posted by Mark Brown 1 month, 1 week ago
On Fri, 11 Oct 2024 18:53:46 +0100, Prabhakar wrote:
> Refactor the code responsible for selecting the correct device node for
> audio endpoint parsing in the rsnd driver. A new helper function
> `rsnd_pick_endpoint_node_for_ports()` is introduced to handle the
> selection of the endpoint node by checking whether the port is named
> 'port' or 'ports'.
> 
> This change simplifies the logic in both `rsnd_dai_of_node()` and
> `rsnd_dai_probe()` functions by replacing repetitive condition checks
> with the new helper.
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: rsnd: Refactor port handling with helper for endpoint node selection
      commit: daf5e3c68144bdb7e605f46853febc7bb257d44d

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
Re: [PATCH] ASoC: rsnd: Refactor port handling with helper for endpoint node selection
Posted by Kuninori Morimoto 1 month, 1 week ago
Hi Prabhakar

> From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> 
> Refactor the code responsible for selecting the correct device node for
> audio endpoint parsing in the rsnd driver. A new helper function
> `rsnd_pick_endpoint_node_for_ports()` is introduced to handle the
> selection of the endpoint node by checking whether the port is named
> 'port' or 'ports'.
> 
> This change simplifies the logic in both `rsnd_dai_of_node()` and
> `rsnd_dai_probe()` functions by replacing repetitive condition checks
> with the new helper.
> 
> Suggested-by: Geert Uytterhoeven <geert+renesas@glider.be>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
> ---

Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Thank you for your help !!

Best regards
---
Kuninori Morimoto