Fri Sep 19 16:49:27 2008 UTC ()
PR/46593: Patrick Welche: Compute both the original and the ~VIA_T_BOOTABLE
hacked checksums and compare against both.


(christos)
diff -r1.5 -r1.6 src/sys/dev/ata/ata_raid_via.c

cvs diff -r1.5 -r1.6 src/sys/dev/ata/ata_raid_via.c (expand / switch to context diff)
--- src/sys/dev/ata/ata_raid_via.c 2008/03/18 20:46:36 1.5
+++ src/sys/dev/ata/ata_raid_via.c 2008/09/19 16:49:27 1.6
@@ -1,4 +1,4 @@
-/*	$NetBSD: ata_raid_via.c,v 1.5 2008/03/18 20:46:36 cube Exp $	*/
+/*	$NetBSD: ata_raid_via.c,v 1.6 2008/09/19 16:49:27 christos Exp $	*/
 
 /*-
  * Copyright (c) 2000,2001,2002 Søren Schmidt <sos@FreeBSD.org>
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.5 2008/03/18 20:46:36 cube Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ata_raid_via.c,v 1.6 2008/09/19 16:49:27 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -120,7 +120,7 @@
 	int bmajor, error;
 	dev_t dev;
 	uint32_t drive;
-	uint8_t checksum, *ptr;
+	uint8_t checksum, checksum_alt, byte3, *ptr;
 	int count, disk;
 	struct ataraid_array_info *aai;
 	struct ataraid_disk_info *adi;
@@ -165,15 +165,18 @@
 	}
 
 	/* calculate checksum and compare for valid */
-	for (checksum = 0, ptr = (uint8_t *)info, count = 0; count < 50;
-	    count++)
+	for (byte3 = 0, checksum = 0, ptr = (uint8_t *)info, count = 0;
+	    count < 50; count++)
 		if (count == 3)
-			checksum += *ptr++ & ~ VIA_T_BOOTABLE;
+			byte3 = *ptr++;
 		else
 			checksum += *ptr++;
-	if (checksum != info->checksum) {
-		DPRINTF(("%s: VIA V-RAID checksum failed 0x%02x != 0x%02x\n",
-		    device_xname(sc->sc_dev), checksum, info->checksum));
+	checksum_alt = checksum + (byte3 & ~VIA_T_BOOTABLE);
+	checksum += byte3;
+	if (checksum != info->checksum && checksum_alt != info->checksum) {
+		DPRINTF(("%s: VIA V-RAID checksum failed 0x%02x != "
+		    "0x%02x or 0x%02x\n", device_xname(sc->sc_dev),
+		    info->checksum, checksum, checksum_alt));
 		error = ESRCH;
 		goto out;
 	}