diff mbox

[31/33] ASoC: max98088: use match_string() helper

Message ID 1526903890-35761-32-git-send-email-xieyisheng1@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Xie Yisheng May 21, 2018, 11:58 a.m. UTC
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>
Cc: Takashi Iwai <tiwai@suse.com>
Cc: alsa-devel@alsa-project.org
Signed-off-by: Yisheng Xie <xieyisheng1@huawei.com>
---
 sound/soc/codecs/max98088.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Andy Shevchenko May 21, 2018, 10:24 p.m. UTC | #1
On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used intead of open coded variant.

>  static int max98088_get_channel(struct snd_soc_component *component, const char *name)
>  {

> +       int ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
I would rather split this and move an assignment to the line before 'if'

>
>         /* Shouldn't happen */

> +       if (ret < 0)
> +               dev_err(component->dev, "Bad EQ channel name '%s'\n", name);

>         return -EINVAL;

return ret;

?

>  }
>
> --
> 1.7.12.4
>
Xie Yisheng May 22, 2018, 12:30 p.m. UTC | #2
Hi Andy,

On 2018/5/22 6:24, Andy Shevchenko wrote:
> On Mon, May 21, 2018 at 2:58 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
>> match_string() returns the index of an array for a matching string,
>> which can be used intead of open coded variant.
> 
>>  static int max98088_get_channel(struct snd_soc_component *component, const char *name)
>>  {
> 
>> +       int ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
> I would rather split this and move an assignment to the line before 'if'

hmm, you mean something like:

	int ret;

	ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
	if (ret < 0) /* Shouldn't happen */
		dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
	return ret;
>>
>>         /* Shouldn't happen */
> 
>> +       if (ret < 0)
>> +               dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
> 
>>         return -EINVAL;
> 
> return ret;
Right, sorry for this big mistake.

Thanks
Yisheng
> 
> ?
> 
>>  }
>>
>> --
>> 1.7.12.4
>>
> 
> 
>
Andy Shevchenko May 22, 2018, 5:23 p.m. UTC | #3
On Tue, May 22, 2018 at 3:30 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:

> hmm, you mean something like:
>
>         int ret;
>
>         ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
>         if (ret < 0) /* Shouldn't happen */
>                 dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
>         return ret;

Yes. (But remove that useless comment).
diff mbox

Patch

diff --git a/sound/soc/codecs/max98088.c b/sound/soc/codecs/max98088.c
index 865f64c..7383f90 100644
--- a/sound/soc/codecs/max98088.c
+++ b/sound/soc/codecs/max98088.c
@@ -1382,14 +1382,11 @@  static int max98088_set_bias_level(struct snd_soc_component *component,
 
 static int max98088_get_channel(struct snd_soc_component *component, const char *name)
 {
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(eq_mode_name); i++)
-		if (strcmp(name, eq_mode_name[i]) == 0)
-			return i;
+	int ret = match_string(eq_mode_name, ARRAY_SIZE(eq_mode_name), name);
 
 	/* Shouldn't happen */
-	dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
+	if (ret < 0)
+		dev_err(component->dev, "Bad EQ channel name '%s'\n", name);
 	return -EINVAL;
 }