Would the father of init_mem_lth please stand up
Subsystems (3)
Quoted 6 lines
And then, my beautiful code is not at all crap that should not have been applied. It fixes a real bug. But there was another bug there that it left, namely that the freed pointers should have been zeroed, so that nobody can come and use them with random results. If nobody else does it, I'll send also that small fix, but maybe not today.
Look at this, just a food for thought - once we start zeroing rscsi_disks, it starts popping up in places. You don't need to do it exactly this way, of course.
------------------------------------------------
* kfree(static) in sd.c.
* Fix for sd_init failures: scsi_device.detected; zeroing of xx.dev_noticed.
* "scsi_devices corrupt" == rscsi_disks pointing to kfree-d memory.
drivers/scsi/hosts.c +18 -0
@@ -275,6 +275,24 @@return 0 ; } +void +scsi_deregister_device (struct Scsi_Device_Template * tpnt) +{ +struct Scsi_Device_Template *spnt; +struct Scsi_Device_Template *prev_spnt; + + spnt = scsi_devicelist; + prev_spnt =NULL ; +while (spnt != tpnt) { + prev_spnt = spnt; + spnt = spnt->next; + } +if (prev_spnt ==NULL ) + scsi_devicelist = tpnt->next; +else + prev_spnt->next = spnt->next; +} +/* * Overrides for Emacs so that we follow Linus's tabbing style. * Emacs will notice this stuff at the end of the file and automatically
drivers/scsi/hosts.h +1 -0
@@ -526,6 +526,7 @@void scsi_initialize_queue (Scsi_Device * SDpnt,struct Scsi_Host * SHpnt);int scsi_register_device (struct Scsi_Device_Template * sdpnt); +void scsi_deregister_device (struct Scsi_Device_Template * tpnt);/* These are used by loadable modules */ extern int scsi_register_module (int ,void *);
drivers/scsi/scsi.c +17 -16
@@ -2227,7 +2227,7 @@for (SDpnt = shpnt->host_queue; SDpnt; SDpnt = SDpnt->next) {if (tpnt->detect) - SDpnt->attached += (*tpnt->detect) (SDpnt); + SDpnt->detected = (*tpnt->detect) (SDpnt); } }
@@ -2235,9 +2235,19 @@* If any of the devices would match this driver, then perform the * init function. */ -if (tpnt->init && tpnt->dev_noticed) -if ((*tpnt->init) ()) +if (tpnt->init && tpnt->dev_noticed) { +if ((*tpnt->init) ()) { +for (shpnt = scsi_hostlist; shpnt; + shpnt = shpnt->next) { +for (SDpnt = shpnt->host_queue; SDpnt; + SDpnt = SDpnt->next) { + SDpnt->detected =0 ; + } + } +scsi_deregister_device (tpnt);return 1 ; + } + }/* * Now actually connect the devices to the new driver.
@@ -2245,6 +2255,8 @@for (shpnt = scsi_hostlist; shpnt; shpnt = shpnt->next) {for (SDpnt = shpnt->host_queue; SDpnt; SDpnt = SDpnt->next) { + SDpnt->attached += SDpnt->detected; + SDpnt->detected =0 ;if (tpnt->attach) (*tpnt->attach) (SDpnt);/*
@@ -2280,9 +2292,7 @@ {Scsi_Device *SDpnt;struct Scsi_Host *shpnt; -struct Scsi_Device_Template *spnt; -struct Scsi_Device_Template *prev_spnt; - +lock_kernel ();/* * If we are busy, this is not going to fly.
@@ -2313,16 +2323,7 @@/* * Extract the template from the linked list. */ - spnt = scsi_devicelist; - prev_spnt =NULL ; -while (spnt != tpnt) { - prev_spnt = spnt; - spnt = spnt->next; - } -if (prev_spnt ==NULL ) - scsi_devicelist = tpnt->next; -else - prev_spnt->next = spnt->next; +scsi_deregister_device (tpnt);MOD_DEC_USE_COUNT ;unlock_kernel ();
drivers/scsi/scsi.h +2 -2
@@ -575,8 +575,8 @@* vendor-specific cmd's */ unsigned sector_size;/* size in bytes */ -int attached;/* # of high level drivers attached to -* this */ +int attached;/* # of high level drivers attached to this */ +int detected;/* Delta attached - don't use in drivers! */ int access_count;/* Count of open channels/mounts */ void *hostdata;/* available to low-level driver */
drivers/scsi/sd.c +32 -21
139 lines not on this page · raw message
drivers/scsi/sg.c +2 -0
@@ -1170,6 +1170,7 @@printk ("Unable to get major %d for generic SCSI device\n" ,SCSI_GENERIC_MAJOR );write_unlock_irqrestore (&sg_dev_arr_lock, iflags); + sg_template.dev_noticed =0 ;return 1 ; } sg_registered++;
@@ -1182,6 +1183,7 @@if (NULL == sg_dev_arr) {printk ("sg_init: no space for sg_dev_arr\n" );write_unlock_irqrestore (&sg_dev_arr_lock, iflags); + sg_template.dev_noticed =0 ;return 1 ; }memset (sg_dev_arr,0 , sg_template.dev_max *sizeof (Sg_device *));
drivers/scsi/sr.c +5 -0
@@ -768,6 +768,7 @@if (!sr_registered) {if (devfs_register_blkdev (MAJOR_NR ,"sr" , &cdrom_fops)) {printk ("Unable to get major %d for SCSI-CD\n" ,MAJOR_NR ); + sr_template.dev_noticed =0 ;return 1 ; } sr_registered++;
@@ -809,8 +810,10 @@kfree (sr_sizes); cleanup_cds:kfree (scsi_CDs); + scsi_CDs =NULL ; cleanup_devfs:devfs_unregister_blkdev (MAJOR_NR ,"sr" ); + sr_template.dev_noticed =0 ; sr_registered--;return 1 ; }
@@ -884,6 +887,8 @@Scsi_CD *cpnt;int i; +if (scsi_CDs ==NULL ) +return ;for (cpnt = scsi_CDs, i =0 ; i < sr_template.dev_max; i++, cpnt++)if (cpnt->device == SDp) {/*
drivers/scsi/st.c +1 -0
@@ -3722,6 +3722,7 @@write_unlock_irqrestore (&st_dev_arr_lock, flags);printk (KERN_ERR "Unable to get major %d for SCSI tapes\n" ,MAJOR_NR ); + st_template.dev_noticed =0 ;return 1 ; } st_registered++;