linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ata: fix "ering" sysfs time printing
@ 2016-06-17 15:37 Arnd Bergmann
  2016-06-17 16:10 ` Tejun Heo
  0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2016-06-17 15:37 UTC (permalink / raw)
  To: Tejun Heo
  Cc: y2038, Arnd Bergmann, linux-ide, linux-arm-kernel,
	bcm-kernel-feedback-list, linux-kernel

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>
---
 drivers/ata/libata-transport.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/ata/libata-transport.c b/drivers/ata/libata-transport.c
index e2d94972962d..7ef16c085058 100644
--- a/drivers/ata/libata-transport.c
+++ b/drivers/ata/libata-transport.c
@@ -495,12 +495,13 @@ struct ata_show_ering_arg {
 static int ata_show_ering(struct ata_ering_entry *ent, void *void_arg)
 {
 	struct ata_show_ering_arg* arg = void_arg;
-	struct timespec time;
+	u64 seconds;
+	u32 rem;
 
-	jiffies_to_timespec(ent->timestamp,&time);
+	seconds = div_u64_rem(ent->timestamp, HZ, &rem);
 	arg->written += sprintf(arg->buf + arg->written,
-			       "[%5lu.%06lu]",
-			       time.tv_sec, time.tv_nsec);
+			        "[%5llu.%09lu]", seconds,
+				rem * NSEC_PER_SEC / HZ);
 	arg->written += get_ata_err_names(ent->err_mask,
 					  arg->buf + arg->written);
 	return 0;
-- 
2.9.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ata: fix "ering" sysfs time printing
  2016-06-17 15:37 [PATCH] ata: fix "ering" sysfs time printing Arnd Bergmann
@ 2016-06-17 16:10 ` Tejun Heo
  0 siblings, 0 replies; 2+ messages in thread
From: Tejun Heo @ 2016-06-17 16:10 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: y2038, linux-ide, linux-arm-kernel, bcm-kernel-feedback-list,
	linux-kernel

On Fri, Jun 17, 2016 at 05:37:12PM +0200, Arnd Bergmann wrote:
> 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>

Heh, I'm not even sure why we're exposing this but it's already there.
Applied to libata/for-4.8.

Thanks!

-- 
tejun

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-17 16:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-17 15:37 [PATCH] ata: fix "ering" sysfs time printing Arnd Bergmann
2016-06-17 16:10 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).