MLK-11183 usb: chipidea: otg: complete state machine before cancel hrtimer
authorLi Jun <jun.li@freescale.com>
Thu, 2 Jul 2015 00:13:39 +0000 (08:13 +0800)
committerNitin Garg <nitin.garg@nxp.com>
Mon, 19 Mar 2018 19:47:17 +0000 (14:47 -0500)
When do usb driver module load and unload loop test for A-device, the
hrtimer may be cancelled during otg state machine running, so after
the hrtimer is cancelled, the otg state machine may start it again by
adding a new timer, this will cause the hrtimer will be active after
its function memory is freed by module unload. This patch is to fix it
by trying to hold the fsm mutex lock before setting otg state to be
undefined, then otg hrtimer will be cancelled after current otg fsm
transition completes, and no new timer will be added.

Signed-off-by: Li Jun <jun.li@freescale.com>
(cherry picked from commit 8c3ab4f22bc34675aeb8f9c62e69b450a179be0f)
(cherry picked from commit 95c8590c5232eeb9d054ac7504455a90a133f05a)

drivers/usb/chipidea/otg_fsm.c

index 72a565b..b6a8f7f 100644 (file)
@@ -936,6 +936,10 @@ void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci)
 {
        enum otg_fsm_timer i;
 
+       mutex_lock(&ci->fsm.lock);
+       ci->fsm.otg->state = OTG_STATE_UNDEFINED;
+       mutex_unlock(&ci->fsm.lock);
+
        for (i = 0; i < NUM_OTG_FSM_TIMERS; i++)
                otg_del_timer(&ci->fsm, i);
 
@@ -946,7 +950,6 @@ void ci_hdrc_otg_fsm_remove(struct ci_hdrc *ci)
                otg_drv_vbus(&ci->fsm, 0);
 
        sysfs_remove_group(&ci->dev->kobj, &inputs_attr_group);
-       ci->fsm.otg->state = OTG_STATE_UNDEFINED;
 }
 
 /* Restart OTG fsm if resume from power lost */