Skip to contentSkip to conversation

Isn't sd_major() broken ?

PATCH Badari Pulavarty 1 participant 1 message Apr 10, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

Hi,

I am little confused about the correctness of sd_major() in drivers/scsi/sd.c.

static int sd_major(int major_idx)

{
        switch (major_idx) {
        case 0:
                return SCSI_DISK0_MAJOR;
        case 1 ... 7:
                return SCSI_DISK1_MAJOR + major_idx - 1;
        case 8 ... 15:
                return SCSI_DISK8_MAJOR + major_idx;
        default:
                BUG();
                return 0;       /* shut up gcc */
        }
}

So, if major_idx = 8, It returns 143.
But according to major.h, scsi has 128-135 reserved majors. But it is registering 136 - 143 as its majors.

#define SCSI_DISK8_MAJOR        128
#define SCSI_DISK9_MAJOR        129
#define SCSI_DISK10_MAJOR       130
#define SCSI_DISK11_MAJOR       131
#define SCSI_DISK12_MAJOR       132
#define SCSI_DISK13_MAJOR       133
#define SCSI_DISK14_MAJOR       134
#define SCSI_DISK15_MAJOR       135

Isn't sd_major() broken ? Here is the patch to fix it.

Thanks,
Badari

# cat /proc/devices
...
Block devices:
  2 fd
  3 ide0
  8 sd
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd
136 sd
137 sd
138 sd
139 sd
140 sd
141 sd
142 sd
143 sd
scsi/sd.c renamed from scsi/sd.c.org +1 -1
@@ -123,7 +123,7 @@ static int sd_major(int major_idx)
 	case 1 ... 7:
 		return SCSI_DISK1_MAJOR + major_idx - 1;
 	case 8 ... 15:
-		return SCSI_DISK8_MAJOR + major_idx;
+		return SCSI_DISK8_MAJOR + major_idx - 8;
 	default:
 		BUG();
 		return 0;	/* shut up gcc */