Skip to content

Commit 75a2385

Browse files
Finn Thaingeertu
authored andcommitted
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>
1 parent d996e9d commit 75a2385

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

‎arch/m68k/mac/misc.c‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -304,35 +304,41 @@ static void via_write_pram(int offset, __u8 data)
304304
static long via_read_time(void)
305305
{
306306
union {
307-
__u8 cdata[4];
308-
long idata;
307+
__u8 cdata[4];
308+
long idata;
309309
} 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]);
311316

312317
/*
313318
* The NetBSD guys say to loop until you get the same reading
314319
* twice in a row.
315320
*/
316321

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) {
329323
via_pram_command(0x81, &result.cdata[3]);
330324
via_pram_command(0x85, &result.cdata[2]);
331325
via_pram_command(0x89, &result.cdata[1]);
332326
via_pram_command(0x8D, &result.cdata[0]);
333-
} while (result.idata != last_result.idata);
334327

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;
336342
}
337343

338344
/*

0 commit comments

Comments
 (0)