Linux-kernel mailing list archive 1999-23,: [patch] 2.2.* and 2.3.*: problems with sd_detach

# [patch] 2.2.* and 2.3.*: problems with sd_detach

Maciej W. Rozycki (macro@ds2.pg.gda.pl)
Mon, 7 Jun 1999 14:15:42 +0200 (MET DST)

- Messages sorted by: [ date ][ thread ][ subject ][ author ]
- Next message: Bryn Paul Arnold Jones: "Re: FireWire subsystem in development"
- Previous message: Gabor Lenart: "hard crash under 2.2.9"

Hi,

There is a nasty problem with SCSI disks which exists for quite a long
time. After removing the module for the second SCSI host adapter (ppa;
the first one is ncr53c8xx and is compiled into the kernel), further
/proc/scsi accesses cause bad things to happen to my Alpha system.
Sometimes the process is being killed due to unaligned code accesses and
sometimes it just hangs forever.

The reason seem to be located within sd_detach. Upon exiting from this
function the number of devices attached to the major number is to be
decremented. The macro that is used to achieve this expects to get the
number of the device to be disconnected as the parameter. Unfortunately,
it receives the minor number instead which causes random corruption to
happen.

The following patch seems to fix the problem. It was sent to
linux-kernel already but since neither this nor an alternative solution is
provided in pre-2.2.10-2 and 2.3.5, I am resubmitting it hereby.

Maciej

    --
    +  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
    +--------------------------------------------------------------+
    +        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

    diff -u --recursive --new-file linux-2.2.8.macro/drivers/scsi/sd.c linux-2.2.8/drivers/scsi/sd.c
    --- linux-2.2.8.macro/drivers/scsi/sd.c	Fri May 14 14:12:43 1999
    +++ linux-2.2.8/drivers/scsi/sd.c	Fri May 14 14:06:28 1999
    @@ -1729,7 +1729,7 @@
     static void sd_detach(Scsi_Device * SDp)
     {
         Scsi_Disk * dpnt;
    -    int i;
    +    int i, j;
         int max_p;
         int start;

    @@ -1741,8 +1741,8 @@
     	    max_p = sd_gendisk.max_p;
     	    start = i << sd_gendisk.minor_shift;

    -	    for (i=max_p - 1; i >=0 ; i--) {
    -		int index = start+i;
    +	    for (j=max_p - 1; j >=0 ; j--) {
    +		int index = start+j;
     		kdev_t devi = MKDEV_SD_PARTITION(index);
                     struct super_block *sb = get_super(devi);
     		sync_dev(devi);
    @@ -1759,7 +1759,7 @@
     	    SDp->attached--;
     	    sd_template.dev_noticed--;
     	    sd_template.nr_dev--;
    -	    SD_GENDISK(start).nr_real--;
    +	    SD_GENDISK(i).nr_real--;
     	    return;
     	}
         return;

    -
    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: Bryn Paul Arnold Jones: "Re: FireWire subsystem in development"
- Previous message: Gabor Lenart: "hard crash under 2.2.9"