Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp6691074pxu; Thu, 24 Dec 2020 09:21:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJwct9zT/GfpeEQgyybc8AQ3a3Di6dqtX+MUvfHARZPOb8ak7nhSJzh8zDo/GdSAZJCItoZY X-Received: by 2002:a05:6402:1597:: with SMTP id c23mr29737738edv.212.1608830518692; Thu, 24 Dec 2020 09:21:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1608830518; cv=none; d=google.com; s=arc-20160816; b=tQqWUUVphgKW6fPWslluB8oClUCOXMB4QWFP4pq9cxQ2kR61HLPAeRYj0bzw/qh2HY 6zFCx68Rlfy8o5+i1rj5Pwyu3NBVv9XnD61PwFr9AdMPeV7vvxPPJOD7BXmbSbpD2cu6 qCXf4OdKonlnB5+iwGDINw6nPGxpW86oQUO3LbDXjHFULLNFjoAooKqc+YqX5W56llgl iyLc3Hy2JVS4ksgqjDTmCKsnE91wZAHvTT5KkPL5q+2Y2RUFlsNmNxC54AyqCH4EM0B4 G9JcmQ8jY/nsp/itnlP4fxdtmJgbMrchqSaNxTHwGhOyfQieYzJAVwRefgIGa1d8rPOt d2jQ== 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:dkim-signature; bh=M/LQBu//i4RMgFaViCE8yWcfBThRAvtu9np9/z5UKcA=; b=ndRH7rEYWzfoW3oHBTuOvPEunq1U9mPKrvaC9cMotIUOuDalsLoQPsmkG9GFBMaOew a4DIijNA4rAS4BxrLbcAcN98q0eWreKbGNM1590sqCHpR46YTHDfDIQQqRuyBm7TuDVn gClIyf5QKgu5Zqp2+sD917TR47W3rpqrGj+dzWEU/jbUIJFNuxewsjgTDMhfVs/Jk60j 0gA5+IONBaztkvMV6JXogFZ0PbHxrq/aHmd5MGmHAs0SooQLoRR26To2iSPrkanDqvGU +UBGhlAsCt1Vwmf2DCZunS5NQLPD9+tmqAa2POBDgVo6HR8xr/Icuj1XwO4/19AaSptI rqgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Ms/eruC8"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cq10si14666649edb.140.2020.12.24.09.21.35; Thu, 24 Dec 2020 09:21:58 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Ms/eruC8"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728791AbgLXRVJ (ORCPT + 99 others); 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-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-kernel@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); -- 2.17.1