summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorIngo Rohloff <ingo.rohloff@lauterbach.com>2024-12-12 16:41:14 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2025-01-17 13:40:55 +0100
commit62aa896683b02979869f2b467a8656f79dfa4d71 (patch)
tree6b43a33b7ea708fedcd0753efe24baf76abdec7a /drivers
parenta8b6a18b9b66cc4c016d63132b59ce5383f7cdd2 (diff)
downloadlinux-62aa896683b02979869f2b467a8656f79dfa4d71.tar.gz
linux-62aa896683b02979869f2b467a8656f79dfa4d71.tar.bz2
linux-62aa896683b02979869f2b467a8656f79dfa4d71.zip
usb: gadget: configfs: Ignore trailing LF for user strings to cdev
commit 9466545720e231fc02acd69b5f4e9138e09a26f6 upstream. 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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/gadget/configfs.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index c82a6a0fba93..29390d573e23 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -827,11 +827,15 @@ static ssize_t gadget_string_s_store(struct config_item *item, const char *page,
{
struct gadget_string *string = to_gadget_string(item);
int size = min(sizeof(string->string), len + 1);
+ ssize_t cpy_len;
if (len > USB_MAX_STRING_LEN)
return -EINVAL;
- return strscpy(string->string, page, size);
+ cpy_len = strscpy(string->string, page, size);
+ if (cpy_len > 0 && string->string[cpy_len - 1] == '\n')
+ string->string[cpy_len - 1] = 0;
+ return len;
}
CONFIGFS_ATTR(gadget_string_, s);