Skip to content

Commit e8afdfd

Browse files
committed
ALSA: usb-audio: Convert remaining strlcpy() to strscpy()
USB-audio driver still contains two calls of strlcpy() because the return size is evaluated. Basically it just checks whether the string is copied or not, but since strcpy() may return a negative error code, we should check the negative value and treat as filled. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 75b1a8f commit e8afdfd

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

sound/usb/mixer.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,14 @@ find_map(const struct usbmix_name_map *p, int unitid, int control)
115115
static int
116116
check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen)
117117
{
118+
int len;
119+
118120
if (!p || !p->name)
119121
return 0;
120122

121123
buflen--;
122-
return strlcpy(buf, p->name, buflen);
124+
len = strscpy(buf, p->name, buflen);
125+
return len < 0 ? buflen : len;
123126
}
124127

125128
/* ignore the error value if ignore_ctl_error flag is set */
@@ -151,12 +154,15 @@ static int check_mapped_selector_name(struct mixer_build *state, int unitid,
151154
int index, char *buf, int buflen)
152155
{
153156
const struct usbmix_selector_map *p;
157+
int len;
154158

155159
if (!state->selector_map)
156160
return 0;
157161
for (p = state->selector_map; p->id; p++) {
158-
if (p->id == unitid && index < p->count)
159-
return strlcpy(buf, p->names[index], buflen);
162+
if (p->id == unitid && index < p->count) {
163+
len = strscpy(buf, p->names[index], buflen);
164+
return len < 0 ? buflen : len;
165+
}
160166
}
161167
return 0;
162168
}

0 commit comments

Comments
 (0)