Skip to content

Commit

Permalink
scsi: ufs: core: sysfs: Prevent div by zero
Browse files Browse the repository at this point in the history
commit eb48e9f upstream.

Prevent a division by 0 when monitoring is not enabled.

Fixes: 1d8613a ("scsi: ufs: core: Introduce HBA performance monitor sysfs nodes")
Cc: [email protected]
Signed-off-by: Gwendal Grignou <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Can Guo <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
gwendalcr authored and gregkh committed Dec 14, 2024
1 parent 38bd792 commit 0069928
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/ufs/core/ufs-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down Expand Up @@ -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]));
}
Expand Down

0 comments on commit 0069928

Please sign in to comment.