Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: configfs: Ignore trailing LF for user strings to cdev

Since commit c033563220e0f7a8
("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: c033563220e0 ("usb: gadget: configfs: Attach arbitrary strings to cdev")
Cc: stable <stable@kernel.org>
Signed-off-by: Ingo Rohloff <ingo.rohloff@lauterbach.com>
Link: https://lore.kernel.org/r/20241212154114.29295-1-ingo.rohloff@lauterbach.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ingo Rohloff and committed by
Greg Kroah-Hartman
94665457 7a3d76a0

+5 -1
+5 -1
drivers/usb/gadget/configfs.c
··· 827 827 { 828 828 struct gadget_string *string = to_gadget_string(item); 829 829 int size = min(sizeof(string->string), len + 1); 830 + ssize_t cpy_len; 830 831 831 832 if (len > USB_MAX_STRING_LEN) 832 833 return -EINVAL; 833 834 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; 835 839 } 836 840 CONFIGFS_ATTR(gadget_string_, s); 837 841