mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
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: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
2f229a31aa
commit
08d1e63508
1 changed files with 14 additions and 9 deletions
|
@ -898,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = {
|
|||
* 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,
|
||||
unsigned int ctl_mask, int control,
|
||||
struct usb_audio_term *iterm, int unitid)
|
||||
|
@ -978,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc,
|
|||
*/
|
||||
if (! mapped_name && ! (state->oterm.type >> 16)) {
|
||||
if ((state->oterm.type & 0xff00) == 0x0100) {
|
||||
len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name));
|
||||
len = append_ctl_name(kctl, " Capture");
|
||||
} 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",
|
||||
sizeof(kctl->id.name));
|
||||
append_ctl_name(kctl, control == USB_FEATURE_MUTE ?
|
||||
" Switch" : " Volume");
|
||||
if (control == USB_FEATURE_VOLUME) {
|
||||
kctl->tlv.c = mixer_vol_tlv;
|
||||
kctl->vd[0].access |=
|
||||
|
@ -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);
|
||||
if (! len)
|
||||
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",
|
||||
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
|
|||
if (! len)
|
||||
strlcpy(kctl->id.name, name, sizeof(kctl->id.name));
|
||||
}
|
||||
strlcat(kctl->id.name, " ", sizeof(kctl->id.name));
|
||||
strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name));
|
||||
append_ctl_name(kctl, " ");
|
||||
append_ctl_name(kctl, valinfo->suffix);
|
||||
|
||||
snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n",
|
||||
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
|
|||
strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name));
|
||||
|
||||
if ((state->oterm.type & 0xff00) == 0x0100)
|
||||
strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name));
|
||||
append_ctl_name(kctl, " Capture Source");
|
||||
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",
|
||||
|
|
Loading…
Reference in a new issue