Date:        Thu, 12 Oct 2000 12:48:27 -0700 (PDT)
   From: Linus Torvalds <[EMAIL PROTECTED]>

   David, you know this code, would you mind giving it another pair of
   eyes?  I hate code that doesn't make sense.

Ok, the deal is that the tpnt->present handling during unregister is
really broken.  There is no way for the "if" conditional in question
to differentiate between the following two cases:

1) No host adapters for this tpnt were ever registered
2) All host adapters for this tpns were successfully
   removed by this loop above the test in question:

        /* Next we go through and remove the instances of the individual hosts
         * that were detected */

        pcount0 = next_scsi_host;
        for (shpnt = scsi_hostlist; shpnt; shpnt = sh1) {

Both events leave us with tpnt->present == 0, but only in the #2 case
do we want to do the unlink and procfs deletions.

It's very easy to fix, Torben can you try this (untested) patch?

--- drivers/scsi/scsi.c.~1~     Wed Oct  4 16:11:38 2000
+++ drivers/scsi/scsi.c Thu Oct 12 18:45:06 2000
@@ -1976,6 +1976,7 @@
        struct Scsi_Host *sh1;
        struct Scsi_Host *shpnt;
        char name[10];  /* host_no>=10^9? I don't think so. */
+        int orig_present;
 
        /*
         * First verify that this host adapter is completely free with no pending
@@ -2109,6 +2110,7 @@
         * that were detected */
 
        pcount0 = next_scsi_host;
+        orig_present = tpnt->present;
        for (shpnt = scsi_hostlist; shpnt; shpnt = sh1) {
                sh1 = shpnt->next;
                if (shpnt->hostt != tpnt)
@@ -2155,8 +2157,11 @@
               (scsi_memory_upper_value - scsi_init_memory_start) / 1024);
 #endif
 
-       /* Remove it from the linked list and /proc */
-       if (tpnt->present) {
+       /* Remove it from the linked list and /proc, but only if
+         * any hosts were registered to begin with _and_ we were
+         * able to remove all of them above.
+         */
+       if (orig_present && !tpnt->present) {
                Scsi_Host_Template **SHTp = &scsi_hosts;
                Scsi_Host_Template *SHT;
 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
Please read the FAQ at http://www.tux.org/lkml/

Reply via email to