diff mbox series

[v1,1/1] ufs: mcq: Fix the sq_head_slot wrap around logic

Message ID f711489c6b95ec410e500543fd24ca9fc0f462cd.1685618737.git.quic_nguyenb@quicinc.com
State Superseded
Headers show
Series [v1,1/1] ufs: mcq: Fix the sq_head_slot wrap around logic | expand

Commit Message

Bao D. Nguyen June 1, 2023, 11:27 a.m. UTC
If the hwq's queue depth is not a multiple of 4s, the
logic used for wrapping around the increase-by-1 sq_head_slot
variable in ufshcd_mcq_sqe_search() will give an incorrect
result because the binary expression of the mask is not
a uniform of all 1s.

Signed-off-by: Bao D. Nguyen <quic_nguyenb@quicinc.com>
---
 drivers/ufs/core/ufs-mcq.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 66ac02e..8e5bc88 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -585,7 +585,6 @@  static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba,
 {
 	struct ufshcd_lrb *lrbp = &hba->lrb[task_tag];
 	struct utp_transfer_req_desc *utrd;
-	u32 mask = hwq->max_entries - 1;
 	__le64  cmd_desc_base_addr;
 	bool ret = false;
 	u64 addr, match;
@@ -610,7 +609,10 @@  static bool ufshcd_mcq_sqe_search(struct ufs_hba *hba,
 			ret = true;
 			goto out;
 		}
-		sq_head_slot = (sq_head_slot + 1) & mask;
+
+		sq_head_slot++;
+		if (sq_head_slot == hwq->max_entries)
+			sq_head_slot = 0;
 	}
 
 out: