From patchwork Sat Jul 18 04:13:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Can Guo X-Patchwork-Id: 11671567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5732713B6 for ; Sat, 18 Jul 2020 04:13:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 408132083E for ; Sat, 18 Jul 2020 04:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726087AbgGRENY (ORCPT ); Sat, 18 Jul 2020 00:13:24 -0400 Received: from labrats.qualcomm.com ([199.106.110.90]:38944 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725763AbgGRENY (ORCPT ); Sat, 18 Jul 2020 00:13:24 -0400 IronPort-SDR: qUTFuhNRZj84fLLA3LVw5IQFRyjDdZH8LWq1yILR+s7hHAOR7fBTWyJ4r0pUFsyuu1NsEzN2y3 L5XIaItW1WGJ19+K+k6qh07DdyYLenuSQUrFLN4CvbXmPsI5VRQZ9pMk6QzD7vRUMzSU+J+zmn u+fp9AYxPUiHr7ZGbBPHw+H02ipzR3KbVr4eXwoQL2XHrnlSBqKZuZYkZsl4S5N2Y3D5ZGs7VY f4UIsEErv+b2DIgbsOtQ3d/8KxbSipiLuGVAkSkQqlh7/qEiRGuLwf021/1XsV1zYas2FCB9OK iqY= X-IronPort-AV: E=Sophos;i="5.75,365,1589266800"; d="scan'208";a="47222743" Received: from unknown (HELO ironmsg03-sd.qualcomm.com) ([10.53.140.143]) by labrats.qualcomm.com with ESMTP; 17 Jul 2020 21:13:24 -0700 Received: from pacamara-linux.qualcomm.com ([192.168.140.135]) by ironmsg03-sd.qualcomm.com with ESMTP; 17 Jul 2020 21:13:22 -0700 Received: by pacamara-linux.qualcomm.com (Postfix, from userid 359480) id A631C22D61; Fri, 17 Jul 2020 21:13:22 -0700 (PDT) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, sh425.lee@samsung.com, linux-scsi@vger.kernel.org, kernel-team@android.com, saravanak@google.com, salyzyn@google.com, cang@codeaurora.org Cc: Alim Akhtar , Avri Altman , "James E.J. Bottomley" , "Martin K. Petersen" , Stanley Chu , Bean Huo , Bart Van Assche , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3 2/4] scsi: ufs: Fix imbalanced scsi_block_reqs_cnt caused by ufshcd_hold() Date: Fri, 17 Jul 2020 21:13:02 -0700 Message-Id: <1595045585-16402-3-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1595045585-16402-1-git-send-email-cang@codeaurora.org> References: <1595045585-16402-1-git-send-email-cang@codeaurora.org> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org The scsi_block_reqs_cnt increased in ufshcd_hold() is supposed to be decreased back in ufshcd_ungate_work() in a paired way. However, if specific ufshcd_hold/release sequences are met, it is possible that scsi_block_reqs_cnt is increased twice but only one ungate work is queued. To make sure scsi_block_reqs_cnt is handled by ufshcd_hold() and ufshcd_ungate_work() in a paired way, increase it only if queue_work() returns true. Signed-off-by: Can Guo --- drivers/scsi/ufs/ufshcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 9ddfd13..4a34f2a 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1611,12 +1611,12 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) */ /* fallthrough */ case CLKS_OFF: - ufshcd_scsi_block_requests(hba); hba->clk_gating.state = REQ_CLKS_ON; trace_ufshcd_clk_gating(dev_name(hba->dev), hba->clk_gating.state); - queue_work(hba->clk_gating.clk_gating_workq, - &hba->clk_gating.ungate_work); + if (queue_work(hba->clk_gating.clk_gating_workq, + &hba->clk_gating.ungate_work)) + ufshcd_scsi_block_requests(hba); /* * fall through to check if we should wait for this * work to be done or not.