Commit 79d8554f authored by Andrew Morton's avatar Andrew Morton Committed by David S. Miller

[PATCH] Fix math underflow in disk accounting

Patch from Lev Makhlis <mlev@despammed.com>

The disk accounting will overflow after 4,000,000 seconds.  Extend that
by a factor of 1000.
parent becd026d
......@@ -324,9 +324,16 @@ static ssize_t disk_size_read(struct gendisk * disk,
{
return off ? 0 : sprintf(page, "%llu\n",(unsigned long long)get_capacity(disk));
}
static inline unsigned MSEC(unsigned x)
static inline unsigned jiffies_to_msec(unsigned jif)
{
return x * 1000 / HZ;
#if 1000 % HZ == 0
return jif * (1000 / HZ);
#elif HZ % 1000 == 0
return jif / (HZ / 1000);
#else
return (jif / HZ) * 1000 + (jif % HZ) * 1000 / HZ;
#endif
}
static ssize_t disk_stat_read(struct gendisk * disk,
char *page, size_t count, loff_t off)
......@@ -338,11 +345,11 @@ static ssize_t disk_stat_read(struct gendisk * disk,
"%8u %8u %8u"
"\n",
disk->reads, disk->read_merges, (u64)disk->read_sectors,
MSEC(disk->read_ticks),
jiffies_to_msec(disk->read_ticks),
disk->writes, disk->write_merges, (u64)disk->write_sectors,
MSEC(disk->write_ticks),
disk->in_flight, MSEC(disk->io_ticks),
MSEC(disk->time_in_queue));
jiffies_to_msec(disk->write_ticks),
disk->in_flight, jiffies_to_msec(disk->io_ticks),
jiffies_to_msec(disk->time_in_queue));
}
static struct disk_attribute disk_attr_dev = {
.attr = {.name = "dev", .mode = S_IRUGO },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment