Skip to contentSkip to conversation

usb: gadget: configfs: Fix set but not used variable warning

PATCH In review Daniel Scally 2 participants 4 messages Feb 9, 2023 – Feb 10, 2023 USB

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb: gadget: configfs: Fix set but not used variable warning

Fix a -Wunused-but-set-variable warning in gadget_string_s_store()

Fixes 15a7cf8caabe ("usb: gadget: configfs: Support arbitrary string descriptors")
---
 drivers/usb/gadget/configfs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/usb/gadget/configfs.c +1 -3
index 06a0b73e0546..b9f1136aa0a2 100644
@@ -821,13 +821,11 @@ 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);
-	int ret;
 
 	if (len > USB_MAX_STRING_LEN)
 		return -EINVAL;
 
-	ret = strscpy(string->string, page, size);
-	return len;
+	return strscpy(string->string, page, size);
 }
 CONFIGFS_ATTR(gadget_string_, s);
 
Signature · 1 line
2.34.1
#1 lore raw
Quoted 1 line · Daniel Scally

Fix a -Wunused-but-set-variable warning in gadget_string_s_store()

A side comment below.

...

drivers/usb/gadget/configfs.c static ssize_t gadget_string_s_store(struct config_item *item, const char *page, · line 828

Quoted 6 lines
drivers/usb/gadget/configfs.c +1 -2
 	if (len > USB_MAX_STRING_LEN)
 		return -EINVAL;
 
-	ret = strscpy(string->string, page, size);
-	return len;
+	return strscpy(string->string, page, size);

Do you need above check with strscpy()? You may supply the maximum length and negative error code from the strscpy() will indicate the cut.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw

Hi Andy

Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Daniel Scally

Fix a -Wunused-but-set-variable warning in gadget_string_s_store()

A side comment below.

...

Quoted 9 lines

drivers/usb/gadget/configfs.c static ssize_t gadget_string_s_store(struct config_item *item, const char *page, · line 828

Quoted 6 lines

if (len > USB_MAX_STRING_LEN)
return -EINVAL;

drivers/usb/gadget/configfs.c +1 -2
-	ret = strscpy(string->string, page, size);
-	return len;
+	return strscpy(string->string, page, size);

Do you need above check with strscpy()? You may supply the maximum length and negative error code from the strscpy() will indicate the cut.

It would still copy the truncated string in that case though, correct? Seems cleaner to me to just fail and leave the string as-is, but I don't particularly mind either way.

#3 lore raw
Quoted 4 lines · Dan Scally
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Daniel Scally

Fix a -Wunused-but-set-variable warning in gadget_string_s_store()

A side comment below.

...

Quoted 11 lines
Quoted 8 lines

drivers/usb/gadget/configfs.c static ssize_t gadget_string_s_store(struct config_item *item, const char *page, · line 828

Quoted 5 lines

if (len > USB_MAX_STRING_LEN)
return -EINVAL;

drivers/usb/gadget/configfs.c +1 -2
-	ret = strscpy(string->string, page, size);
-	return len;
+	return strscpy(string->string, page, size);

Do you need above check with strscpy()? You may supply the maximum length and negative error code from the strscpy() will indicate the cut.

It would still copy the truncated string in that case though, correct? Seems cleaner to me to just fail and leave the string as-is, but I don't particularly mind either way.

Good point. Yes, depending on the nature of the data we copy it (my proposal) may or may not be a good idea.

Signature · 2 lines
With Best Regards,
Andy Shevchenko