aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2014-02-18 02:11:42 -0500
committerMark Brown <broonie@linaro.org>2014-02-19 20:42:53 -0500
commit9a8d38db030f016bee45b927af02d9b46398ed46 (patch)
tree3f0e1d8e3d42778880caf5ac6f4bfef6e96dc5c0 /sound/soc/soc-core.c
parent38dbfb59d1175ef458d006556061adeaa8751b72 (diff)
ASoC: Rename soc_enum.max field with items
The name "max" in struct soc_enum is rather confusing since it actually takes the number of items. With "max", one might try to assign (nitems - 1) value. Rename the field to a more appropriate one, "items", which is also used in struct snd_ctl_elem_info, too. This patch also rewrites some code like "if (x > e->nitems - 1)" with "if (x >= e->nitems)". Not only the latter improves the readability, it also fixes a potential bug when e->items is zero. Signed-off-by: Takashi Iwai <tiwai@suse.de> Acked-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/soc-core.c')
-rw-r--r--sound/soc/soc-core.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index fe1df50805a3..4372efb4e033 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2571,10 +2571,10 @@ int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
2571 2571
2572 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2572 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2573 uinfo->count = e->shift_l == e->shift_r ? 1 : 2; 2573 uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
2574 uinfo->value.enumerated.items = e->max; 2574 uinfo->value.enumerated.items = e->items;
2575 2575
2576 if (uinfo->value.enumerated.item > e->max - 1) 2576 if (uinfo->value.enumerated.item >= e->items)
2577 uinfo->value.enumerated.item = e->max - 1; 2577 uinfo->value.enumerated.item = e->items - 1;
2578 strlcpy(uinfo->value.enumerated.name, 2578 strlcpy(uinfo->value.enumerated.name,
2579 e->texts[uinfo->value.enumerated.item], 2579 e->texts[uinfo->value.enumerated.item],
2580 sizeof(uinfo->value.enumerated.name)); 2580 sizeof(uinfo->value.enumerated.name));
@@ -2626,12 +2626,12 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
2626 unsigned int val; 2626 unsigned int val;
2627 unsigned int mask; 2627 unsigned int mask;
2628 2628
2629 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2629 if (ucontrol->value.enumerated.item[0] >= e->items)
2630 return -EINVAL; 2630 return -EINVAL;
2631 val = ucontrol->value.enumerated.item[0] << e->shift_l; 2631 val = ucontrol->value.enumerated.item[0] << e->shift_l;
2632 mask = e->mask << e->shift_l; 2632 mask = e->mask << e->shift_l;
2633 if (e->shift_l != e->shift_r) { 2633 if (e->shift_l != e->shift_r) {
2634 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2634 if (ucontrol->value.enumerated.item[1] >= e->items)
2635 return -EINVAL; 2635 return -EINVAL;
2636 val |= ucontrol->value.enumerated.item[1] << e->shift_r; 2636 val |= ucontrol->value.enumerated.item[1] << e->shift_r;
2637 mask |= e->mask << e->shift_r; 2637 mask |= e->mask << e->shift_r;
@@ -2662,14 +2662,14 @@ int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
2662 2662
2663 reg_val = snd_soc_read(codec, e->reg); 2663 reg_val = snd_soc_read(codec, e->reg);
2664 val = (reg_val >> e->shift_l) & e->mask; 2664 val = (reg_val >> e->shift_l) & e->mask;
2665 for (mux = 0; mux < e->max; mux++) { 2665 for (mux = 0; mux < e->items; mux++) {
2666 if (val == e->values[mux]) 2666 if (val == e->values[mux])
2667 break; 2667 break;
2668 } 2668 }
2669 ucontrol->value.enumerated.item[0] = mux; 2669 ucontrol->value.enumerated.item[0] = mux;
2670 if (e->shift_l != e->shift_r) { 2670 if (e->shift_l != e->shift_r) {
2671 val = (reg_val >> e->shift_r) & e->mask; 2671 val = (reg_val >> e->shift_r) & e->mask;
2672 for (mux = 0; mux < e->max; mux++) { 2672 for (mux = 0; mux < e->items; mux++) {
2673 if (val == e->values[mux]) 2673 if (val == e->values[mux])
2674 break; 2674 break;
2675 } 2675 }
@@ -2700,12 +2700,12 @@ int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
2700 unsigned int val; 2700 unsigned int val;
2701 unsigned int mask; 2701 unsigned int mask;
2702 2702
2703 if (ucontrol->value.enumerated.item[0] > e->max - 1) 2703 if (ucontrol->value.enumerated.item[0] >= e->items)
2704 return -EINVAL; 2704 return -EINVAL;
2705 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l; 2705 val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
2706 mask = e->mask << e->shift_l; 2706 mask = e->mask << e->shift_l;
2707 if (e->shift_l != e->shift_r) { 2707 if (e->shift_l != e->shift_r) {
2708 if (ucontrol->value.enumerated.item[1] > e->max - 1) 2708 if (ucontrol->value.enumerated.item[1] >= e->items)
2709 return -EINVAL; 2709 return -EINVAL;
2710 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r; 2710 val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
2711 mask |= e->mask << e->shift_r; 2711 mask |= e->mask << e->shift_r;