Skip to content

Commit eb48e9f

Browse files
gwendalcrmartinkpetersen
authored andcommitted
scsi: ufs: core: sysfs: Prevent div by zero
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]>
1 parent 35002a8 commit eb48e9f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/ufs/core/ufs-sysfs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,9 @@ static ssize_t read_req_latency_avg_show(struct device *dev,
670670
struct ufs_hba *hba = dev_get_drvdata(dev);
671671
struct ufs_hba_monitor *m = &hba->monitor;
672672

673+
if (!m->nr_req[READ])
674+
return sysfs_emit(buf, "0\n");
675+
673676
return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[READ]),
674677
m->nr_req[READ]));
675678
}
@@ -737,6 +740,9 @@ static ssize_t write_req_latency_avg_show(struct device *dev,
737740
struct ufs_hba *hba = dev_get_drvdata(dev);
738741
struct ufs_hba_monitor *m = &hba->monitor;
739742

743+
if (!m->nr_req[WRITE])
744+
return sysfs_emit(buf, "0\n");
745+
740746
return sysfs_emit(buf, "%llu\n", div_u64(ktime_to_us(m->lat_sum[WRITE]),
741747
m->nr_req[WRITE]));
742748
}

0 commit comments

Comments
 (0)