From patchwork Thu Dec 24 17:20:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11989717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDCDFC433E0 for ; Thu, 24 Dec 2020 17:21:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A6EF922512 for ; Thu, 24 Dec 2020 17:21:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728700AbgLXRVI (ORCPT ); Thu, 24 Dec 2020 12:21:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727144AbgLXRVH (ORCPT ); Thu, 24 Dec 2020 12:21:07 -0500 Received: from mail-ej1-x62f.google.com (mail-ej1-x62f.google.com [IPv6:2a00:1450:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A91EC061757; Thu, 24 Dec 2020 09:20:27 -0800 (PST) Received: by mail-ej1-x62f.google.com with SMTP id b9so4084265ejy.0; Thu, 24 Dec 2020 09:20:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GGGzCG6IsBMm3fKDl4elkBUls6e2qJh6NDI+c/9UOVg=; b=A84eQ8uVK969jiJpPK8vMzc/Lqjy5tRqL3zSTKKnNfLXXRbLO49oKzNcIsl5NvxqkZ /yy2sLywselg8mHHlONdYTQocLy5wRinuSfyYjX7/a+f6Ch1wfXUYGMpjsaLOIBCU187 pnGKVoAYsTZgBo27GPBbhqPe12PdgAVsU6d0V9OTEFpz5k4DKFB2QHukyQcP9Mkk8554 a2y/kvrPoPHSZV4vw0tBXm5vjZXy+uFrGE9NlmovHSgEsyJO5wpvXlZv92tbfgLxeUtO dN/by6puRFDD3UD+xw5DFdNCrcxMbjk3j59b8py6SIAHGvChuk/Yf865Mc4gurCGNLoz qaMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GGGzCG6IsBMm3fKDl4elkBUls6e2qJh6NDI+c/9UOVg=; b=H9h5Zk+UFGMqxiybUN+Xxmx1cvzNbj481zcGg40O/gpH1YuIV829VT1X8MYS6L6K3f MmnRxEswZlbXgMf2J4cBoysijiy0iZMBuG0gGA1Qpxloy35KnyvXDSamBqUb6CWQ5Lis y45PtEpI5FRj+2Hbz1IlZ2M2uK9AqwwU/sAbM7rZnI2ayN6Vzndv3PpPjnkFmm1EHNUH dwrvdNzQTugvd/LefpraRiSWeay/CapTQEqHC4NBx6nE20vGHKz3MRxGgfO9RaLYLIlj EirXirX3/0plPOjWFkRUk2LBVz8b4nHt7d5D6tA1Ze78g0t4rPzAnu7DQOHMX9kpid5l f/1g== X-Gm-Message-State: AOAM533bEyfVzzk/BUXBMAMDQYHoGyPrnfjryntD//9HJ9HMQgwb7Yom AODWHYK+G7ZQws5QFJ6Ancw= X-Google-Smtp-Source: ABdhPJxwfqpAyB2nBZn54mlMWSjbeK9ir7qV1+u+LZm+giSvrDBMjS2wmfYoMIQt+zwAMfeqFTVAhw== X-Received: by 2002:a17:907:105e:: with SMTP id oy30mr28636567ejb.495.1608830425752; Thu, 24 Dec 2020 09:20:25 -0800 (PST) Received: from localhost.localdomain (ip5f5bfce9.dynamic.kabel-deutschland.de. [95.91.252.233]) by smtp.gmail.com with ESMTPSA id m5sm12874446eja.11.2020.12.24.09.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Dec 2020 09:20:25 -0800 (PST) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net Subject: [PATCH v2 1/3] scsi: ufs: Replace sprintf and snprintf with sysfs_emit Date: Thu, 24 Dec 2020 18:20:08 +0100 Message-Id: <20201224172010.10701-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224172010.10701-1-huobean@gmail.com> References: <20201224172010.10701-1-huobean@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo sprintf and snprintf may cause output defect in sysfs content, it is better to use new added sysfs_emit function which knows the size of the temporary buffer. Reviewed-by: Avri Altman Suggested-by: Greg Kroah-Hartman Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs-sysfs.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 08e72b7eef6a..0e1438485133 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -67,7 +67,7 @@ static ssize_t rpm_lvl_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", hba->rpm_lvl); + return sysfs_emit(buf, "%d\n", hba->rpm_lvl); } static ssize_t rpm_lvl_store(struct device *dev, @@ -81,7 +81,7 @@ static ssize_t rpm_target_dev_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( ufs_pm_lvl_states[hba->rpm_lvl].dev_state)); } @@ -90,7 +90,7 @@ static ssize_t rpm_target_link_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( ufs_pm_lvl_states[hba->rpm_lvl].link_state)); } @@ -99,7 +99,7 @@ static ssize_t spm_lvl_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%d\n", hba->spm_lvl); + return sysfs_emit(buf, "%d\n", hba->spm_lvl); } static ssize_t spm_lvl_store(struct device *dev, @@ -113,7 +113,7 @@ static ssize_t spm_target_dev_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( + return sysfs_emit(buf, "%s\n", ufschd_ufs_dev_pwr_mode_to_string( ufs_pm_lvl_states[hba->spm_lvl].dev_state)); } @@ -122,7 +122,7 @@ static ssize_t spm_target_link_state_show(struct device *dev, { struct ufs_hba *hba = dev_get_drvdata(dev); - return sprintf(buf, "%s\n", ufschd_uic_link_state_to_string( + return sysfs_emit(buf, "%s\n", ufschd_uic_link_state_to_string( ufs_pm_lvl_states[hba->spm_lvl].link_state)); } @@ -165,7 +165,7 @@ static ssize_t auto_hibern8_show(struct device *dev, ufshcd_release(hba); pm_runtime_put_sync(hba->dev); - return scnprintf(buf, PAGE_SIZE, "%d\n", ufshcd_ahit_to_us(ahit)); + return sysfs_emit(buf, "%d\n", ufshcd_ahit_to_us(ahit)); } static ssize_t auto_hibern8_store(struct device *dev, @@ -233,18 +233,18 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba, return -EINVAL; switch (param_size) { case 1: - ret = sprintf(sysfs_buf, "0x%02X\n", *desc_buf); + ret = sysfs_emit(sysfs_buf, "0x%02X\n", *desc_buf); break; case 2: - ret = sprintf(sysfs_buf, "0x%04X\n", + ret = sysfs_emit(sysfs_buf, "0x%04X\n", get_unaligned_be16(desc_buf)); break; case 4: - ret = sprintf(sysfs_buf, "0x%08X\n", + ret = sysfs_emit(sysfs_buf, "0x%08X\n", get_unaligned_be32(desc_buf)); break; case 8: - ret = sprintf(sysfs_buf, "0x%016llX\n", + ret = sysfs_emit(sysfs_buf, "0x%016llX\n", get_unaligned_be64(desc_buf)); break; } @@ -609,7 +609,7 @@ static ssize_t _name##_show(struct device *dev, \ SD_ASCII_STD); \ if (ret < 0) \ goto out; \ - ret = snprintf(buf, PAGE_SIZE, "%s\n", desc_buf); \ + ret = sysfs_emit(buf, "%s\n", desc_buf); \ out: \ pm_runtime_put_sync(hba->dev); \ kfree(desc_buf); \ @@ -659,7 +659,7 @@ static ssize_t _name##_show(struct device *dev, \ pm_runtime_put_sync(hba->dev); \ if (ret) \ return -EINVAL; \ - return sprintf(buf, "%s\n", flag ? "true" : "false"); \ + return sysfs_emit(buf, "%s\n", flag ? "true" : "false"); \ } \ static DEVICE_ATTR_RO(_name) @@ -717,7 +717,7 @@ static ssize_t _name##_show(struct device *dev, \ pm_runtime_put_sync(hba->dev); \ if (ret) \ return -EINVAL; \ - return sprintf(buf, "0x%08X\n", value); \ + return sysfs_emit(buf, "0x%08X\n", value); \ } \ static DEVICE_ATTR_RO(_name) @@ -856,7 +856,7 @@ static ssize_t dyn_cap_needed_attribute_show(struct device *dev, pm_runtime_put_sync(hba->dev); if (ret) return -EINVAL; - return sprintf(buf, "0x%08X\n", value); + return sysfs_emit(buf, "0x%08X\n", value); } static DEVICE_ATTR_RO(dyn_cap_needed_attribute); From patchwork Thu Dec 24 17:20:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11989713 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 43777C4332B for ; Thu, 24 Dec 2020 17:21:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 246762333B for ; Thu, 24 Dec 2020 17:21:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728782AbgLXRVJ (ORCPT ); Thu, 24 Dec 2020 12:21:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728757AbgLXRVI (ORCPT ); Thu, 24 Dec 2020 12:21:08 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280BAC0613C1; Thu, 24 Dec 2020 09:20:28 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id g20so4073544ejb.1; Thu, 24 Dec 2020 09:20:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M/LQBu//i4RMgFaViCE8yWcfBThRAvtu9np9/z5UKcA=; b=Ms/eruC8VTv6TU8MVGSXjz7bkMOulkKXj8aW/dBzQM/k391Oj2+5HCt21Deuk89pCk gGQpC+FkIkk0+mHk9yCDec4qpsLnJg1JXekl4qxqaGzjAMNX/XeOHS6dPoCwF9E4P4vJ d6rKtbgkUuexYec+s3lpxG4xuQKPEip79i6JOVheWrhAU6Crx28T2OZ5p92Jrvs/Bn7h e/+kbJkESR0tIXZ4IUjr2Kvn6bMz//axjjkM6XQ1Fv5F//Dl6cXiOeV77J0cFvszqNy3 vBRTpDC4M0i7fOsjFzF3p8FSBCj/Oq+s24yPUiRDKhHiRUAg4AKFeBW/oLlFYQiP8k65 BsVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=M/LQBu//i4RMgFaViCE8yWcfBThRAvtu9np9/z5UKcA=; b=NltxW1FvtvSsFRhqVSNDtdw31PCPaDDsHajjSlgZ0PBvP51eDOUfsvOoOBGQVY2Aw8 w3PsxF5ajT3woVXn7tNB4L0dVu2gYNHm8dnpRFM7g4GqFCkaRyVLkF97aqZEK/htvUbw IurUjYHlQccDWVTImLNXgqXoQFtAUeEehrpQhLRCaWYUlozYGy7xvpPaXJxCAhjXjhG5 2Thqi+j8BkaNG2Ozl1aB5QKGC3U0lhtEHEInImxOZFfoDvUIInJKodPWZb1CaNrrEo+6 QOSo+VjO9kT7jPijpjQ6la+imnvwjXnXeKP/0YrKx7a6WFEJfQ2/4bWpQP9jgfMsC0p+ RTQQ== X-Gm-Message-State: AOAM533DzXXUC1IcMY+CI/g2erQ4TtKGKRvPRWBnq8bbIS8le19+HxlH qLQgh8iV3GSoSqmpm6yZkFw= X-Google-Smtp-Source: ABdhPJzN/gLmuzqyLugtiP/+C7l4ix2b7L87Sg6F/PypGxkJxjWRIHY3iPGhayjhSrMJ+LaMifWMLw== X-Received: by 2002:a17:906:59a:: with SMTP id 26mr28356496ejn.309.1608830426883; Thu, 24 Dec 2020 09:20:26 -0800 (PST) Received: from localhost.localdomain (ip5f5bfce9.dynamic.kabel-deutschland.de. [95.91.252.233]) by smtp.gmail.com with ESMTPSA id m5sm12874446eja.11.2020.12.24.09.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Dec 2020 09:20:26 -0800 (PST) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net Subject: [PATCH v2 2/3] scsi: ufs: Add handling of the return value of pm_runtime_get_sync() Date: Thu, 24 Dec 2020 18:20:09 +0100 Message-Id: <20201224172010.10701-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224172010.10701-1-huobean@gmail.com> References: <20201224172010.10701-1-huobean@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo The race issue may exist between UFS access in UFS sysfs context and UFS shutdown, thus will cause pm_runtime_get_sync() resume failure. Add handling of the return value of pm_runtime_get_sync(). Let it return in case pm_runtime_get_sync() resume failed. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufs-sysfs.c | 38 ++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/ufs/ufs-sysfs.c b/drivers/scsi/ufs/ufs-sysfs.c index 0e1438485133..8e5e36e01bee 100644 --- a/drivers/scsi/ufs/ufs-sysfs.c +++ b/drivers/scsi/ufs/ufs-sysfs.c @@ -154,12 +154,17 @@ static ssize_t auto_hibern8_show(struct device *dev, struct device_attribute *attr, char *buf) { u32 ahit; + int ret; struct ufs_hba *hba = dev_get_drvdata(dev); if (!ufshcd_is_auto_hibern8_supported(hba)) return -EOPNOTSUPP; - pm_runtime_get_sync(hba->dev); + ret = pm_runtime_get_sync(hba->dev); + if (ret < 0) { + pm_runtime_put_noidle(hba->dev); + return ret; + } ufshcd_hold(hba, false); ahit = ufshcd_readl(hba, REG_AUTO_HIBERNATE_IDLE_TIMER); ufshcd_release(hba); @@ -225,7 +230,12 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba, if (param_size > 8) return -EINVAL; - pm_runtime_get_sync(hba->dev); + ret = pm_runtime_get_sync(hba->dev); + if (ret < 0) { + pm_runtime_put_noidle(hba->dev); + return ret; + } + ret = ufshcd_read_desc_param(hba, desc_id, desc_index, param_offset, desc_buf, param_size); pm_runtime_put_sync(hba->dev); @@ -594,7 +604,11 @@ static ssize_t _name##_show(struct device *dev, \ desc_buf = kzalloc(QUERY_DESC_MAX_SIZE, GFP_ATOMIC); \ if (!desc_buf) \ return -ENOMEM; \ - pm_runtime_get_sync(hba->dev); \ + ret = pm_runtime_get_sync(hba->dev); \ + if (ret < 0) { \ + pm_runtime_put_noidle(hba->dev); \ + return ret; \ + } \ ret = ufshcd_query_descriptor_retry(hba, \ UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE, \ 0, 0, desc_buf, &desc_len); \ @@ -653,7 +667,11 @@ static ssize_t _name##_show(struct device *dev, \ struct ufs_hba *hba = dev_get_drvdata(dev); \ if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \ index = ufshcd_wb_get_query_index(hba); \ - pm_runtime_get_sync(hba->dev); \ + ret = pm_runtime_get_sync(hba->dev); \ + if (ret < 0) { \ + pm_runtime_put_noidle(hba->dev); \ + return ret; \ + } \ ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \ QUERY_FLAG_IDN##_uname, index, &flag); \ pm_runtime_put_sync(hba->dev); \ @@ -711,7 +729,11 @@ static ssize_t _name##_show(struct device *dev, \ u8 index = 0; \ if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \ index = ufshcd_wb_get_query_index(hba); \ - pm_runtime_get_sync(hba->dev); \ + ret = pm_runtime_get_sync(hba->dev); \ + if (ret < 0) { \ + pm_runtime_put_noidle(hba->dev); \ + return ret; \ + } \ ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, \ QUERY_ATTR_IDN##_uname, index, 0, &value); \ pm_runtime_put_sync(hba->dev); \ @@ -850,7 +872,11 @@ static ssize_t dyn_cap_needed_attribute_show(struct device *dev, u8 lun = ufshcd_scsi_to_upiu_lun(sdev->lun); int ret; - pm_runtime_get_sync(hba->dev); + ret = pm_runtime_get_sync(hba->dev); + if (ret < 0) { + pm_runtime_put_noidle(hba->dev); + return ret; + } ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR, QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value); pm_runtime_put_sync(hba->dev); From patchwork Thu Dec 24 17:20:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 11989711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 431D3C43381 for ; Thu, 24 Dec 2020 17:21:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 07DB1224B1 for ; Thu, 24 Dec 2020 17:21:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728868AbgLXRVO (ORCPT ); Thu, 24 Dec 2020 12:21:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728757AbgLXRVJ (ORCPT ); Thu, 24 Dec 2020 12:21:09 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23782C0613ED; Thu, 24 Dec 2020 09:20:29 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id 6so4037164ejz.5; Thu, 24 Dec 2020 09:20:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PYycvZZtwv/h41HPPKiYNBu4NL6LfmBrKKP66ExytA8=; b=p8gLsi1W5BS0fLO7h/XP01TZk9IHMhDz2+a0nVYDI1BQULoIXmMGQSy/rVwHmPpsZx jhQa88c7R+ERK2CvwEcNElAqiMz1f1Ms9afTjAh89irUo1YY2FCfL8AeKURciX5DZ6gF nvz132IAObMGwRTbDbiS2qpms8VfaF4AIE2kyxnaDrpwvwT7L2v/Plr2N3AxhdOddKzq eQa/pMeHAadtZroYliX/JK1bOQu9BIOuYpyvR7L6RWwcdjpG63WomFCe+tNc08Hzldq/ FaefQZo/wv7SatN5goG7t9X57M3ai15+PRXuQ14bkgp9FhBpFdQhkeU5rsb6rj6gimWA J3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PYycvZZtwv/h41HPPKiYNBu4NL6LfmBrKKP66ExytA8=; b=EUqy3DT194KrAV5opTECU7HnzHsej3o5yOnz+/a86zqd5+ld98ZfM1PEBM6QC3y5Dj CF7HRUDHDxZOacV1cQDZVsZcd0AIBlnQ0JY4cqIJwaMc3AjjAXih1ApV8MlTE7d9CG2T +BEganrp86MUNHU0lFHu22UBpEc6PJ7vEqYwLeCss3rk1r0RqCFsGxW4TQ151j3P6q4u n/1Usrcd+Ksp9HZAtGtu5LFhig2fIzE6v+n1rYNGMbvKM3xm2zqocii9KFZrpWuO8ay9 ZLVrdyi/GbW5/VGiH3hCemHB+smfF/jhsQcNxva2mZcFIkakBiuQUjtrU+GZjgcO9eqv QClg== X-Gm-Message-State: AOAM532rO39d25FQDeoNTTroMJyAywm6jmbcADAn/Toua0l3mbXfKAsf E/YAqNVvy7R8Rmx8r1s52aa5fFjqpmjrKg== X-Google-Smtp-Source: ABdhPJwDLNmkh3yZW5f7r/O2OrAwj05q/Ovu3ZsJimwP+OxRmgm+mvBPEqQRIn+R+o0JxLRTi4PKOQ== X-Received: by 2002:a17:906:3711:: with SMTP id d17mr28536567ejc.121.1608830427928; Thu, 24 Dec 2020 09:20:27 -0800 (PST) Received: from localhost.localdomain (ip5f5bfce9.dynamic.kabel-deutschland.de. [95.91.252.233]) by smtp.gmail.com with ESMTPSA id m5sm12874446eja.11.2020.12.24.09.20.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Dec 2020 09:20:27 -0800 (PST) From: Bean Huo To: alim.akhtar@samsung.com, avri.altman@wdc.com, asutoshd@codeaurora.org, jejb@linux.ibm.com, martin.petersen@oracle.com, stanley.chu@mediatek.com, beanhuo@micron.com, bvanassche@acm.org, tomas.winkler@intel.com, cang@codeaurora.org Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, rjw@rjwysocki.net Subject: [PATCH v2 3/3] scsi: ufs: Let resume callback return -EBUSY after ufshcd_shutdown Date: Thu, 24 Dec 2020 18:20:10 +0100 Message-Id: <20201224172010.10701-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201224172010.10701-1-huobean@gmail.com> References: <20201224172010.10701-1-huobean@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org From: Bean Huo After ufshcd_shutdown(), both UFS device and UFS LINk are powered off, return '0' will mislead the upper PM layer since the device has not been successfully resumed yet. This will let pm_runtime_get_sync() caller mistakenly believe the device/LINK has been resumed, which leads to request processing timeout that was en-queued later. To fix this, let ufshcd_system/runtimie_resume() return -EBUSY in case of hba->is_powered == false. Signed-off-by: Bean Huo --- drivers/scsi/ufs/ufshcd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c index e221add25a7e..e1bcac51c01f 100644 --- a/drivers/scsi/ufs/ufshcd.c +++ b/drivers/scsi/ufs/ufshcd.c @@ -8950,14 +8950,16 @@ int ufshcd_system_resume(struct ufs_hba *hba) return -EINVAL; } - if (!hba->is_powered || pm_runtime_suspended(hba->dev)) + if (!hba->is_powered || pm_runtime_suspended(hba->dev)) { /* * Let the runtime resume take care of resuming * if runtime suspended. */ + ret = -EBUSY; goto out; - else + } else { ret = ufshcd_resume(hba, UFS_SYSTEM_PM); + } out: trace_ufshcd_system_resume(dev_name(hba->dev), ret, ktime_to_us(ktime_sub(ktime_get(), start)), @@ -9026,10 +9028,12 @@ int ufshcd_runtime_resume(struct ufs_hba *hba) if (!hba) return -EINVAL; - if (!hba->is_powered) + if (!hba->is_powered) { + ret = -EBUSY; goto out; - else + } else { ret = ufshcd_resume(hba, UFS_RUNTIME_PM); + } out: trace_ufshcd_runtime_resume(dev_name(hba->dev), ret, ktime_to_us(ktime_sub(ktime_get(), start)),