[PATCH] usb: gadget: configfs: unregister gadget only when udc name exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When drop usb config link file, gadget will unregistered,
then if set UDC name to empty, it will return ENODEV.
this change will check udc name to avoid unregister gadget twice
and avoid user space warning message for ENODEV.

Signed-off-by: yuan linyu <cugyly@xxxxxxx>
---
 drivers/usb/gadget/configfs.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index ab9ac48a751a..88a56bf47c0e 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -242,9 +242,6 @@ static int unregister_gadget(struct gadget_info *gi)
 {
 	int ret;
 
-	if (!gi->composite.gadget_driver.udc_name)
-		return -ENODEV;
-
 	ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
 	if (ret)
 		return ret;
@@ -269,9 +266,11 @@ static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
 	mutex_lock(&gi->lock);
 
 	if (!strlen(name)) {
-		ret = unregister_gadget(gi);
-		if (ret)
-			goto err;
+		if (gi->composite.gadget_driver.udc_name) {
+			ret = unregister_gadget(gi);
+			if (ret)
+				goto err;
+		}
 		kfree(name);
 	} else {
 		if (gi->composite.gadget_driver.udc_name) {
@@ -1598,7 +1597,8 @@ void unregister_gadget_item(struct config_item *item)
 	struct gadget_info *gi = to_gadget_info(item);
 
 	mutex_lock(&gi->lock);
-	unregister_gadget(gi);
+	if (gi->composite.gadget_driver.udc_name)
+		unregister_gadget(gi);
 	mutex_unlock(&gi->lock);
 }
 EXPORT_SYMBOL_GPL(unregister_gadget_item);
-- 
2.17.1





[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux