Re: discriminate single bit error hardware failure from slab corruption.

From: linux
Date: Fri Feb 03 2006 - 04:23:41 EST


Um... case values are allowed to be expressions.

Isn't
+ switch (total) {
+ case SLAB_POISON ^ 0x01:
+ case SLAB_POISON ^ 0x02:
+ case SLAB_POISON ^ 0x04:
+ case SLAB_POISON ^ 0x08:
+ case SLAB_POISON ^ 0x10:
+ case SLAB_POISON ^ 0x20:
+ case SLAB_POISON ^ 0x40:
+ case SLAB_POISON ^ 0x80:
+ printk (KERN_ERR "Single bit error detected. Possibly bad RAM\n"

Infinitely clearer, even without the comments? Or, if you want to
be cleverer:

total ^= SLAB_POISON;
if ((total & (total-1)) == 0) {
printk (KERN_ERR "Single bit error detected. Possibly bad RAM\n"
}


If you wanted to get the bit-counting exactly accurate, you'd do:

unsigned char total = 0, total2 = 0;

for (i = 0; i < limit; i++) {
unsigned char delta = data[offset+i];
printk(" %02x", delta;
delta ^= POISON_FREE;
total2 |= total & delta;
total |= delta;
}
printk("\n");

/* If total2 has 0 bits set and total1 has at most 1 bit set... */
if (!total2 && !(total1 & (total1 - 1)) {
printk (KERN_ERR "Single bit error detected. Possibly bad RAM\n"

}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/