Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: fix "ering" sysfs time printing

The sysfs file for the libata error handling has multiple issues
in the way it prints time stamps:

* it prints a 9-digit nanosecond value using a %06lu format string,
which drops some leading zeroes
* it converts a 64-bit jiffes value to a timespec using
jiffies_to_timespec(), which takes a 'long' argument, so the
result is wrong after a jiffies overflow (49 days).
* we try to avoid using timespec because that generally overflows
in 2038, although this particular usage is ok.

This replaces the jiffies_to_timespec call with an open-coded
implementation that gets it right.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Arnd Bergmann and committed by
Tejun Heo
f3f99d37 8dbcad02

+5 -4
+5 -4
drivers/ata/libata-transport.c
··· 495 495 static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg) 496 496 { 497 497 struct ata_show_ering_arg* arg = void_arg; 498 - struct timespec time; 498 + u64 seconds; 499 + u32 rem; 499 500 500 - jiffies_to_timespec(ent->timestamp,&time); 501 + seconds = div_u64_rem(ent->timestamp, HZ, &rem); 501 502 arg->written += sprintf(arg->buf + arg->written, 502 - "[%5lu.%06lu]", 503 - time.tv_sec, time.tv_nsec); 503 + "[%5llu.%09lu]", seconds, 504 + rem * NSEC_PER_SEC / HZ); 504 505 arg->written += get_ata_err_names(ent->err_mask, 505 506 arg->buf + arg->written); 506 507 return 0;