Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp285039pxb; Mon, 2 Nov 2020 22:26:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwuFrJ61Vw1v2cFiVWYpT1laOpicSDrjbUQ2sfAQnOWKQkWJ2VILj3ZmBemsAtUqI6eP+SB X-Received: by 2002:a17:906:7797:: with SMTP id s23mr17966027ejm.312.1604384813674; Mon, 02 Nov 2020 22:26:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604384813; cv=none; d=google.com; s=arc-20160816; b=hJGVJIU1jOprPk4Xuo8OSWsQDTtRpKoFOmvVDxTmE+cdsr6o8v6czwqN8J+Y2Dbx5c YfLz96Prc2+N1nOA+RKYmAPBuRbCdkQ7nHR9xkpLYdwf6eSgF/lpU1RlLG1d2pllcZHk WSbXli7qBM16fy4hWF7li8UTASx8ccY7M6nNrpQ2+Chl8Rlh/qp2Bq2KRsU2KQDXSynt aCGwzJIlsXDfWDvNSSb3wPVPRZEaSL5ef7jLvMpwBD1ci2PhDat3/sHnhdqgdsLTpreY bMUGuCL7QSpYb2Y3eqpadBXqu4J9mszMvNpibpyEkj5+2LSpYvCEjWS+dWWsSd5XQN6L lhwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr; bh=g6MhfEQqSLRS1f3XG8BNEUUaULnRg2BbliwbU9RMams=; b=0l9pkj7F3AHxrrHcukuaw02UQw6+5OoJdhaoOvyIVfoDRTJ7OmJhUHfcaDt1UiITXh U8De8Mk6KGI0gwoBC3EthjIeIj/7r9EhkMTFHY2mAVWpf0vfNOkhD5rC1HryZAFQoTeF gszewsRIumNMNPmWKH9D+uR21F4x5rtpGJkg2336zlN7U+LfJRfHC4tQY/ZkRxqqoVfE C/klT4GwwXZwjs85Hm/kEMFSznwvnQGgTb/9z+hTrZWSiACOcI+A4T6xIkG4i9leQkRt qMb/h4pVIJLE0z+UIcXnM3SjdVa9Hm598OFuxxWQklq3hr4NFwoLUd4pgYW8DjTzeW2l x84w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y2si5305439edp.10.2020.11.02.22.26.31; Mon, 02 Nov 2020 22:26:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727474AbgKCGYu (ORCPT + 99 others); Tue, 3 Nov 2020 01:24:50 -0500 Received: from labrats.qualcomm.com ([199.106.110.90]:20045 "EHLO labrats.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725988AbgKCGYu (ORCPT ); Tue, 3 Nov 2020 01:24:50 -0500 IronPort-SDR: tm9WZLWZnji4s6uVJx5CRrXJDcOHRFhIr4cdBUbQsFcvY6G0ChSme/CtCOR0/C2lPOtMM7KIeD n0LZsv61nVREaxyChqVJEC5LzPpBdjbX3bEbNy6QuAIPbtDQ+29qLYC+senLqhrUUNj/llK1pF zLNb30L0+vT2GhT0mQuiFjUDpUBHg13iwo4kP9LTxbalHROZRfVZFm1A+fEXJVnqIZmdnLE9V2 TZPOXyUks/Qwo5fhUY9lfMR/CJDnbl8IrEiUWxPFuco4VyicR0xOFdjmdYA92FLFz+RvQna6Sf CXQ= X-IronPort-AV: E=Sophos;i="5.77,447,1596524400"; d="scan'208";a="47412255" Received: from unknown (HELO ironmsg02-sd.qualcomm.com) ([10.53.140.142]) by labrats.qualcomm.com with ESMTP; 02 Nov 2020 22:24:49 -0800 X-QCInternal: smtphost Received: from wsp769891wss.qualcomm.com (HELO stor-presley.qualcomm.com) ([192.168.140.85]) by ironmsg02-sd.qualcomm.com with ESMTP; 02 Nov 2020 22:24:48 -0800 Received: by stor-presley.qualcomm.com (Postfix, from userid 359480) id 8229F217C9; Mon, 2 Nov 2020 22:24:48 -0800 (PST) From: Can Guo To: asutoshd@codeaurora.org, nguyenb@codeaurora.org, hongwus@codeaurora.org, rnayak@codeaurora.org, 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 v1 1/2] scsi: ufs: Fix unbalanced scsi_block_reqs_cnt caused by ufshcd_hold() Date: Mon, 2 Nov 2020 22:24:39 -0800 Message-Id: <1604384682-15837-2-git-send-email-cang@codeaurora.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1604384682-15837-1-git-send-email-cang@codeaurora.org> References: <1604384682-15837-1-git-send-email-cang@codeaurora.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Reviewed-by: Hongwu Su --- 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 847f355..efa7d86 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1634,12 +1634,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. -- Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project.