diff options
author | Takashi Iwai <tiwai@suse.de> | 2009-10-02 08:06:08 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2009-10-02 08:06:08 -0400 |
commit | 08d1e635089f41e28fec644a8620a0e8d66b1235 (patch) | |
tree | d56d44b59fb58df714c762296da438e3fbd9fef2 /sound | |
parent | 2f229a31aac86ea6911d70ec4c79196ca711d625 (diff) |
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>
Diffstat (limited to 'sound')
-rw-r--r-- | sound/usb/usbmixer.c | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c index ab5a3ac2ac47..9efcfd08d747 100644 --- a/sound/usb/usbmixer.c +++ b/sound/usb/usbmixer.c | |||
@@ -898,6 +898,11 @@ static struct snd_kcontrol_new usb_feature_unit_ctl = { | |||
898 | * build a feature control | 898 | * build a feature control |
899 | */ | 899 | */ |
900 | 900 | ||
901 | static size_t append_ctl_name(struct snd_kcontrol *kctl, const char *str) | ||
902 | { | ||
903 | return strlcat(kctl->id.name, str, sizeof(kctl->id.name)); | ||
904 | } | ||
905 | |||
901 | static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, | 906 | static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, |
902 | unsigned int ctl_mask, int control, | 907 | unsigned int ctl_mask, int control, |
903 | struct usb_audio_term *iterm, int unitid) | 908 | struct usb_audio_term *iterm, int unitid) |
@@ -978,13 +983,13 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, | |||
978 | */ | 983 | */ |
979 | if (! mapped_name && ! (state->oterm.type >> 16)) { | 984 | if (! mapped_name && ! (state->oterm.type >> 16)) { |
980 | if ((state->oterm.type & 0xff00) == 0x0100) { | 985 | if ((state->oterm.type & 0xff00) == 0x0100) { |
981 | len = strlcat(kctl->id.name, " Capture", sizeof(kctl->id.name)); | 986 | len = append_ctl_name(kctl, " Capture"); |
982 | } else { | 987 | } else { |
983 | len = strlcat(kctl->id.name + len, " Playback", sizeof(kctl->id.name)); | 988 | len = append_ctl_name(kctl, " Playback"); |
984 | } | 989 | } |
985 | } | 990 | } |
986 | strlcat(kctl->id.name + len, control == USB_FEATURE_MUTE ? " Switch" : " Volume", | 991 | append_ctl_name(kctl, control == USB_FEATURE_MUTE ? |
987 | sizeof(kctl->id.name)); | 992 | " Switch" : " Volume"); |
988 | if (control == USB_FEATURE_VOLUME) { | 993 | if (control == USB_FEATURE_VOLUME) { |
989 | kctl->tlv.c = mixer_vol_tlv; | 994 | kctl->tlv.c = mixer_vol_tlv; |
990 | kctl->vd[0].access |= | 995 | kctl->vd[0].access |= |
@@ -1143,7 +1148,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, | |||
1143 | len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); | 1148 | len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); |
1144 | if (! len) | 1149 | if (! len) |
1145 | len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); | 1150 | len = sprintf(kctl->id.name, "Mixer Source %d", in_ch + 1); |
1146 | strlcat(kctl->id.name + len, " Volume", sizeof(kctl->id.name)); | 1151 | append_ctl_name(kctl, " Volume"); |
1147 | 1152 | ||
1148 | snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", | 1153 | snd_printdd(KERN_INFO "[%d] MU [%s] ch = %d, val = %d/%d\n", |
1149 | cval->id, kctl->id.name, cval->channels, cval->min, cval->max); | 1154 | 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 | if (! len) | 1405 | if (! len) |
1401 | strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); | 1406 | strlcpy(kctl->id.name, name, sizeof(kctl->id.name)); |
1402 | } | 1407 | } |
1403 | strlcat(kctl->id.name, " ", sizeof(kctl->id.name)); | 1408 | append_ctl_name(kctl, " "); |
1404 | strlcat(kctl->id.name, valinfo->suffix, sizeof(kctl->id.name)); | 1409 | append_ctl_name(kctl, valinfo->suffix); |
1405 | 1410 | ||
1406 | snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", | 1411 | snd_printdd(KERN_INFO "[%d] PU [%s] ch = %d, val = %d/%d\n", |
1407 | cval->id, kctl->id.name, cval->channels, cval->min, cval->max); | 1412 | 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 | strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); | 1615 | strlcpy(kctl->id.name, "USB", sizeof(kctl->id.name)); |
1611 | 1616 | ||
1612 | if ((state->oterm.type & 0xff00) == 0x0100) | 1617 | if ((state->oterm.type & 0xff00) == 0x0100) |
1613 | strlcat(kctl->id.name, " Capture Source", sizeof(kctl->id.name)); | 1618 | append_ctl_name(kctl, " Capture Source"); |
1614 | else | 1619 | else |
1615 | strlcat(kctl->id.name, " Playback Source", sizeof(kctl->id.name)); | 1620 | append_ctl_name(kctl, " Playback Source"); |
1616 | } | 1621 | } |
1617 | 1622 | ||
1618 | snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", | 1623 | snd_printdd(KERN_INFO "[%d] SU [%s] items = %d\n", |