Skip to contentSkip to conversation

USB: gadget: Fix return of -EBUSY

PATCH In review Colin Ian King 2 participants 2 messages May 4, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 USB: gadget: Fix return of -EBUSY

Currently when driver->match_existing_only is true, the error return is set to -EBUSY however ret is then set to 0 at the end of the if/else statement. I believe the ret = 0 statement should be set in the else part of the if statement and not at the end to ensure -EBUSY is being returned correctly.

Detected by clang scan:
drivers/usb/gadget/udc/core.c:1558:4: warning: Value stored to 'ret' is never read [deadcode.DeadStores]

Fixes fc274c1e9973 ("USB: gadget: Add a new bus for gadgets")
---
 drivers/usb/gadget/udc/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/core.c +1 -1
index 61790592b2c8..3281d8a3dae7 100644
@@ -1559,8 +1559,8 @@ int usb_gadget_register_driver_owner(struct usb_gadget_driver *driver,
 		} else {
 			pr_info("%s: couldn't find an available UDC\n",
 					driver->function);
+			ret = 0;
 		}
-		ret = 0;
 	}
 	mutex_unlock(&udc_lock);
 
Signature · 1 line
2.35.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Colin Ian King

Currently when driver->match_existing_only is true, the error return is set to -EBUSY however ret is then set to 0 at the end of the if/else statement. I believe the ret = 0 statement should be set in the else part of the if statement and not at the end to ensure -EBUSY is being returned correctly.

Quoted 7 lines

Detected by clang scan:
drivers/usb/gadget/udc/core.c:1558:4: warning: Value stored to 'ret' is never read [deadcode.DeadStores]

Fixes fc274c1e9973 ("USB: gadget: Add a new bus for gadgets")

---

Don't know how I missed that. Thanks for fixing it.

In fact, since it's guaranteed that ret is already 0 before the driver->match_existing_only test, you could eliminate the assignment entirely. But moving it into the second branch of the "if" statement is probably more clear.

Alan Stern

Quoted 20 lines
 drivers/usb/gadget/udc/core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/gadget/udc/core.c +1 -1
index 61790592b2c8..3281d8a3dae7 100644
@@ -1559,8 +1559,8 @@ int usb_gadget_register_driver_owner(struct usb_gadget_driver *driver,
 		} else {
 			pr_info("%s: couldn't find an available UDC\n",
 					driver->function);
+			ret = 0;
 		}
-		ret = 0;
 	}
 	mutex_unlock(&udc_lock);
 
Signature · 1 line
2.35.1