diff --git a/drivers/usbhost/usbhost_hidkbd.c b/drivers/usbhost/usbhost_hidkbd.c index fe1b898426..98ca7b83da 100644 --- a/drivers/usbhost/usbhost_hidkbd.c +++ b/drivers/usbhost/usbhost_hidkbd.c @@ -800,11 +800,12 @@ static void usbhost_destroy(FAR void *arg) DRVR_DISCONNECT(hport->drvr); - /* And free the class instance. Hmmm.. this may execute on the worker - * thread and the work structure is part of what is getting freed. That - * should be okay because once the work contained is removed from the - * queue, it should not longer be accessed by the worker thread. - */ + /* Free the function address assigned to this device */ + + usbhost_devaddr_destroy(hport, hport->funcaddr); + hport->funcaddr = 0; + + /* And free the class instance. */ usbhost_freeclass(priv); } @@ -1981,10 +1982,8 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass, static int usbhost_disconnected(struct usbhost_class_s *usbclass) { FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)usbclass; - FAR struct usbhost_hubport_s *hport; - DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL); - hport = priv->usbclass.hport; + DEBUGASSERT(priv != NULL); /* Set an indication to any users of the keyboard device that the device * is no longer available. @@ -2033,10 +2032,6 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) (void)work_queue(HPWORK, &priv->work, usbhost_destroy, priv, 0); } - /* Free the function address assigned to this device */ - - usbhost_devaddr_destroy(hport, hport->funcaddr); - hport->funcaddr = 0; return OK; } diff --git a/drivers/usbhost/usbhost_hidmouse.c b/drivers/usbhost/usbhost_hidmouse.c index 41b16a2546..423a4db375 100644 --- a/drivers/usbhost/usbhost_hidmouse.c +++ b/drivers/usbhost/usbhost_hidmouse.c @@ -656,11 +656,12 @@ static void usbhost_destroy(FAR void *arg) DRVR_DISCONNECT(hport->drvr); - /* And free the class instance. Hmmm.. this may execute on the worker - * thread and the work structure is part of what is getting freed. That - * should be okay because once the work contained is removed from the - * queue, it should not longer be accessed by the worker thread. - */ + /* Free the function address assigned to this device */ + + usbhost_devaddr_destroy(hport, hport->funcaddr); + hport->funcaddr = 0; + + /* And free the class instance. */ usbhost_freeclass(priv); } @@ -2047,11 +2048,9 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass, static int usbhost_disconnected(struct usbhost_class_s *usbclass) { FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)usbclass; - FAR struct usbhost_hubport_s *hport; int i; - DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL); - hport = priv->usbclass.hport; + DEBUGASSERT(priv != NULL); /* Set an indication to any users of the mouse device that the device * is no longer available. @@ -2099,10 +2098,6 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) (void)work_queue(HPWORK, &priv->work, usbhost_destroy, priv, 0); } - /* Free the function address assigned to this device */ - - usbhost_devaddr_destroy(hport, hport->funcaddr); - hport->funcaddr = 0; return OK; } diff --git a/drivers/usbhost/usbhost_storage.c b/drivers/usbhost/usbhost_storage.c index bfe2f53a3c..a5d1f61008 100644 --- a/drivers/usbhost/usbhost_storage.c +++ b/drivers/usbhost/usbhost_storage.c @@ -954,11 +954,12 @@ static void usbhost_destroy(FAR void *arg) DRVR_DISCONNECT(hport->drvr); - /* And free the class instance. Hmmm.. this may execute on the worker - * thread and the work structure is part of what is getting freed. That - * should be okay because once the work contained is removed from the - * queue, it should not longer be accessed by the worker thread. - */ + /* Free the function address assigned to this device */ + + usbhost_devaddr_destroy(hport, hport->funcaddr); + hport->funcaddr = 0; + + /* And free the class instance. */ usbhost_freeclass(priv); } @@ -1810,11 +1811,9 @@ static int usbhost_connect(FAR struct usbhost_class_s *usbclass, static int usbhost_disconnected(struct usbhost_class_s *usbclass) { FAR struct usbhost_state_s *priv = (FAR struct usbhost_state_s *)usbclass; - FAR struct usbhost_hubport_s *hport; irqstate_t flags; - DEBUGASSERT(priv != NULL && priv->usbclass.hport != NULL); - hport = priv->usbclass.hport; + DEBUGASSERT(priv != NULL); /* Set an indication to any users of the mass storage device that the device * is no longer available. @@ -1854,11 +1853,6 @@ static int usbhost_disconnected(struct usbhost_class_s *usbclass) } irqrestore(flags); - - /* Free the function address assigned to this device */ - - usbhost_devaddr_destroy(hport, hport->funcaddr); - hport->funcaddr = 0; return OK; }