From ae024ed4f72fc3b2374c4180860630b644197d44 Mon Sep 17 00:00:00 2001 From: Jack Pham Date: Wed, 24 May 2017 18:41:53 -0700 Subject: [PATCH] usb: pd: Rerun usbpd_sm if RX queue is not empty Upon receiving a PD message the state machine is queued to act on it. However, if another message is received quickly before usbpd_sm is scheduled, it will only process the first message. Add a check if the RX queue is not empty in order to drain the messages properly. Change-Id: Ie9e079a51a5740024c9a1be5ba27b3edacf9b2df Signed-off-by: Jack Pham --- drivers/usb/pd/policy_engine.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/pd/policy_engine.c b/drivers/usb/pd/policy_engine.c index 7d893c5815e2..78dbd0c7d2c3 100644 --- a/drivers/usb/pd/policy_engine.c +++ b/drivers/usb/pd/policy_engine.c @@ -2308,6 +2308,14 @@ static void usbpd_sm(struct work_struct *w) sm_done: kfree(rx_msg); + spin_lock_irqsave(&pd->rx_lock, flags); + ret = list_empty(&pd->rx_q); + spin_unlock_irqrestore(&pd->rx_lock, flags); + + /* requeue if there are any new/pending RX messages */ + if (!ret) + kick_sm(pd, 0); + if (!pd->sm_queued) pm_relax(&pd->dev); }