mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Can Guo <cang@codeaurora.org>
To: Bean Huo <huobean@gmail.com>
Cc: 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,
	linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
	rjw@rjwysocki.net
Subject: Re: [PATCH v2 2/3] scsi: ufs: Add handling of the return value of pm_runtime_get_sync()
Date: Mon, 28 Dec 2020 09:50:30 +0800	[thread overview]
Message-ID: <88069c938a06b06f89cc4662cef3c1be@codeaurora.org> (raw)
In-Reply-To: <20201224172010.10701-3-huobean@gmail.com>

On 2020-12-25 01:20, Bean Huo wrote:
> From: Bean Huo <beanhuo@micron.com>
> 
> The race issue may exist between UFS access in UFS sysfs context and 
> UFS
> shutdown, thus will cause pm_runtime_get_sync() resume failure.

Are you trying to fix the race condition by adding these checks or just
adding these checks in case pm_runtime_get_sync() fails?

Can Guo.

> 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 <beanhuo@micron.com>
> ---
>  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);

  reply	other threads:[~2020-12-28  1:51 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-24 17:20 [PATCH v2 0/3] Two changes of UFS sysfs Bean Huo
2020-12-24 17:20 ` [PATCH v2 1/3] scsi: ufs: Replace sprintf and snprintf with sysfs_emit Bean Huo
2020-12-24 17:20 ` [PATCH v2 2/3] scsi: ufs: Add handling of the return value of pm_runtime_get_sync() Bean Huo
2020-12-28  1:50   ` Can Guo [this message]
2021-01-04 17:39     ` Bean Huo
2020-12-24 17:20 ` [PATCH v2 3/3] scsi: ufs: Let resume callback return -EBUSY after ufshcd_shutdown Bean Huo
2021-01-04 19:26   ` Bean Huo
2021-01-05  1:10   ` Can Guo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=88069c938a06b06f89cc4662cef3c1be@codeaurora.org \
    --to=cang@codeaurora.org \
    --cc=alim.akhtar@samsung.com \
    --cc=asutoshd@codeaurora.org \
    --cc=avri.altman@wdc.com \
    --cc=beanhuo@micron.com \
    --cc=bvanassche@acm.org \
    --cc=huobean@gmail.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=rjw@rjwysocki.net \
    --cc=stanley.chu@mediatek.com \
    --cc=tomas.winkler@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome