Skip to contentSkip to conversation

discriminate single bit error hardware failure from slab corruption.

DISCUSSION [email protected] 2 participants 2 messages Feb 3, 2006

lore
Share & tools
lore
#0 lore raw

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"
		
	}
#1 lore raw
Quoted 2 lines

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

Whatever they are, they must be able to be reduced to an integer constant.

Jan Engelhardt