IDE problem?

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Sun, 16 May 1999 00:15:02 +0200 (MEST)


Hi,

I'm not really experiencing problems with respect to what I'm
reporting here, but I was reading the code and I might have spotted a
problem in the IDE driver in 2.0.36:

static int lba_capacity_is_ok (struct hd_driveid *id)
{
unsigned long lba_sects = id->lba_capacity;
unsigned long chs_sects = id->cyls * id->heads * id->sectors;
unsigned long _10_percent = chs_sects / 10;

/* very large drives (8GB+) may lie about the number of cylinders */
if (id->cyls == 16383 && id->heads == 16 && id->sectors == 63 && lba_sects > chs_se
cts) {
id->cyls = lba_sects / (16 * 63); /* correct cyls */
return 1; /* lba_capacity is our only option */
}
/* perform a rough sanity check on lba_sects: within 10% is "okay" */
if ((lba_sects - chs_sects) < _10_percent)
return 1; /* lba_capacity is good */

/* some drives have the word order reversed */
lba_sects = (lba_sects << 16) | (lba_sects >> 16);
if ((lba_sects - chs_sects) < _10_percent) {
id->lba_capacity = lba_sects; /* fix it */
return 1; /* lba_capacity is (now) good */
}
return 0; /* lba_capacity value is bad */
}

As "lba_sects" is defined a "long", this will be 64 bits on
Alpha. Swapping the words with the "(lba_sects << 16) | (lba_sects >>
16);" wont work: you're counting on 32bit arithmetic. I recommend
adding the appropriate & 0xffff's in there...

I can imagine that code not getting enough testing... :-)
(as not many alpha-owners are going to have an odd IDE disk like that)

Regards,

Roger.

-- 
** R.E.Wolff@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2137555 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
------ Microsoft SELLS you Windows, Linux GIVES you the whole house ------

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