ASoC: Intel: mrfld: simplify sst_fill_widget_module_info
authorRasmus Villemoes <linux@rasmusvillemoes.dk>
Thu, 4 Jun 2015 08:13:53 +0000 (10:13 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 15 Jun 2015 09:50:28 +0000 (10:50 +0100)
Some tiny improvements, cutting 180 bytes off the generated code.

- use strchr() for single-character needle

- compute index using pointer subtraction instead of two strlen()
  calls

- factor out the common check for whether the initial part of
  kctl->id.name (before the space) is identical to w->name.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Acked-by: Vinod Koul <vinod.koul@intel.com>
Tested-by: Fang, Yang A <yang.a.fang@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/atom/sst-atom-controls.c

index 61e24093545115d8653b9fe51249727df45315ca..31e9b9ecbb8a599100774ad6fdee346755d43b42 100644 (file)
@@ -1401,36 +1401,32 @@ static int sst_fill_widget_module_info(struct snd_soc_dapm_widget *w,
        down_read(&card->controls_rwsem);
 
        list_for_each_entry(kctl, &card->controls, list) {
-               idx = strstr(kctl->id.name, " ");
+               idx = strchr(kctl->id.name, ' ');
                if (idx == NULL)
                        continue;
-               index  = strlen(kctl->id.name) - strlen(idx);
+               index = idx - (char*)kctl->id.name;
+               if (strncmp(kctl->id.name, w->name, index))
+                       continue;
 
-               if (strstr(kctl->id.name, "Volume") &&
-                   !strncmp(kctl->id.name, w->name, index))
+               if (strstr(kctl->id.name, "Volume"))
                        ret = sst_fill_module_list(kctl, w, SST_MODULE_GAIN);
 
-               else if (strstr(kctl->id.name, "params") &&
-                        !strncmp(kctl->id.name, w->name, index))
+               else if (strstr(kctl->id.name, "params"))
                        ret = sst_fill_module_list(kctl, w, SST_MODULE_ALGO);
 
                else if (strstr(kctl->id.name, "Switch") &&
-                        !strncmp(kctl->id.name, w->name, index) &&
                         strstr(kctl->id.name, "Gain")) {
                        struct sst_gain_mixer_control *mc =
                                                (void *)kctl->private_value;
 
                        mc->w = w;
 
-               } else if (strstr(kctl->id.name, "interleaver") &&
-                        !strncmp(kctl->id.name, w->name, index)) {
+               } else if (strstr(kctl->id.name, "interleaver")) {
                        struct sst_enum *e = (void *)kctl->private_value;
 
                        e->w = w;
 
-               } else if (strstr(kctl->id.name, "deinterleaver") &&
-                        !strncmp(kctl->id.name, w->name, index)) {
-
+               } else if (strstr(kctl->id.name, "deinterleaver")) {
                        struct sst_enum *e = (void *)kctl->private_value;
 
                        e->w = w;