diff options
author | Bryn M. Reeves <bmr@redhat.com> | 2016-07-06 09:20:05 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2016-07-06 09:23:13 +0100 |
commit | 95ef0cdb461dfb7b7e6ac8e2484564fe0b5ec0ed (patch) | |
tree | 323d099c845e740a3e92e2ac08ee78d08f6dd8b0 | |
parent | 03e03e9c11f5731c225d6cb99a1f36d4d8b699f6 (diff) | |
download | lvm2-95ef0cdb461dfb7b7e6ac8e2484564fe0b5ec0ed.tar.gz |
libdm: check non-zero io count in _average_{rd,wr}_wait_time (Coverity)
Although a non-zero value for the number of ticks spent doing IO
should imply a non-zero number of IOs in the interval test for
this explicitly to avoid a divide-by-zero in the event of bad
counter data.
-rw-r--r-- | libdm/libdm-stats.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/libdm/libdm-stats.c b/libdm/libdm-stats.c index c0ef38f4c..c669b5111 100644 --- a/libdm/libdm-stats.c +++ b/libdm/libdm-stats.c @@ -2600,11 +2600,15 @@ static int _average_rd_wait_time(const struct dm_stats *dms, double *await, rd_io_ticks = dm_stats_get_counter(dms, DM_STATS_READ_NSECS, region_id, area_id); - nr_rd_ios = dm_stats_get_counter(dms, DM_STATS_READS_COUNT, region_id, area_id); - if (rd_io_ticks > 0) + /* + * If rd_io_ticks is > 0 this should imply that nr_rd_ios is + * also > 0 (unless a kernel bug exists). Test for both here + * before using the IO count as a divisor (Coverity). + */ + if (rd_io_ticks > 0 && nr_rd_ios > 0) *await = (double) rd_io_ticks / (double) nr_rd_ios; else *await = 0.0; @@ -2622,7 +2626,12 @@ static int _average_wr_wait_time(const struct dm_stats *dms, double *await, nr_wr_ios = dm_stats_get_counter(dms, DM_STATS_WRITES_COUNT, region_id, area_id); - if (wr_io_ticks > 0) + /* + * If wr_io_ticks is > 0 this should imply that nr_wr_ios is + * also > 0 (unless a kernel bug exists). Test for both here + * before using the IO count as a divisor (Coverity). + */ + if (wr_io_ticks > 0 && nr_wr_ios > 0) *await = (double) wr_io_ticks / (double) nr_wr_ios; else *await = 0.0; |