[PATCH] ASoC: fix code redundancy in sound/soc/soc-core.c

Liu Jing posted 1 patch 1 month, 1 week ago
sound/soc/soc-core.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
[PATCH] ASoC: fix code redundancy in sound/soc/soc-core.c
Posted by Liu Jing 1 month, 1 week ago
In the snd_soc_register_dai function, the logic for assigning the value of dai->id can be simplified
using the conditional operator (also known as the ternary operator).

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
 sound/soc/soc-core.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 20248a29d167..cbe2be64e1c3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2663,10 +2663,7 @@ struct snd_soc_dai *snd_soc_register_dai(struct snd_soc_component *component,
 		dai->name = fmt_single_name(dev, &dai->id);
 	} else {
 		dai->name = fmt_multiple_name(dev, dai_drv);
-		if (dai_drv->id)
-			dai->id = dai_drv->id;
-		else
-			dai->id = component->num_dai;
+		dai->id = dai_drv->id ? dai_drv->id : component->num_dai;
 	}
 	if (!dai->name)
 		return NULL;
-- 
2.27.0
Re: [PATCH] ASoC: fix code redundancy in sound/soc/soc-core.c
Posted by Mark Brown 1 month, 1 week ago
On Tue, Oct 15, 2024 at 11:17:42AM +0800, Liu Jing wrote:
> In the snd_soc_register_dai function, the logic for assigning the value of dai->id can be simplified
> using the conditional operator (also known as the ternary operator).

The ternery operator is rarely a legibility improvement when used
standalone, this seems to just make thing harder to follow.