Skip to content

Commit

Permalink
ALSA: usb - Use strlcat() correctly
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Takashi Iwai committed Oct 2, 2009
1 parent 2f229a3 commit 08d1e63
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sound/usb/usbmixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 |=
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 08d1e63

Please sign in to comment.