summaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-core.c
diff options
context:
space:
mode:
authorTakashi Iwai2014-02-18 08:11:42 +0100
committerMark Brown2014-02-20 02:42:53 +0100
commit9a8d38db030f016bee45b927af02d9b46398ed46 (patch)
tree3f0e1d8e3d42778880caf5ac6f4bfef6e96dc5c0 /sound/soc/soc-core.c
parentLinus 3.14-rc1 (diff)
downloadkernel-qcow2-linux-9a8d38db030f016bee45b927af02d9b46398ed46.tar.gz
kernel-qcow2-linux-9a8d38db030f016bee45b927af02d9b46398ed46.tar.xz
kernel-qcow2-linux-9a8d38db030f016bee45b927af02d9b46398ed46.zip
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,
uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
uinfo->count = e->shift_l == e->shift_r ? 1 : 2;
- uinfo->value.enumerated.items = e->max;
+ uinfo->value.enumerated.items = e->items;
- if (uinfo->value.enumerated.item > e->max - 1)
- uinfo->value.enumerated.item = e->max - 1;
+ if (uinfo->value.enumerated.item >= e->items)
+ uinfo->value.enumerated.item = e->items - 1;
strlcpy(uinfo->value.enumerated.name,
e->texts[uinfo->value.enumerated.item],
sizeof(uinfo->value.enumerated.name));
@@ -2626,12 +2626,12 @@ int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
unsigned int val;
unsigned int mask;
- if (ucontrol->value.enumerated.item[0] > e->max - 1)
+ if (ucontrol->value.enumerated.item[0] >= e->items)
return -EINVAL;
val = ucontrol->value.enumerated.item[0] << e->shift_l;
mask = e->mask << e->shift_l;
if (e->shift_l != e->shift_r) {
- if (ucontrol->value.enumerated.item[1] > e->max - 1)
+ if (ucontrol->value.enumerated.item[1] >= e->items)
return -EINVAL;
val |= ucontrol->value.enumerated.item[1] << e->shift_r;
mask |= e->mask << e->shift_r;
@@ -2662,14 +2662,14 @@ int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
reg_val = snd_soc_read(codec, e->reg);
val = (reg_val >> e->shift_l) & e->mask;
- for (mux = 0; mux < e->max; mux++) {
+ for (mux = 0; mux < e->items; mux++) {
if (val == e->values[mux])
break;
}
ucontrol->value.enumerated.item[0] = mux;
if (e->shift_l != e->shift_r) {
val = (reg_val >> e->shift_r) & e->mask;
- for (mux = 0; mux < e->max; mux++) {
+ for (mux = 0; mux < e->items; mux++) {
if (val == e->values[mux])
break;
}
@@ -2700,12 +2700,12 @@ int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
unsigned int val;
unsigned int mask;
- if (ucontrol->value.enumerated.item[0] > e->max - 1)
+ if (ucontrol->value.enumerated.item[0] >= e->items)
return -EINVAL;
val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
mask = e->mask << e->shift_l;
if (e->shift_l != e->shift_r) {
- if (ucontrol->value.enumerated.item[1] > e->max - 1)
+ if (ucontrol->value.enumerated.item[1] >= e->items)
return -EINVAL;
val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
mask |= e->mask << e->shift_r;