@@ -1052,6 +1052,45 @@ void usb_udc_vbus_handler(struct usb_gadget *gadget, bool status)
}
EXPORT_SYMBOL_GPL(usb_udc_vbus_handler);
+void usb_gadget_udc_disconnect(struct usb_gadget *gadget)
+{
+ struct usb_udc *udc = gadget->udc;
+
+ if (udc && udc->driver && udc->driver->disconnect)
+ udc->driver->disconnect(gadget);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_udc_disconnect);
+
+void usb_gadget_udc_suspend(struct usb_gadget *gadget)
+{
+ struct usb_udc *udc = gadget->udc;
+
+ if (udc && udc->driver && udc->driver->suspend)
+ udc->driver->suspend(gadget);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_udc_suspend);
+
+void usb_gadget_udc_resume(struct usb_gadget *gadget)
+{
+ struct usb_udc *udc = gadget->udc;
+
+ if (udc && udc->driver && udc->driver->resume)
+ udc->driver->resume(gadget);
+}
+EXPORT_SYMBOL_GPL(usb_gadget_udc_resume);
+
+int usb_gadget_udc_setup(struct usb_gadget *gadget,
+ const struct usb_ctrlrequest *ctrl)
+{
+ struct usb_udc *udc = gadget->udc;
+
+ if (udc && udc->driver)
+ return udc->driver->setup(gadget, ctrl);
+
+ return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(usb_gadget_udc_setup);
+
/**
* usb_gadget_udc_reset - notifies the udc core that bus reset occurs
* @gadget: The gadget which bus reset occurs
@@ -1064,7 +1103,13 @@ EXPORT_SYMBOL_GPL(usb_udc_vbus_handler);
void usb_gadget_udc_reset(struct usb_gadget *gadget,
struct usb_gadget_driver *driver)
{
- driver->reset(gadget);
+ struct usb_udc *udc = gadget->udc;
+
+ if (driver)
+ driver->reset(gadget);
+ else if (udc && udc->driver)
+ udc->driver->reset(gadget);
+
usb_gadget_set_state(gadget, USB_STATE_DEFAULT);
}
EXPORT_SYMBOL_GPL(usb_gadget_udc_reset);
@@ -881,6 +881,12 @@ extern void usb_gadget_set_state(struct usb_gadget *gadget,
/*-------------------------------------------------------------------------*/
+extern void usb_gadget_udc_disconnect(struct usb_gadget *gadget);
+extern void usb_gadget_udc_suspend(struct usb_gadget *gadget);
+extern void usb_gadget_udc_resume(struct usb_gadget *gadget);
+extern int usb_gadget_udc_setup(struct usb_gadget *gadget,
+ const struct usb_ctrlrequest *ctrl);
+
/* utility to tell udc core that the bus reset occurs */
extern void usb_gadget_udc_reset(struct usb_gadget *gadget,
struct usb_gadget_driver *driver);
currently most gadget driver have a pointer to save struct usb_gadget_driver from upper layer, it allow upper layer set and unset of the pointer. there is race that upper layer unset the pointer first, but gadget driver use the pointer later, and it cause system crash due to NULL pointer access. Signed-off-by: Linyu Yuan <linyyuan@codeaurora.org> --- drivers/usb/gadget/udc/core.c | 47 ++++++++++++++++++++++++++++++++++- include/linux/usb/gadget.h | 6 +++++ 2 files changed, 52 insertions(+), 1 deletion(-)