Skip to content

Commit ca2d3d8

Browse files
trace32mehmetb0
authored andcommitted
usb: gadget: configfs: Ignore trailing LF for user strings to cdev
BugLink: https://bugs.launchpad.net/bugs/2106770 commit 9466545 upstream. 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 <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> Signed-off-by: Manuel Diewald <manuel.diewald@canonical.com> Signed-off-by: Mehmet Basaran <mehmet.basaran@canonical.com>
1 parent b217d35 commit ca2d3d8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/usb/gadget/configfs.c

Lines changed: 5 additions & 1 deletion
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)