Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ALSA: hda - Use a macro for snd_array iteration loops

Introduce a new helper macro, snd_array_for_each(), to iterate for
each snd_array element. It slightly improves the readability than
lengthy open codes at each place.

Along with it, add const prefix to some obvious places.

There should be no functional changes by this.

Signed-off-by: Takashi Iwai <tiwai@suse.de>

+57 -54
+5
include/sound/hdaudio.h
··· 571 571 return (unsigned long)(ptr - array->list) / array->elem_size; 572 572 } 573 573 574 + /* a helper macro to iterate for each snd_array element */ 575 + #define snd_array_for_each(array, idx, ptr) \ 576 + for ((idx) = 0, (ptr) = (array)->list; (idx) < (array)->used; \ 577 + (ptr) = snd_array_elem(array, ++(idx))) 578 + 574 579 #endif /* __SOUND_HDAUDIO_H */
+2 -2
sound/hda/hdac_regmap.c
··· 65 65 { 66 66 struct hdac_device *codec = dev_to_hdac_dev(dev); 67 67 unsigned int verb = get_verb(reg); 68 + const unsigned int *v; 68 69 int i; 69 70 70 - for (i = 0; i < codec->vendor_verbs.used; i++) { 71 - unsigned int *v = snd_array_elem(&codec->vendor_verbs, i); 71 + snd_array_for_each(&codec->vendor_verbs, i, v) { 72 72 if (verb == *v) 73 73 return true; 74 74 }
+5 -5
sound/pci/hda/hda_auto_parser.c
··· 793 793 */ 794 794 void snd_hda_apply_verbs(struct hda_codec *codec) 795 795 { 796 + const struct hda_verb **v; 796 797 int i; 797 - for (i = 0; i < codec->verbs.used; i++) { 798 - struct hda_verb **v = snd_array_elem(&codec->verbs, i); 798 + 799 + snd_array_for_each(&codec->verbs, i, v) 799 800 snd_hda_sequence_write(codec, *v); 800 - } 801 801 } 802 802 EXPORT_SYMBOL_GPL(snd_hda_apply_verbs); 803 803 ··· 890 890 static bool pin_config_match(struct hda_codec *codec, 891 891 const struct hda_pintbl *pins) 892 892 { 893 + const struct hda_pincfg *pin; 893 894 int i; 894 895 895 - for (i = 0; i < codec->init_pins.used; i++) { 896 - struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 896 + snd_array_for_each(&codec->init_pins, i, pin) { 897 897 hda_nid_t nid = pin->nid; 898 898 u32 cfg = pin->cfg; 899 899 const struct hda_pintbl *t_pins;
+18 -18
sound/pci/hda/hda_codec.c
··· 481 481 struct snd_array *array, 482 482 hda_nid_t nid) 483 483 { 484 + struct hda_pincfg *pin; 484 485 int i; 485 - for (i = 0; i < array->used; i++) { 486 - struct hda_pincfg *pin = snd_array_elem(array, i); 486 + 487 + snd_array_for_each(array, i, pin) { 487 488 if (pin->nid == nid) 488 489 return pin; 489 490 } ··· 619 618 */ 620 619 void snd_hda_shutup_pins(struct hda_codec *codec) 621 620 { 621 + const struct hda_pincfg *pin; 622 622 int i; 623 + 623 624 /* don't shut up pins when unloading the driver; otherwise it breaks 624 625 * the default pin setup at the next load of the driver 625 626 */ 626 627 if (codec->bus->shutdown) 627 628 return; 628 - for (i = 0; i < codec->init_pins.used; i++) { 629 - struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 629 + snd_array_for_each(&codec->init_pins, i, pin) { 630 630 /* use read here for syncing after issuing each verb */ 631 631 snd_hda_codec_read(codec, pin->nid, 0, 632 632 AC_VERB_SET_PIN_WIDGET_CONTROL, 0); ··· 640 638 /* Restore the pin controls cleared previously via snd_hda_shutup_pins() */ 641 639 static void restore_shutup_pins(struct hda_codec *codec) 642 640 { 641 + const struct hda_pincfg *pin; 643 642 int i; 643 + 644 644 if (!codec->pins_shutup) 645 645 return; 646 646 if (codec->bus->shutdown) 647 647 return; 648 - for (i = 0; i < codec->init_pins.used; i++) { 649 - struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 648 + snd_array_for_each(&codec->init_pins, i, pin) { 650 649 snd_hda_codec_write(codec, pin->nid, 0, 651 650 AC_VERB_SET_PIN_WIDGET_CONTROL, 652 651 pin->ctrl); ··· 700 697 struct hda_cvt_setup *p; 701 698 int i; 702 699 703 - for (i = 0; i < codec->cvt_setups.used; i++) { 704 - p = snd_array_elem(&codec->cvt_setups, i); 700 + snd_array_for_each(&codec->cvt_setups, i, p) { 705 701 if (p->nid == nid) 706 702 return p; 707 703 } ··· 1078 1076 /* make other inactive cvts with the same stream-tag dirty */ 1079 1077 type = get_wcaps_type(get_wcaps(codec, nid)); 1080 1078 list_for_each_codec(c, codec->bus) { 1081 - for (i = 0; i < c->cvt_setups.used; i++) { 1082 - p = snd_array_elem(&c->cvt_setups, i); 1079 + snd_array_for_each(&c->cvt_setups, i, p) { 1083 1080 if (!p->active && p->stream_tag == stream_tag && 1084 1081 get_wcaps_type(get_wcaps(c, p->nid)) == type) 1085 1082 p->dirty = 1; ··· 1141 1140 static void purify_inactive_streams(struct hda_codec *codec) 1142 1141 { 1143 1142 struct hda_codec *c; 1143 + struct hda_cvt_setup *p; 1144 1144 int i; 1145 1145 1146 1146 list_for_each_codec(c, codec->bus) { 1147 - for (i = 0; i < c->cvt_setups.used; i++) { 1148 - struct hda_cvt_setup *p; 1149 - p = snd_array_elem(&c->cvt_setups, i); 1147 + snd_array_for_each(&c->cvt_setups, i, p) { 1150 1148 if (p->dirty) 1151 1149 really_cleanup_stream(c, p); 1152 1150 } ··· 1156 1156 /* clean up all streams; called from suspend */ 1157 1157 static void hda_cleanup_all_streams(struct hda_codec *codec) 1158 1158 { 1159 + struct hda_cvt_setup *p; 1159 1160 int i; 1160 1161 1161 - for (i = 0; i < codec->cvt_setups.used; i++) { 1162 - struct hda_cvt_setup *p = snd_array_elem(&codec->cvt_setups, i); 1162 + snd_array_for_each(&codec->cvt_setups, i, p) { 1163 1163 if (p->stream_tag) 1164 1164 really_cleanup_stream(codec, p); 1165 1165 } ··· 2461 2461 struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec, 2462 2462 hda_nid_t nid) 2463 2463 { 2464 + struct hda_spdif_out *spdif; 2464 2465 int i; 2465 - for (i = 0; i < codec->spdif_out.used; i++) { 2466 - struct hda_spdif_out *spdif = 2467 - snd_array_elem(&codec->spdif_out, i); 2466 + 2467 + snd_array_for_each(&codec->spdif_out, i, spdif) { 2468 2468 if (spdif->nid == nid) 2469 2469 return spdif; 2470 2470 }
+13 -14
sound/pci/hda/hda_generic.c
··· 264 264 int anchor_nid) 265 265 { 266 266 struct hda_gen_spec *spec = codec->spec; 267 + struct nid_path *path; 267 268 int i; 268 269 269 - for (i = 0; i < spec->paths.used; i++) { 270 - struct nid_path *path = snd_array_elem(&spec->paths, i); 270 + snd_array_for_each(&spec->paths, i, path) { 271 271 if (path->depth <= 0) 272 272 continue; 273 273 if ((!from_nid || path->path[0] == from_nid) && ··· 325 325 static bool is_dac_already_used(struct hda_codec *codec, hda_nid_t nid) 326 326 { 327 327 struct hda_gen_spec *spec = codec->spec; 328 + const struct nid_path *path; 328 329 int i; 329 330 330 - for (i = 0; i < spec->paths.used; i++) { 331 - struct nid_path *path = snd_array_elem(&spec->paths, i); 331 + snd_array_for_each(&spec->paths, i, path) { 332 332 if (path->path[0] == nid) 333 333 return true; 334 334 } ··· 351 351 static bool is_ctl_used(struct hda_codec *codec, unsigned int val, int type) 352 352 { 353 353 struct hda_gen_spec *spec = codec->spec; 354 + const struct nid_path *path; 354 355 int i; 355 356 356 357 val &= AMP_VAL_COMPARE_MASK; 357 - for (i = 0; i < spec->paths.used; i++) { 358 - struct nid_path *path = snd_array_elem(&spec->paths, i); 358 + snd_array_for_each(&spec->paths, i, path) { 359 359 if ((path->ctls[type] & AMP_VAL_COMPARE_MASK) == val) 360 360 return true; 361 361 } ··· 638 638 { 639 639 struct hda_gen_spec *spec = codec->spec; 640 640 int type = get_wcaps_type(get_wcaps(codec, nid)); 641 + const struct nid_path *path; 641 642 int i, n; 642 643 643 644 if (nid == codec->core.afg) 644 645 return true; 645 646 646 - for (n = 0; n < spec->paths.used; n++) { 647 - struct nid_path *path = snd_array_elem(&spec->paths, n); 647 + snd_array_for_each(&spec->paths, n, path) { 648 648 if (!path->active) 649 649 continue; 650 650 if (codec->power_save_node) { ··· 2696 2696 static bool find_kctl_name(struct hda_codec *codec, const char *name, int idx) 2697 2697 { 2698 2698 struct hda_gen_spec *spec = codec->spec; 2699 + const struct snd_kcontrol_new *kctl; 2699 2700 int i; 2700 2701 2701 - for (i = 0; i < spec->kctls.used; i++) { 2702 - struct snd_kcontrol_new *kctl = snd_array_elem(&spec->kctls, i); 2702 + snd_array_for_each(&spec->kctls, i, kctl) { 2703 2703 if (!strcmp(kctl->name, name) && kctl->index == idx) 2704 2704 return true; 2705 2705 } ··· 4021 4021 struct nid_path *path; 4022 4022 int n; 4023 4023 4024 - for (n = 0; n < spec->paths.used; n++) { 4025 - path = snd_array_elem(&spec->paths, n); 4024 + snd_array_for_each(&spec->paths, n, path) { 4026 4025 if (!path->depth) 4027 4026 continue; 4028 4027 if (path->path[0] == nid || ··· 5830 5831 */ 5831 5832 static void clear_unsol_on_unused_pins(struct hda_codec *codec) 5832 5833 { 5834 + const struct hda_pincfg *pin; 5833 5835 int i; 5834 5836 5835 - for (i = 0; i < codec->init_pins.used; i++) { 5836 - struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 5837 + snd_array_for_each(&codec->init_pins, i, pin) { 5837 5838 hda_nid_t nid = pin->nid; 5838 5839 if (is_jack_detectable(codec, nid) && 5839 5840 !snd_hda_jack_tbl_get(codec, nid))
+10 -10
sound/pci/hda/hda_sysfs.c
··· 80 80 struct snd_array *list, 81 81 char *buf) 82 82 { 83 + const struct hda_pincfg *pin; 83 84 int i, len = 0; 84 85 mutex_lock(&codec->user_mutex); 85 - for (i = 0; i < list->used; i++) { 86 - struct hda_pincfg *pin = snd_array_elem(list, i); 86 + snd_array_for_each(list, i, pin) { 87 87 len += sprintf(buf + len, "0x%02x 0x%08x\n", 88 88 pin->nid, pin->cfg); 89 89 } ··· 217 217 char *buf) 218 218 { 219 219 struct hda_codec *codec = dev_get_drvdata(dev); 220 + const struct hda_verb *v; 220 221 int i, len = 0; 221 222 mutex_lock(&codec->user_mutex); 222 - for (i = 0; i < codec->init_verbs.used; i++) { 223 - struct hda_verb *v = snd_array_elem(&codec->init_verbs, i); 223 + snd_array_for_each(&codec->init_verbs, i, v) { 224 224 len += snprintf(buf + len, PAGE_SIZE - len, 225 225 "0x%02x 0x%03x 0x%04x\n", 226 226 v->nid, v->verb, v->param); ··· 267 267 char *buf) 268 268 { 269 269 struct hda_codec *codec = dev_get_drvdata(dev); 270 + const struct hda_hint *hint; 270 271 int i, len = 0; 271 272 mutex_lock(&codec->user_mutex); 272 - for (i = 0; i < codec->hints.used; i++) { 273 - struct hda_hint *hint = snd_array_elem(&codec->hints, i); 273 + snd_array_for_each(&codec->hints, i, hint) { 274 274 len += snprintf(buf + len, PAGE_SIZE - len, 275 275 "%s = %s\n", hint->key, hint->val); 276 276 } ··· 280 280 281 281 static struct hda_hint *get_hint(struct hda_codec *codec, const char *key) 282 282 { 283 + struct hda_hint *hint; 283 284 int i; 284 285 285 - for (i = 0; i < codec->hints.used; i++) { 286 - struct hda_hint *hint = snd_array_elem(&codec->hints, i); 286 + snd_array_for_each(&codec->hints, i, hint) { 287 287 if (!strcmp(hint->key, key)) 288 288 return hint; 289 289 } ··· 783 783 void snd_hda_sysfs_clear(struct hda_codec *codec) 784 784 { 785 785 #ifdef CONFIG_SND_HDA_RECONFIG 786 + struct hda_hint *hint; 786 787 int i; 787 788 788 789 /* clear init verbs */ 789 790 snd_array_free(&codec->init_verbs); 790 791 /* clear hints */ 791 - for (i = 0; i < codec->hints.used; i++) { 792 - struct hda_hint *hint = snd_array_elem(&codec->hints, i); 792 + snd_array_for_each(&codec->hints, i, hint) { 793 793 kfree(hint->key); /* we don't need to free hint->val */ 794 794 } 795 795 snd_array_free(&codec->hints);
+2 -3
sound/pci/hda/patch_conexant.c
··· 588 588 const struct hda_fixup *fix, int action) 589 589 { 590 590 struct conexant_spec *spec = codec->spec; 591 + struct snd_kcontrol_new *kctl; 591 592 int i; 592 593 593 594 if (action != HDA_FIXUP_ACT_PROBE) ··· 607 606 snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50); 608 607 609 608 /* override mic boost control */ 610 - for (i = 0; i < spec->gen.kctls.used; i++) { 611 - struct snd_kcontrol_new *kctl = 612 - snd_array_elem(&spec->gen.kctls, i); 609 + snd_array_for_each(&spec->gen.kctls, i, kctl) { 613 610 if (!strcmp(kctl->name, "Mic Boost Volume")) { 614 611 kctl->put = olpc_xo_mic_boost_put; 615 612 break;
+2 -2
sound/pci/hda/patch_realtek.c
··· 2828 2828 2829 2829 static void alc286_shutup(struct hda_codec *codec) 2830 2830 { 2831 + const struct hda_pincfg *pin; 2831 2832 int i; 2832 2833 int mic_pin = find_ext_mic_pin(codec); 2833 2834 /* don't shut up pins when unloading the driver; otherwise it breaks ··· 2836 2835 */ 2837 2836 if (codec->bus->shutdown) 2838 2837 return; 2839 - for (i = 0; i < codec->init_pins.used; i++) { 2840 - struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i); 2838 + snd_array_for_each(&codec->init_pins, i, pin) { 2841 2839 /* use read here for syncing after issuing each verb */ 2842 2840 if (pin->nid != mic_pin) 2843 2841 snd_hda_codec_read(codec, pin->nid, 0,