Linux-kernel mailing list archive 1999-20,: IDE fix... ("obviously correct").

# IDE fix... ("obviously correct").

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Mon, 17 May 1999 08:01:31 +0200 (MEST)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Rogier Wolff: "Re: 2.3.x wish list?"
- Previous message: Cameron Simpson: "[OT] Re: C expressions"
- Next in thread: Guest section DW: "Re: IDE fix... ("obviously correct")."
- Reply: Guest section DW: "Re: IDE fix... ("obviously correct")."
- Reply: Linus Torvalds: "Re: IDE fix... ("obviously correct")."

Hi,

It is so obvious I couldn't believe my eyes, and had to ask a second
opinion in this matter, and I therfore didn't provide a patch first
time around.

It looks as if noone with a 64 bit machine has gotten bitten by this
yet, but the IDE/64bit architecture combination is getting more and
more common.

lba_sects is defined as a long, which is 64 bits on 64-bit
architectures like Alpha.

Supposed it has the value 0x12345678, and the original code is used:

lba_sects = (lba_sects << 16) | (lba_sects >> 16);

then, we assign

lba_sects = 0x123456780000 | 0x1234
= 0x123456781234

which is not the intention: we wanted 0x56781234.

I therefore propose the following patch:

diff -ur linux-2.2.9.clean/drivers/block/ide-disk.c linux/drivers/block/ide-disk.c
--- linux-2.2.9.clean/drivers/block/ide-disk.c Wed Apr 7 17:03:50 1999
+++ linux/drivers/block/ide-disk.c Mon May 17 07:53:48 1999
@@ -106,7 +106,8 @@
return 1; /* lba_capacity is good */
}
/* some drives have the word order reversed */
- lba_sects = (lba_sects << 16) | (lba_sects >> 16);
+ lba_sects = ((lba_sects & 0xffff) << 16) |
+ ((lba_sects >> 16) & 0xffff);
if ((lba_sects - chs_sects) < _10_percent) {
id->lba_capacity = lba_sects; /* fix it */
return 1; /* lba_capacity is (now) good */

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/

- Next message: Rogier Wolff: "Re: 2.3.x wish list?"
- Previous message: Cameron Simpson: "[OT] Re: C expressions"
- Next in thread: Guest section DW: "Re: IDE fix... ("obviously correct")."
- Reply: Guest section DW: "Re: IDE fix... ("obviously correct")."
- Reply: Linus Torvalds: "Re: IDE fix... ("obviously correct")."