Commit 5aeee342 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb-audio: Refactor ignore_ctl_error checks

Introduce an internal helper macro for avoiding many open codes.

The only slight behavior change is in a couple of get ballcks where
the value is reset at error no matter whether ignore_ctl_error is set
or not.  Actually this is even safer than before.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent a69862d8
...@@ -136,6 +136,10 @@ check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen) ...@@ -136,6 +136,10 @@ check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen)
return strlcpy(buf, p->name, buflen); return strlcpy(buf, p->name, buflen);
} }
/* ignore the error value if ignore_ctl_error flag is set */
#define filter_error(cval, err) \
((cval)->mixer->ignore_ctl_error ? 0 : (err))
/* check whether the control should be ignored */ /* check whether the control should be ignored */
static inline int static inline int
check_ignored_ctl(const struct usbmix_name_map *p) check_ignored_ctl(const struct usbmix_name_map *p)
...@@ -1088,7 +1092,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, ...@@ -1088,7 +1092,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
continue; continue;
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val); err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &val);
if (err < 0) if (err < 0)
return cval->mixer->ignore_ctl_error ? 0 : err; return filter_error(cval, err);
val = get_relative_value(cval, val); val = get_relative_value(cval, val);
ucontrol->value.integer.value[cnt] = val; ucontrol->value.integer.value[cnt] = val;
cnt++; cnt++;
...@@ -1098,7 +1102,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, ...@@ -1098,7 +1102,7 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol,
/* master channel */ /* master channel */
err = snd_usb_get_cur_mix_value(cval, 0, 0, &val); err = snd_usb_get_cur_mix_value(cval, 0, 0, &val);
if (err < 0) if (err < 0)
return cval->mixer->ignore_ctl_error ? 0 : err; return filter_error(cval, err);
val = get_relative_value(cval, val); val = get_relative_value(cval, val);
ucontrol->value.integer.value[0] = val; ucontrol->value.integer.value[0] = val;
} }
...@@ -1120,7 +1124,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, ...@@ -1120,7 +1124,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
continue; continue;
err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval); err = snd_usb_get_cur_mix_value(cval, c + 1, cnt, &oval);
if (err < 0) if (err < 0)
return cval->mixer->ignore_ctl_error ? 0 : err; return filter_error(cval, err);
val = ucontrol->value.integer.value[cnt]; val = ucontrol->value.integer.value[cnt];
val = get_abs_value(cval, val); val = get_abs_value(cval, val);
if (oval != val) { if (oval != val) {
...@@ -1133,7 +1137,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, ...@@ -1133,7 +1137,7 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol,
/* master channel */ /* master channel */
err = snd_usb_get_cur_mix_value(cval, 0, 0, &oval); err = snd_usb_get_cur_mix_value(cval, 0, 0, &oval);
if (err < 0) if (err < 0)
return cval->mixer->ignore_ctl_error ? 0 : err; return filter_error(cval, err);
val = ucontrol->value.integer.value[0]; val = ucontrol->value.integer.value[0];
val = get_abs_value(cval, val); val = get_abs_value(cval, val);
if (val != oval) { if (val != oval) {
...@@ -1628,12 +1632,10 @@ static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol, ...@@ -1628,12 +1632,10 @@ static int mixer_ctl_procunit_get(struct snd_kcontrol *kcontrol,
int err, val; int err, val;
err = get_cur_ctl_value(cval, cval->control << 8, &val); err = get_cur_ctl_value(cval, cval->control << 8, &val);
if (err < 0 && cval->mixer->ignore_ctl_error) { if (err < 0) {
ucontrol->value.integer.value[0] = cval->min; ucontrol->value.integer.value[0] = cval->min;
return 0; return filter_error(cval, err);
} }
if (err < 0)
return err;
val = get_relative_value(cval, val); val = get_relative_value(cval, val);
ucontrol->value.integer.value[0] = val; ucontrol->value.integer.value[0] = val;
return 0; return 0;
...@@ -1647,11 +1649,8 @@ static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol, ...@@ -1647,11 +1649,8 @@ static int mixer_ctl_procunit_put(struct snd_kcontrol *kcontrol,
int val, oval, err; int val, oval, err;
err = get_cur_ctl_value(cval, cval->control << 8, &oval); err = get_cur_ctl_value(cval, cval->control << 8, &oval);
if (err < 0) { if (err < 0)
if (cval->mixer->ignore_ctl_error) return filter_error(cval, err);
return 0;
return err;
}
val = ucontrol->value.integer.value[0]; val = ucontrol->value.integer.value[0];
val = get_abs_value(cval, val); val = get_abs_value(cval, val);
if (val != oval) { if (val != oval) {
...@@ -1923,11 +1922,8 @@ static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol, ...@@ -1923,11 +1922,8 @@ static int mixer_ctl_selector_get(struct snd_kcontrol *kcontrol,
err = get_cur_ctl_value(cval, cval->control << 8, &val); err = get_cur_ctl_value(cval, cval->control << 8, &val);
if (err < 0) { if (err < 0) {
if (cval->mixer->ignore_ctl_error) {
ucontrol->value.enumerated.item[0] = 0; ucontrol->value.enumerated.item[0] = 0;
return 0; return filter_error(cval, err);
}
return err;
} }
val = get_relative_value(cval, val); val = get_relative_value(cval, val);
ucontrol->value.enumerated.item[0] = val; ucontrol->value.enumerated.item[0] = val;
...@@ -1942,11 +1938,8 @@ static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol, ...@@ -1942,11 +1938,8 @@ static int mixer_ctl_selector_put(struct snd_kcontrol *kcontrol,
int val, oval, err; int val, oval, err;
err = get_cur_ctl_value(cval, cval->control << 8, &oval); err = get_cur_ctl_value(cval, cval->control << 8, &oval);
if (err < 0) { if (err < 0)
if (cval->mixer->ignore_ctl_error) return filter_error(cval, err);
return 0;
return err;
}
val = ucontrol->value.enumerated.item[0]; val = ucontrol->value.enumerated.item[0];
val = get_abs_value(cval, val); val = get_abs_value(cval, val);
if (val != oval) { if (val != oval) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment