Re: [PATCH v2] kernel/power/hibernate.c: use 'u64' instead of 's64' to avoid warning

From: Pavel Machek
Date: Tue Apr 22 2014 - 03:21:32 EST


On Tue 2014-04-22 09:29:20, Chen Gang wrote:
> For do_div(), it need 'u64' type, which means the outside must be sure
> of 'start' is not bigger than 'stop', or it will report warning.
>
> Even if 'start' was really bigger than 'stop', it would print incorrect
> information, but for kernel, it still can continue, so use WARN_ON() is
> enough.
>
> The related warning (with allmodconfig for unicore32):
>
> CC kernel/power/hibernate.o
> kernel/power/hibernate.c: In function âswsusp_show_speedâ:
> kernel/power/hibernate.c:237: warning: comparison of distinct pointer types lacks a cast
>
>

Certainly better, but

> - s64 elapsed_centisecs64;
> + u64 elapsed_centisecs64;
> int centisecs;
> int k;
> int kps;
>
> elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
> + WARN_ON((s64)elapsed_centisecs64 < 0);
> do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
> centisecs = elapsed_centisecs64;

...do we need to do the WARN_ON()? Only result of underflow will be
very long elapsed time reported... that does not sound too
bad. ... and it will be quite obvious what went wrong.
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/