From patchwork Tue Jul 28 14:10:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanley Chu X-Patchwork-Id: 11689239 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 5C5C6138C for ; Tue, 28 Jul 2020 14:11:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43D25206F5 for ; Tue, 28 Jul 2020 14:11:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="apE8fI/q" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730144AbgG1OLC (ORCPT ); Tue, 28 Jul 2020 10:11:02 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:7961 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1730057AbgG1OLC (ORCPT ); Tue, 28 Jul 2020 10:11:02 -0400 X-UUID: c254afc30da74d48aec926f2773c279e-20200728 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=suEMosAXJcsVRBqEPCC9fdQP59XGs0hD3Jn+cHeYz6A=; b=apE8fI/qTpyi8svFmT4raknEZ4iQy/Wg/7sBZGW3hjb99/aLJwdS/ev7cadKXgbVgmbfEu2MyH1/UyK3R4eq2HYi9DWEoDAPYkx9U5uPTvvyzikmHgN3MkYdz1SPPPtkWIQwYlG0KqA3jqduKJsOovY5jL+RSIL/DpaI8mWbQQk=; X-UUID: c254afc30da74d48aec926f2773c279e-20200728 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 37312028; Tue, 28 Jul 2020 22:10:57 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs02n1.mediatek.inc (172.21.101.77) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 28 Jul 2020 22:10:53 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 28 Jul 2020 22:10:55 +0800 From: Stanley Chu To: , , , , , CC: , , , , , , , , , , , , , Stanley Chu Subject: [PATCH v1] scsi: ufs: Fix possible infinite loop in ufshcd_hold Date: Tue, 28 Jul 2020 22:10:55 +0800 Message-ID: <20200728141055.22160-1-stanley.chu@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 X-MTK: N Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org In ufshcd_suspend(), after clk-gating is suspended and link is set as Hibern8 state, ufshcd_hold() is still possibly invoked before ufshcd_suspend() returns. For example, MediaTek's suspend vops may issue UIC commands which would call ufshcd_hold() during the command issuing flow. Now if UFSHCD_CAP_HIBERN8_WITH_CLK_GATING capability is enabled, then ufshcd_hold() may enter infinite loops because there is no clk-ungating work is scheduled or pending. In this case, ufshcd_hold() shall just bypass, and keep the link as Hibern8 state. Signed-off-by: Stanley Chu Signed-off-by: Andy Teng --- drivers/scsi/ufs/ufshcd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index 577cc0d7487f..267b02e1afd6 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -1592,7 +1592,11 @@ int ufshcd_hold(struct ufs_hba *hba, bool async) break; } spin_unlock_irqrestore(hba->host->host_lock, flags); - flush_work(&hba->clk_gating.ungate_work); + rc = flush_work(&hba->clk_gating.ungate_work); + if (hba->clk_gating.is_suspended && !rc) { + rc = 0; + goto out; + } spin_lock_irqsave(hba->host->host_lock, flags); goto start; }