Skip to content

Commit 9466545

Browse files
trace32gregkh
authored andcommitted
usb: gadget: configfs: Ignore trailing LF for user strings to cdev
Since commit c033563 ("usb: gadget: configfs: Attach arbitrary strings to cdev") a user can provide extra string descriptors to a USB gadget via configfs. For "manufacturer", "product", "serialnumber", setting the string via configfs ignores a trailing LF. For the arbitrary strings the LF was not ignored. This patch ignores a trailing LF to make this consistent with the existing behavior for "manufacturer", ... string descriptors. Fixes: c033563 ("usb: gadget: configfs: Attach arbitrary strings to cdev") Cc: stable <[email protected]> Signed-off-by: Ingo Rohloff <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 7a3d76a commit 9466545

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Diff for: drivers/usb/gadget/configfs.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -827,11 +827,15 @@ static ssize_t gadget_string_s_store(struct config_item *item, const char *page,
827827
{
828828
struct gadget_string *string = to_gadget_string(item);
829829
int size = min(sizeof(string->string), len + 1);
830+
ssize_t cpy_len;
830831

831832
if (len > USB_MAX_STRING_LEN)
832833
return -EINVAL;
833834

834-
return strscpy(string->string, page, size);
835+
cpy_len = strscpy(string->string, page, size);
836+
if (cpy_len > 0 && string->string[cpy_len - 1] == '\n')
837+
string->string[cpy_len - 1] = 0;
838+
return len;
835839
}
836840
CONFIGFS_ATTR(gadget_string_, s);
837841

0 commit comments

Comments
 (0)