Commit 08d1e635 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: usb - Use strlcat() correctly

Don't pass the advanced position to strlcat() but just gives the buffer
head position so that the max size limit can be checked correctly.
Introduced a new helper function to standaralize strlcat() calls.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 2f229a31
...@@ -898,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = { ...@@ -898,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = {
* build a feature control * build a feature control
*/ */
static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str)
{
return strlcat(kctl->id.name, str, sizeof(kctl->id.name));
}
static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
unsigned int ctl_mask, int control, unsigned int ctl_mask, int control,
struct usb_audio_term *iterm, int unitid) struct usb_audio_term *iterm, int unitid)
...@@ -978,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, ...@@ -978,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
*/ */
if (! mapped_name && ! (state->oterm.type >> 16)) { if (! mapped_name && ! (state->oterm.type >> 16)) {
if ((state->oterm.type & 0xff00) == 0x0100) { if ((state->oterm.type & 0xff00) == 0x0100) {
len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name)); len = append_ctl_name(kctl, " Capture");
} else { } else {
len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name)); len = append_ctl_name(kctl, " Playback");
} }
} }
strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume", append_ctl_name(kctl, control == USB_FEATURE_MUTE ?
sizeof(kctl->id.name)); " Switch" : " Volume");
if (control == USB_FEATURE_VOLUME) { if (control == USB_FEATURE_VOLUME) {
kctl->tlv.c = mixer_vol_tlv; kctl->tlv.c = mixer_vol_tlv;
kctl->vd[0].access |= kctl->vd[0].access |=
...@@ -1143,7 +1148,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, ...@@ -1143,7 +1148,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc,
len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0);
if (! len) if (! len)
len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1);
strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name)); append_ctl_name(kctl, " Volume");
snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n",
cval->id, kctl->id.name, cval->channels, cval->min, cval->max); cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
...@@ -1400,8 +1405,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned ...@@ -1400,8 +1405,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned
if (! len) if (! len)
strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
} }
strlcat(kctl->id.name, " ", sizeof(kctl->id.name)); append_ctl_name(kctl, " ");
strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name)); append_ctl_name(kctl, valinfo->suffix);
snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
cval->id, kctl->id.name, cval->channels, cval->min, cval->max); cval->id, kctl->id.name, cval->channels, cval->min, cval->max);
...@@ -1610,9 +1615,9 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi ...@@ -1610,9 +1615,9 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi
strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
if ((state->oterm.type & 0xff00) == 0x0100) if ((state->oterm.type & 0xff00) == 0x0100)
strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name)); append_ctl_name(kctl, " Capture Source");
else else
strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name)); append_ctl_name(kctl, " Playback Source");
} }
snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n",
......
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