[PATCH] fix 'rmmod sd_mod' with no scsi disks (test9-2 and 2.2.17)

From: raubitsj@dynabytesystems.com
Date: Mon Sep 18 2000 - 08:10:53 EST


I have seen this problem for a long time now (and it has been reported on
this list before-months ago). My TODO list of bugs to investigate has
grown too large so I needed to get this one off my list.

the offending code is:
"linux/drivers/scsi/sd.c" 1353/1393 (test9-2)
> for (i = 0; i <= (sd_template.dev_max - 1) / SCSI_DISKS_PER_MAJOR; i++)
> devfs_unregister_blkdev(SD_MAJOR(i), "sd");

This code will do nasty things if td_template.dev_max=0, namely loop for a
very long time. The condition becomes:
> for (i = 0; i <= (sd_template.dev_max - 1) / SCSI_DISKS_PER_MAJOR; i++)
> = for (i = 0; i <= (0 - 1) / 16; i++)
> = for (i = 0; i <= 0xFFFFFFFF / 16; i++)
   
The solution seems to be to use the macros and make the loop look like:
>#define N_USED_SCSI_DISKS (sd_template.dev_max + SCSI_DISKS_PER_MAJOR -1)
>#define N_USED_SD_MAJORS (N_USED_SCSI_DISKS / SCSI_DISKS_PER_MAJOR)
NEW_CODE:
> for (i = 0; i < N_USED_SD_MAJORS; i++)
> devfs_unregister_blkdev(SD_MAJOR(i), "sd");
Seems like a good idea to use the macros that are already defined.

This offending loop seems to be in the code 4 times
(lines 1033, 1145, 1353, 1382)

I have experienced this problem in 2.4.0test kernels but a quick
inspection of 2.2.x reveals that it has the same code and probably the
same problem.

Attacted are fixes for test9-2 and 2.2.17. This is my first patch to the
list so please give it a glance before applying. I have tested this
patch only on a machine without scsi disks.

-jeff

  ------------------------------------------------------------------------
       Jeff Raubitschek
       DynaByte Systems
       raubitsj@DynaByteSystems.com





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



This archive was generated by hypermail 2b29 : Sat Sep 23 2000 - 21:00:17 EST