diff mbox

[v2,15/21] ALSA: oxygen: use match_string() helper

Message ID 1527765086-19873-16-git-send-email-xieyisheng1@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

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

Cc: Clemens Ladisch <clemens@ladisch.de>
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>
---
v2:
 - do not change the type of i - per Andy

 sound/pci/oxygen/oxygen_mixer.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Takashi Iwai May 31, 2018, 6:39 p.m. UTC | #1
On Thu, 31 May 2018 13:11:20 +0200,
Yisheng Xie wrote:
> 
> match_string() returns the index of an array for a matching string,
> which can be used instead of open coded variant.
> 
> Cc: Clemens Ladisch <clemens@ladisch.de>
> 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>

Applied, thanks.


Takashi
Andy Shevchenko May 31, 2018, 6:40 p.m. UTC | #2
On Thu, May 31, 2018 at 9:39 PM, Takashi Iwai <tiwai@suse.de> wrote:
> On Thu, 31 May 2018 13:11:20 +0200,
> Yisheng Xie wrote:
>>
>> match_string() returns the index of an array for a matching string,
>> which can be used instead of open coded variant.
>>
>> Cc: Clemens Ladisch <clemens@ladisch.de>
>> 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>
>
> Applied, thanks.

Is it too late for nitpick?
Andy Shevchenko May 31, 2018, 6:41 p.m. UTC | #3
On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> match_string() returns the index of an array for a matching string,
> which can be used instead of open coded variant.

Sorry, didn't notice before one thing:

> +               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
> +               if (j >= 0) {
> +                       chip->controls[j] = ctl;
> +                       ctl->private_free = oxygen_any_ctl_free;
> +               }

It looks to me you may get rid of j completely by utilizing existing err.
Takashi Iwai May 31, 2018, 6:43 p.m. UTC | #4
On Thu, 31 May 2018 20:40:28 +0200,
Andy Shevchenko wrote:
> 
> On Thu, May 31, 2018 at 9:39 PM, Takashi Iwai <tiwai@suse.de> wrote:
> > On Thu, 31 May 2018 13:11:20 +0200,
> > Yisheng Xie wrote:
> >>
> >> match_string() returns the index of an array for a matching string,
> >> which can be used instead of open coded variant.
> >>
> >> Cc: Clemens Ladisch <clemens@ladisch.de>
> >> 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>
> >
> > Applied, thanks.
> 
> Is it too late for nitpick?

Depends :)


Takashi
Andy Shevchenko May 31, 2018, 6:44 p.m. UTC | #5
On Thu, May 31, 2018 at 9:43 PM, Takashi Iwai <tiwai@suse.de> wrote:
> On Thu, 31 May 2018 20:40:28 +0200,
> Andy Shevchenko wrote:
>>
>> On Thu, May 31, 2018 at 9:39 PM, Takashi Iwai <tiwai@suse.de> wrote:

>> > Applied, thanks.
>>
>> Is it too late for nitpick?
>
> Depends :)

See my previous mail then.
Takashi Iwai May 31, 2018, 6:59 p.m. UTC | #6
On Thu, 31 May 2018 20:41:36 +0200,
Andy Shevchenko wrote:
> 
> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> > match_string() returns the index of an array for a matching string,
> > which can be used instead of open coded variant.
> 
> Sorry, didn't notice before one thing:
> 
> > +               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
> > +               if (j >= 0) {
> > +                       chip->controls[j] = ctl;
> > +                       ctl->private_free = oxygen_any_ctl_free;
> > +               }
> 
> It looks to me you may get rid of j completely by utilizing existing err.

Well, err isn't ideal as it's referred as the actual index.
That is, the line below looks weird to me:
	chip->controls[err] = ctl;

Of course, j isn't the best name, either, but at least, keeping the
same variable makes the code conversion logic clearer.


thanks,

Takashi
Andy Shevchenko May 31, 2018, 7:02 p.m. UTC | #7
On Thu, May 31, 2018 at 9:59 PM, Takashi Iwai <tiwai@suse.de> wrote:
> On Thu, 31 May 2018 20:41:36 +0200,
> Andy Shevchenko wrote:
>> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:

>> > +               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
>> > +               if (j >= 0) {
>> > +                       chip->controls[j] = ctl;
>> > +                       ctl->private_free = oxygen_any_ctl_free;
>> > +               }
>>
>> It looks to me you may get rid of j completely by utilizing existing err.
>
> Well, err isn't ideal as it's referred as the actual index.
> That is, the line below looks weird to me:
>         chip->controls[err] = ctl;
>
> Of course, j isn't the best name, either, but at least, keeping the
> same variable makes the code conversion logic clearer.

Works for me either way.
Thanks!
Takashi Iwai May 31, 2018, 8:30 p.m. UTC | #8
On Thu, 31 May 2018 21:02:05 +0200,
Andy Shevchenko wrote:
> 
> On Thu, May 31, 2018 at 9:59 PM, Takashi Iwai <tiwai@suse.de> wrote:
> > On Thu, 31 May 2018 20:41:36 +0200,
> > Andy Shevchenko wrote:
> >> On Thu, May 31, 2018 at 2:11 PM, Yisheng Xie <xieyisheng1@huawei.com> wrote:
> 
> >> > +               j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
> >> > +               if (j >= 0) {
> >> > +                       chip->controls[j] = ctl;
> >> > +                       ctl->private_free = oxygen_any_ctl_free;
> >> > +               }
> >>
> >> It looks to me you may get rid of j completely by utilizing existing err.
> >
> > Well, err isn't ideal as it's referred as the actual index.
> > That is, the line below looks weird to me:
> >         chip->controls[err] = ctl;
> >
> > Of course, j isn't the best name, either, but at least, keeping the
> > same variable makes the code conversion logic clearer.
> 
> Works for me either way.
> Thanks!

OK, let's take as is.


thanks,

Takashi
diff mbox

Patch

diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index 4ca1266..81af21a 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -1052,10 +1052,10 @@  static int add_controls(struct oxygen *chip,
 		[CONTROL_CD_CAPTURE_SWITCH] = "CD Capture Switch",
 		[CONTROL_AUX_CAPTURE_SWITCH] = "Aux Capture Switch",
 	};
-	unsigned int i, j;
+	unsigned int i;
 	struct snd_kcontrol_new template;
 	struct snd_kcontrol *ctl;
-	int err;
+	int j, err;
 
 	for (i = 0; i < count; ++i) {
 		template = controls[i];
@@ -1086,11 +1086,11 @@  static int add_controls(struct oxygen *chip,
 		err = snd_ctl_add(chip->card, ctl);
 		if (err < 0)
 			return err;
-		for (j = 0; j < CONTROL_COUNT; ++j)
-			if (!strcmp(ctl->id.name, known_ctl_names[j])) {
-				chip->controls[j] = ctl;
-				ctl->private_free = oxygen_any_ctl_free;
-			}
+		j = match_string(known_ctl_names, CONTROL_COUNT, ctl->id.name);
+		if (j >= 0) {
+			chip->controls[j] = ctl;
+			ctl->private_free = oxygen_any_ctl_free;
+		}
 	}
 	return 0;
 }