aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m68k
diff options
context:
space:
mode:
authorFinn Thain <fthain@telegraphics.com.au>2011-07-17 10:06:10 -0400
committerGeert Uytterhoeven <geert@linux-m68k.org>2011-10-24 15:00:34 -0400
commit75a23850cd282eeafbe23d6a9ade4eaf23babd51 (patch)
treeba6582c7c0c5c54dd5b986b324354b743a2a8299 /arch/m68k
parentd996e9dc453a5f327961f19d274c6481b3bf4f34 (diff)
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>
Diffstat (limited to 'arch/m68k')
-rw-r--r--arch/m68k/mac/misc.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/arch/m68k/mac/misc.c b/arch/m68k/mac/misc.c
index e023fc6b37e5..eb915551de69 100644
--- a/arch/m68k/mac/misc.c
+++ b/arch/m68k/mac/misc.c
@@ -304,35 +304,41 @@ static void via_write_pram(int offset, __u8 data)
304static long via_read_time(void) 304static long via_read_time(void)
305{ 305{
306 union { 306 union {
307 __u8 cdata[4]; 307 __u8 cdata[4];
308 long idata; 308 long idata;
309 } result, last_result; 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 * The NetBSD guys say to loop until you get the same reading 318 * The NetBSD guys say to loop until you get the same reading
314 * twice in a row. 319 * twice in a row.
315 */ 320 */
316 321
317 ct = 0; 322 while (1) {
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
329 via_pram_command(0x81, &result.cdata[3]); 323 via_pram_command(0x81, &result.cdata[3]);
330 via_pram_command(0x85, &result.cdata[2]); 324 via_pram_command(0x85, &result.cdata[2]);
331 via_pram_command(0x89, &result.cdata[1]); 325 via_pram_command(0x89, &result.cdata[1]);
332 via_pram_command(0x8D, &result.cdata[0]); 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/*