Skip to content

Commit 9499327

Browse files
Kevin Groeneveldgregkh
authored andcommitted
usb: gadget: f_uac2: fix return value for UAC2_ATTRIBUTE_STRING store
The configfs store callback should return the number of bytes consumed not the total number of bytes we actually stored. These could differ if for example the passed in string had a newline we did not store. If the returned value does not match the number of bytes written the writer might assume a failure or keep trying to write the remaining bytes. For example the following command will hang trying to write the final newline over and over again (tested on bash 2.05b): echo foo > function_name Fixes: 993a44f ("usb: gadget: f_uac2: allow changing interface name via configfs") Cc: stable <[email protected]> Signed-off-by: Kevin Groeneveld <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 705e3ce commit 9499327

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/usb/gadget/function/f_uac2.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
20612061
const char *page, size_t len) \
20622062
{ \
20632063
struct f_uac2_opts *opts = to_f_uac2_opts(item); \
2064-
int ret = 0; \
2064+
int ret = len; \
20652065
\
20662066
mutex_lock(&opts->lock); \
20672067
if (opts->refcnt) { \
@@ -2072,8 +2072,8 @@ static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
20722072
if (len && page[len - 1] == '\n') \
20732073
len--; \
20742074
\
2075-
ret = scnprintf(opts->name, min(sizeof(opts->name), len + 1), \
2076-
"%s", page); \
2075+
scnprintf(opts->name, min(sizeof(opts->name), len + 1), \
2076+
"%s", page); \
20772077
\
20782078
end: \
20792079
mutex_unlock(&opts->lock); \

0 commit comments

Comments
 (0)