Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche@acm.org>
To: Gwendal Grignou <gwendal@chromium.org>,
	alim.akhtar@samsung.com, avri.altman@wdc.com,
	quic_cang@quicinc.com, daejun7.park@samsung.com
Cc: linux-scsi@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] scsi: ufs: core: sysfs: Prevent div by zero
Date: Thu, 21 Nov 2024 12:24:51 -0800	[thread overview]
Message-ID: <a487b02b-72c6-4bee-bfdf-4106cda96f36@acm.org> (raw)
In-Reply-To: <20241120062522.917157-1-gwendal@chromium.org>

On 11/19/24 10:25 PM, Gwendal Grignou wrote:
> Prevent a division by 0 when monitoring is not enabled.
> 
> Fixes: 1d8613a23f3c ("scsi: ufs: core: Introduce HBA performance monitor sysfs nodes")
> 
> Cc: stable@vger.kernel.org
> Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
> ---
>   drivers/ufs/core/ufs-sysfs.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
> index c95906443d5f9..3692b39b35e78 100644
> --- a/drivers/ufs/core/ufs-sysfs.c
> +++ b/drivers/ufs/core/ufs-sysfs.c
> @@ -485,6 +485,9 @@ static ssize_t read_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[READ])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
>   						 m->nr_req[READ]));
>   }
> @@ -552,6 +555,9 @@ static ssize_t write_req_latency_avg_show(struct device *dev,
>   	struct ufs_hba *hba = dev_get_drvdata(dev);
>   	struct ufs_hba_monitor *m = &hba->monitor;
>   
> +	if (!m->nr_req[WRITE])
> +		return sysfs_emit(buf, "0\n");
> +
>   	return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
>   						 m->nr_req[WRITE]));
>   }

Is anyone using the UFS monitor infrastructure or can it perhaps be
removed?

Thanks,

Bart.

  reply	other threads:[~2024-11-21 20:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20  6:25 [PATCH] scsi: ufs: core: sysfs: Prevent div by zero Gwendal Grignou
2024-11-21 20:24 ` Bart Van Assche [this message]
2024-11-22  2:12   ` Can Guo
2024-11-25 23:08     ` Bart Van Assche
2024-11-22  2:09 ` 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=a487b02b-72c6-4bee-bfdf-4106cda96f36@acm.org \
    --to=bvanassche@acm.org \
    --cc=alim.akhtar@samsung.com \
    --cc=avri.altman@wdc.com \
    --cc=daejun7.park@samsung.com \
    --cc=gwendal@chromium.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=quic_cang@quicinc.com \
    --cc=stable@vger.kernel.org \
    /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