diff mbox series

USB: gadget: Fix a configfs return code

Message ID YCqZ3P53yyIg5cn7@mwanda
State New
Headers show
Series USB: gadget: Fix a configfs return code | expand

Commit Message

Dan Carpenter Feb. 15, 2021, 3:57 p.m. UTC
If the string is invalid, this should return -EINVAL instead of 0.

Fixes: 73517cf49bd4 ("usb: gadget: add RNDIS configfs options for class/subclass/protocol")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/usb/gadget/function/u_ether_configfs.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Comments

Lorenzo Colitti Feb. 16, 2021, 1:23 a.m. UTC | #1
On Tue, Feb 16, 2021 at 12:57 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>         {                                                               \

>                 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item);  \

> -               int ret;                                                \

> +               int ret = -EINVAL;                                      \

>                 u8 val;                                                 \

>                                                                         \

>                 mutex_lock(&opts->lock);                                \

> -               ret = sscanf(page, "%02hhx", &val);                     \

> -               if (ret > 0) {                                          \

> +               if (sscanf(page, "%02hhx", &val) > 0) {                 \

>                         opts->_n_ = val;                                \

>                         ret = len;                                      \

>                 }                                                       \


Acked-by: Lorenzo Colitti <lorenzo@google.com>
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h
index 3dfb460908fa..f558c3139ebe 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -182,12 +182,11 @@  out:									\
 						size_t len)		\
 	{								\
 		struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item);	\
-		int ret;						\
+		int ret = -EINVAL;					\
 		u8 val;							\
 									\
 		mutex_lock(&opts->lock);				\
-		ret = sscanf(page, "%02hhx", &val);			\
-		if (ret > 0) {						\
+		if (sscanf(page, "%02hhx", &val) > 0) {			\
 			opts->_n_ = val;				\
 			ret = len;					\
 		}							\