@@ -393,7 +393,7 @@ int usb_function_deactivate(struct usb_function *function)
spin_lock_irqsave(&cdev->lock, flags);
- if (cdev->deactivations == 0) {
+ if (cdev->deactivations == 0 && cdev->gadget) {
spin_unlock_irqrestore(&cdev->lock, flags);
status = usb_gadget_deactivate(cdev->gadget);
spin_lock_irqsave(&cdev->lock, flags);
@@ -428,7 +428,7 @@ int usb_function_activate(struct usb_function *function)
status = -EINVAL;
else {
cdev->deactivations--;
- if (cdev->deactivations == 0) {
+ if (cdev->deactivations == 0 && cdev->gadget) {
spin_unlock_irqrestore(&cdev->lock, flags);
status = usb_gadget_activate(cdev->gadget);
spin_lock_irqsave(&cdev->lock, flags);
@@ -756,6 +756,9 @@ int usb_gadget_deactivate(struct usb_gadget *gadget)
{
int ret = 0;
+ if (!gadget)
+ return ret;
+
if (gadget->deactivated)
goto out;
It is possible that the configfs gadget layer will be calling the unbind functions of all gadget functions on gadget_dev_desc_UDC_store and cleaned up the cdev structures pointer to the gadget. This will not prevent the usage of the usb_function_de/activate functions. f_obex and f_uvc are the candidates to still call the functions with no valid gadget set. This patch prevents the usage of the gadget if it was already unset. Signed-off-by: Michael Grzeschik <m.grzeschik@pengutronix.de> --- v2: - no changes drivers/usb/gadget/composite.c | 4 ++-- drivers/usb/gadget/udc/core.c | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-)