Re: Bugfix for drivers/scsi/sd.c

Jirka Hanika (HANIKA@ksvi.mff.cuni.cz)
Fri, 4 Dec 1998 22:24:30 +0200 (METDST)


> The patch fixes:
>
> 1. registration 1 scsi major too much

With 0, 16, 32... disks, yes

> 2. getting stuck with _zero_ scsi disks recognized in case
> of having "12 + n * 16" disks (n = 0 to 7).

Getting stuck with only n * 16 disks recognized in that case. Yes.
Your patch is correct, however, it is a bit too cautious.

> --- linux-2.1.130.orig/drivers/scsi/sd.c Thu Nov 19 01:42:44 1998
> +++ linux-2.1.130/drivers/scsi/sd.c Wed Dec 2 01:03:16 1998
> @@ -1487,7 +1487,7 @@
> sd_template.dev_max = 128;
>
> if(!sd_registered) {
> - for (i=0; i <= sd_template.dev_max / SCSI_DISKS_PER_MAJOR; i++) {
> + for (i=0; i <= ( sd_template.dev_max - 1) / SCSI_DISKS_PER_MAJOR; i++) {
> if (register_blkdev(SD_MAJOR(i),"sd",&sd_fops)) {
> printk("Unable to get major %d for SCSI disk\n", SD_MAJOR(i));
> return 1;
> @@ -1540,8 +1540,12 @@
> sd_gendisks[i].real_devices =
> (void *) (rscsi_disks + i * SCSI_DISKS_PER_MAJOR);
> }
> - LAST_SD_GENDISK.max_nr =
> - sd_template.dev_max % SCSI_DISKS_PER_MAJOR;
> + if ( sd_template.dev_max == 0)
> + LAST_SD_GENDISK.max_nr = 0;

We're talking the sd_init() function which doesn't execute at all
if no disks are detected. Moreover, unless SD_EXTRA_DEVS is set to
zero, dev_max is never zero. This check is not necessary.

> + else if ( sd_template.dev_max % SCSI_DISKS_PER_MAJOR == 0)
> + LAST_SD_GENDISK.max_nr = SCSI_DISKS_PER_MAJOR;
> + else
> + LAST_SD_GENDISK.max_nr = sd_template.dev_max % SCSI_DISKS_PER_MAJOR;
> LAST_SD_GENDISK.next = NULL;
> return 0;
> }

What about optimizing away the if's by

LAST_SD_GENDISK.max_nr =
(sd_template.dev_max - 1) % SCSI_DISKS_PER_MAJOR + 1;

I'm not sure which one is nicer

Jirka

-
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/