Linus, I think that patch below should fix procfs-related problems
with USB SCSI (including ->host_no overflows). I don't have the hardware,
so it's completely untested, but I think that it should work better than
the original code (back when it compiled, that is ;-)
        Impact for other drivers: none. Final version of procfs-related
rules for SCSI drivers:
        a) If tpnt->detect() gives positive it should leave ->proc_dir
NULL and set ->proc_name to the name you are claiming in /proc/scsi.
        b) You can't claim the name of already existing directory.
        c) Driver should leave ->proc_dir alone - scsi_unregister_host()
will take care of it.
        d) If ->proc_name is set to constant string - leave it alone, if you
had allocated it (kmalloc, whatever) - free it along with Scsi_Host_Template
(after scsi_unregister_host()).
        That's it.
                                                        Cheers,
                                                                Al
diff -urN linux-2.3.28/drivers/scsi/BusLogic.h linux-bird.scsi/drivers/scsi/BusLogic.h
--- linux-2.3.28/drivers/scsi/BusLogic.h        Thu Nov 11 22:07:53 1999
+++ linux-bird.scsi/drivers/scsi/BusLogic.h     Sat Nov 13 14:16:55 1999
@@ -35,7 +35,6 @@
 */
 
 typedef kdev_t KernelDevice_T;
-typedef struct proc_dir_entry PROC_DirectoryEntry_T;
 typedef unsigned long ProcessorFlags_T;
 typedef struct pt_regs Registers_T;
 typedef struct partition PartitionTable_T;
diff -urN linux-2.3.28/drivers/scsi/hosts.c linux-bird.scsi/drivers/scsi/hosts.c
--- linux-2.3.28/drivers/scsi/hosts.c   Thu Nov 11 22:07:55 1999
+++ linux-bird.scsi/drivers/scsi/hosts.c        Sat Nov 13 14:18:47 1999
@@ -703,8 +703,6 @@
     retval->loaded_as_module = scsi_loadable_module_flag;
     retval->host_no = max_scsi_hosts++; /* never reuse host_no (DB) */
     next_scsi_host++;
-    /* FIXME: what with overflows? Old code suffered from the same, BTW */
-    sprintf(retval->proc_name, "%d", retval->host_no);
     retval->host_queue = NULL;
     init_waitqueue_head(&retval->host_wait);
     retval->resetting = 0;
diff -urN linux-2.3.28/drivers/scsi/hosts.h linux-bird.scsi/drivers/scsi/hosts.h
--- linux-2.3.28/drivers/scsi/hosts.h   Thu Nov 11 22:07:55 1999
+++ linux-bird.scsi/drivers/scsi/hosts.h        Sat Nov 13 14:18:18 1999
@@ -327,7 +327,6 @@
 /* public: */
     unsigned short extra_bytes;
     unsigned short host_no;  /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
-    char proc_name[4];
     int resetting; /* if set, it means that last_reset is a valid value */
     unsigned long last_reset;
 
diff -urN linux-2.3.28/drivers/scsi/scsi.c linux-bird.scsi/drivers/scsi/scsi.c
--- linux-2.3.28/drivers/scsi/scsi.c    Thu Nov 11 22:07:57 1999
+++ linux-bird.scsi/drivers/scsi/scsi.c Sat Nov 13 14:23:28 1999
@@ -2746,6 +2746,7 @@
        struct Scsi_Host *shpnt;
        Scsi_Host_Template *SHT;
        Scsi_Host_Template *SHTp;
+       char name[10];  /* host_no>=10^9? I don't think so. */
 
        /*
         * First verify that this host adapter is completely free with no pending
@@ -2887,7 +2888,8 @@
                        continue;
                pcount = next_scsi_host;
                /* Remove the /proc/scsi directory entry */
-               remove_proc_entry(shpnt->proc_name, tpnt->proc_dir);
+               sprintf(name,"%d",shpnt->host_no);
+               remove_proc_entry(name, tpnt->proc_dir);
                if (tpnt->release)
                        (*tpnt->release) (shpnt);
                else {
diff -urN linux-2.3.28/drivers/scsi/scsi_proc.c 
linux-bird.scsi/drivers/scsi/scsi_proc.c
--- linux-2.3.28/drivers/scsi/scsi_proc.c       Thu Nov 11 22:07:58 1999
+++ linux-bird.scsi/drivers/scsi/scsi_proc.c    Sat Nov 13 14:24:32 1999
@@ -118,6 +118,7 @@
 void build_proc_dir_entries(Scsi_Host_Template * tpnt)
 {
        struct Scsi_Host *hpnt;
+       char name[10];  /* see scsi_unregister_host() */
 
        tpnt->proc_dir = create_proc_entry(tpnt->proc_name, S_IFDIR, proc_scsi);
        tpnt->proc_dir->owner = tpnt->module;
@@ -126,7 +127,8 @@
        while (hpnt) {
                if (tpnt == hpnt->hostt) {
                        struct proc_dir_entry *p;
-                       p = create_proc_read_entry(hpnt->proc_name,
+                       sprintf(name,"%d",hpnt->host_no);
+                       p = create_proc_read_entry(name,
                                        S_IFREG | S_IRUGO | S_IWUSR,
                                        tpnt->proc_dir,
                                        proc_scsi_read,
diff -urN linux-2.3.28/drivers/usb/usb_scsi.c linux-bird.scsi/drivers/usb/usb_scsi.c
--- linux-2.3.28/drivers/usb/usb_scsi.c Fri Nov 12 22:05:16 1999
+++ linux-bird.scsi/drivers/usb/usb_scsi.c      Sat Nov 13 14:31:17 1999
@@ -114,15 +114,6 @@
 #define US_ACT_BUS_RESET       4
 #define US_ACT_HOST_RESET      5
 
-static struct proc_dir_entry proc_usb_scsi =
-{
-    PROC_SCSI_USB_SCSI,                /* It's currently b0rken */
-    0,
-    NULL,
-    S_IFDIR | S_IRUGO | S_IXUGO,
-    2
-};
-
 static struct us_data *us_list;
 
 static struct usb_scsi_filter *filters;
@@ -615,26 +606,19 @@
     char name[32];
 
     sprintf(name, "usbscsi%d", us->host_number);
-    proc_usb_scsi.namelen = strlen(name);
-    proc_usb_scsi.name = kmalloc(proc_usb_scsi.namelen+1, GFP_KERNEL);
-    if (!proc_usb_scsi.name)
+    sht->name = sht->proc_name = kmalloc(strlen(name)+1, GFP_KERNEL);
+    if (!sht->proc_name)
        return 0;
-    strcpy((char *)proc_usb_scsi.name, name);
-    sht->proc_dir = kmalloc(sizeof(*sht->proc_dir), GFP_KERNEL);
-    if (!sht->proc_dir) {
-       kfree(proc_usb_scsi.name);
-       return 0;
-    }
-    *sht->proc_dir = proc_usb_scsi;
-    sht->name = proc_usb_scsi.name;
+    strcpy(sht->proc_name, name);
+    sht->proc_dir = NULL;
     us->host = scsi_register(sht, sizeof(us));
     if (us->host) {
        us->host->hostdata[0] = (unsigned long)us;
        us->host_no = us->host->host_no;
        return 1;
     }
-    kfree(proc_usb_scsi.name);
-    kfree(sht->proc_dir);
+    kfree(sht->proc_name);
+    sht->proc_name = sht->name = NULL;
     return 0;
 }
 


-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [EMAIL PROTECTED]

Reply via email to