usb: configfs: skip unregister gadget in secure
authorYonghua Yan <yanyh2@motorola.com>
Tue, 25 Jun 2019 06:04:04 +0000 (14:04 +0800)
committerlingsen1 <lingsen1@lenovo.com>
Sun, 7 Feb 2021 09:37:03 +0000 (17:37 +0800)
There will be gadget driver unregister twice in USB secure
when try to set the UDC to none from userspace, which will cause
kernel panic in 4.9 kernel version, as there is a feature
about pending gadget driver list being added in this version.

As a solution, make sure gadget driver unregister or probe only
once over secure mode entry or usb configure from userspace.

Kernel BUG at ffffff8093067140 [verbose debug info unavailable]
Internal error: Accessing user space memory outside uaccess.h

Change-Id: I89f03afbf9716a95aae37e354cc0cb293b2ea090
Signed-off-by: a17671 <a17671@motorola.com>
Reviewed-on: https://gerrit.mot.com/1376192
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Tested-by: Jira Key
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Submit-Approved: Jira Key

drivers/usb/gadget/configfs.c

index beb9c932d4952a6aaa7c495944c82931558d7aa0..cd7cdaa3cad0ecf2fa1ebf4c03c94c6ff353405b 100755 (executable)
@@ -284,6 +284,12 @@ static int unregister_gadget(struct gadget_info *gi)
        if (!gi->composite.gadget_driver.udc_name)
                return -ENODEV;
 
+       if (gi->secure) {
+               kfree(gi->composite.gadget_driver.udc_name);
+               gi->composite.gadget_driver.udc_name = NULL;
+               return 0;
+       }
+
        ret = usb_gadget_unregister_driver(&gi->composite.gadget_driver);
        if (ret)
                return ret;