Skip to content

Commit 3d0dc53

Browse files
mgrzeschikgregkh
authored andcommitted
usb: gadget: uvc: fix changing interface name via configfs
When setting the function name, it is always truncated by one char since snprintf is always including the null-termination in the len parameter. We use strscpy and fix the size setting to use len + 1 instead. Fixes: 324e4f8 ("usb: gadget: uvc: allow changing interface name via configfs") Signed-off-by: Michael Grzeschik <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6fb9e1d commit 3d0dc53

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/usb/gadget/function/uvc_configfs.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2371,6 +2371,7 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
23712371
const char *page, size_t len) \
23722372
{ \
23732373
struct f_uvc_opts *opts = to_f_uvc_opts(item); \
2374+
int size = min(sizeof(opts->aname), len + 1); \
23742375
int ret = 0; \
23752376
\
23762377
mutex_lock(&opts->lock); \
@@ -2379,8 +2380,9 @@ static ssize_t f_uvc_opts_string_##cname##_store(struct config_item *item,\
23792380
goto end; \
23802381
} \
23812382
\
2382-
ret = snprintf(opts->aname, min(sizeof(opts->aname), len), \
2383-
"%s", page); \
2383+
ret = strscpy(opts->aname, page, size); \
2384+
if (ret == -E2BIG) \
2385+
ret = size - 1; \
23842386
\
23852387
end: \
23862388
mutex_unlock(&opts->lock); \

0 commit comments

Comments
 (0)