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

m68k/mac: Fix compiler warning in via_read_time()

The algorithm described in the comment compares two reads from the RTC but
the code actually reads once and compares the result to an uninitialized
value. This causes the compiler to warn, "last_result maybe used
uninitialized". Make the code match the comment, fix the warning and
perhaps improve reliability. Tested on a Quadra 700.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>

authored by

Finn Thain and committed by
Geert Uytterhoeven
75a23850 d996e9dc

+23 -17
+23 -17
arch/m68k/mac/misc.c
··· 304 304 static long via_read_time(void) 305 305 { 306 306 union { 307 - __u8 cdata[4]; 308 - long idata; 307 + __u8 cdata[4]; 308 + long idata; 309 309 } result, last_result; 310 - int ct; 310 + int count = 1; 311 + 312 + via_pram_command(0x81, &last_result.cdata[3]); 313 + via_pram_command(0x85, &last_result.cdata[2]); 314 + via_pram_command(0x89, &last_result.cdata[1]); 315 + via_pram_command(0x8D, &last_result.cdata[0]); 311 316 312 317 /* 313 318 * The NetBSD guys say to loop until you get the same reading 314 319 * twice in a row. 315 320 */ 316 321 317 - ct = 0; 318 - do { 319 - if (++ct > 10) { 320 - printk("via_read_time: couldn't get valid time, " 321 - "last read = 0x%08lx and 0x%08lx\n", 322 - last_result.idata, result.idata); 323 - break; 324 - } 325 - 326 - last_result.idata = result.idata; 327 - result.idata = 0; 328 - 322 + while (1) { 329 323 via_pram_command(0x81, &result.cdata[3]); 330 324 via_pram_command(0x85, &result.cdata[2]); 331 325 via_pram_command(0x89, &result.cdata[1]); 332 326 via_pram_command(0x8D, &result.cdata[0]); 333 - } while (result.idata != last_result.idata); 334 327 335 - return result.idata - RTC_OFFSET; 328 + if (result.idata == last_result.idata) 329 + return result.idata - RTC_OFFSET; 330 + 331 + if (++count > 10) 332 + break; 333 + 334 + last_result.idata = result.idata; 335 + } 336 + 337 + pr_err("via_read_time: failed to read a stable value; " 338 + "got 0x%08lx then 0x%08lx\n", 339 + last_result.idata, result.idata); 340 + 341 + return 0; 336 342 } 337 343 338 344 /*