Skip to content

Commit e60284b

Browse files
johnkeepinggregkh
authored andcommitted
usb: gadget: f_uac2: fix non-newline-terminated function name
Most writes to configfs handle an optional newline, but do not require it. By using the number of bytes written as the limit for scnprintf() it is guaranteed that the final character in the buffer will be overwritten. This is expected if it is a newline but is undesirable when a string is written "as-is" (as libusbgx does, for example). Update the store function to strip an optional newline, matching the behaviour of usb_string_copy(). Signed-off-by: John Keeping <jkeeping@inmusicbrands.com> Link: https://lore.kernel.org/r/20240708142553.3995022-1-jkeeping@inmusicbrands.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 4920d37 commit e60284b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

drivers/usb/gadget/function/f_uac2.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,7 +2063,10 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
20632063
goto end; \
20642064
} \
20652065
\
2066-
ret = scnprintf(opts->name, min(sizeof(opts->name), len), \
2066+
if (len && page[len - 1] == '\n') \
2067+
len--; \
2068+
\
2069+
ret = scnprintf(opts->name, min(sizeof(opts->name), len + 1), \
20672070
"%s", page); \
20682071
\
20692072
end: \

0 commit comments

Comments
 (0)