Skip to content

Commit 4881f60

Browse files
Chen-Gangrafaeljw
authored andcommitted
PM / hibernate: use unsigned local variables in swsusp_show_speed()
do_div() needs 'u64' type, or it reports warning. And negative number is meaningless for "speed", so change all signed to unsigned within swsusp_show_speed(). 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 Signed-off-by: Chen Gang <gang.chen.5i5j@gmail.com> [rjw: Subject] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent d1db0ee commit 4881f60

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

kernel/power/hibernate.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,23 @@ static void platform_recover(int platform_mode)
228228
void swsusp_show_speed(struct timeval *start, struct timeval *stop,
229229
unsigned nr_pages, char *msg)
230230
{
231-
s64 elapsed_centisecs64;
232-
int centisecs;
233-
int k;
234-
int kps;
231+
u64 elapsed_centisecs64;
232+
unsigned int centisecs;
233+
unsigned int k;
234+
unsigned int kps;
235235

236236
elapsed_centisecs64 = timeval_to_ns(stop) - timeval_to_ns(start);
237+
/*
238+
* If "(s64)elapsed_centisecs64 < 0", it will print long elapsed time,
239+
* it is obvious enough for what went wrong.
240+
*/
237241
do_div(elapsed_centisecs64, NSEC_PER_SEC / 100);
238242
centisecs = elapsed_centisecs64;
239243
if (centisecs == 0)
240244
centisecs = 1; /* avoid div-by-zero */
241245
k = nr_pages * (PAGE_SIZE / 1024);
242246
kps = (k * 100) / centisecs;
243-
printk(KERN_INFO "PM: %s %d kbytes in %d.%02d seconds (%d.%02d MB/s)\n",
247+
printk(KERN_INFO "PM: %s %u kbytes in %u.%02u seconds (%u.%02u MB/s)\n",
244248
msg, k,
245249
centisecs / 100, centisecs % 100,
246250
kps / 1000, (kps % 1000) / 10);

0 commit comments

Comments
 (0)