diff mbox series

[3/4] ASoC: soc-dapm.c: tidyup snd_soc_dai_link_event_pre_pmu()

Message ID 87y1ux8l7l.wl-kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show
Series ASoC: soc-dapm.c: random cleanup | expand

Commit Message

Kuninori Morimoto Sept. 5, 2022, 11:17 p.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

snd_soc_dai_link_event_pre_pmu() is using if/else for config->formats
check, but "else" case is for just error.
Unnecessary if/else is not good for readable code. this patch checks
if config->formats was zero and call "goto out" in such case.

[not readable]
	if (config->formats) {
(A)		fmt = ...
	} else {
		...
(B)		goto err;
	}

[readable]
	if (!config->formats) {
		...
(B)		goto err;
	}

(A)	fmt = ...

Moreover, we don't need to indicate config->formats value in error message,
because it is zero.

=>	if (config->formats) {
		...
	} else {
		dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n",
=>			 config->formats);
		...
	}

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
 sound/soc/soc-dapm.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Mark Brown Sept. 7, 2022, 11:42 a.m. UTC | #1
On Mon, Sep 05, 2022 at 11:17:50PM +0000, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> snd_soc_dai_link_event_pre_pmu() is using if/else for config->formats
> check, but "else" case is for just error.
> Unnecessary if/else is not good for readable code. this patch checks
> if config->formats was zero and call "goto out" in such case.

This isn't applying for me, I suspect it depends on patch 1 though I
didn't check properly.
diff mbox series

Patch

diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index bc7d64b570b4..e8c813586b53 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -3890,16 +3890,14 @@  snd_soc_dai_link_event_pre_pmu(struct snd_soc_dapm_widget *w,
 	}
 
 	/* Be a little careful as we don't want to overflow the mask array */
-	if (config->formats) {
-		fmt = ffs(config->formats) - 1;
-	} else {
-		dev_warn(w->dapm->dev, "ASoC: Invalid format %llx specified\n",
-			 config->formats);
-
+	if (!config->formats) {
+		dev_warn(w->dapm->dev, "ASoC: Invalid format was specified\n");
 		ret = -EINVAL;
 		goto out;
 	}
 
+	fmt = ffs(config->formats) - 1;
+
 	snd_mask_set(hw_param_mask(&params, SNDRV_PCM_HW_PARAM_FORMAT), fmt);
 	hw_param_interval(&params, SNDRV_PCM_HW_PARAM_RATE)->min	= config->rate_min;
 	hw_param_interval(&params, SNDRV_PCM_HW_PARAM_RATE)->max	= config->rate_max;