slimbus: Gracefully handle timeout for a synchronous read
Timed-out transaction is invalidated from the table of
active transactions so that it can be reused later.
This also ensures that stale transaction completion is not called on a
timed-out sync-read caller. This may happen if a synchronous read
fails due to timeout, and read-response is received after timeout.
Signed-off-by: Sagar Dharia <sdharia@codeaurora.org>
diff --git a/drivers/slimbus/slimbus.c b/drivers/slimbus/slimbus.c
index 4bca13f..626bd8d 100644
--- a/drivers/slimbus/slimbus.c
+++ b/drivers/slimbus/slimbus.c
@@ -909,8 +909,22 @@
mc, ec, SLIM_MSG_MT_CORE, rbuf, wbuf, len, mlen,
msg->comp, sbdev->laddr, &tid);
/* sync read */
- if (!ret && !msg->comp)
- wait_for_completion_timeout(&complete, HZ);
+ if (!ret && !msg->comp) {
+ ret = wait_for_completion_timeout(&complete, HZ);
+ if (!ret) {
+ struct slim_msg_txn *txn;
+ dev_err(&ctrl->dev, "slimbus Read timed out");
+ mutex_lock(&ctrl->m_ctrl);
+ txn = ctrl->txnt[tid];
+ /* Invalidate the transaction */
+ ctrl->txnt[tid] = NULL;
+ mutex_unlock(&ctrl->m_ctrl);
+ kfree(txn);
+ ret = -ETIMEDOUT;
+ } else
+ ret = 0;
+ }
+
} else
ret = slim_processtxn(ctrl, SLIM_MSG_DEST_LOGICALADDR, mc, ec,
SLIM_MSG_MT_CORE, rbuf, wbuf, len, mlen,