patch-2.4.4 linux/drivers/scsi/megaraid.c

Next file: linux/drivers/scsi/megaraid.h
Previous file: linux/drivers/scsi/ips.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.3/linux/drivers/scsi/megaraid.c linux/drivers/scsi/megaraid.c
@@ -75,7 +75,7 @@
  *     Changed megaraid_command to use wait_queue.
  *
  * Version 1.00:
- *     Checks to see if an irq ocurred while in isr, and runs through
+ *     Checks to see if an irq occurred while in isr, and runs through
  *       routine again.
  *     Copies mailbox to temp area before processing in isr
  *     Added barrier() in busy wait to fix volatility bug
@@ -293,6 +293,9 @@
  *	Left 2.0 support but removed 2.1.x support.
  *	Collected much of the compat glue into one spot
  *
+ *	Version 1.14g-ac2 - 22/03/01
+ *	Fixed a non obvious dereference after free in the driver unload path
+ *
  * BUGS:
  *     Some older 2.1 kernels (eg. 2.1.90) have a bug in pci.c that
  *     fails to detect the controller as a pci device on the system.
@@ -391,6 +394,11 @@
 	writel (value, megaCfg->base + 0x2C);
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)	/* 0x020200 */
+#include <linux/smp.h>
+#define cpuid smp_processor_id()
+#endif
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)	/* 0x020100 */
 
 /*
@@ -401,9 +409,6 @@
  *	queue task is a simple api without irq forms
  */
 
-#include <linux/smp.h>
-#define cpuid smp_processor_id()
-
 MODULE_AUTHOR ("American Megatrends Inc.");
 MODULE_DESCRIPTION ("AMI MegaRAID driver");
 
@@ -428,10 +433,8 @@
  *	No pci region api
  *	queue_task is now a single simple API
  */
- 
-#include <linux/smp.h>
-#define cpuid smp_processor_id()
 
+static char kernel_version[] = UTS_RELEASE;
 MODULE_AUTHOR ("American Megatrends Inc.");
 MODULE_DESCRIPTION ("AMI MegaRAID driver");
 
@@ -2507,6 +2510,7 @@
 		if (!host)
 			goto err_unmap;
 
+		scsi_set_pci_device(host, pdev);
 		megaCfg = (mega_host_config *) host->hostdata;
 		memset (megaCfg, 0, sizeof (mega_host_config));
 
@@ -2764,7 +2768,6 @@
 			     sizeof (mega_mailbox64),
 			     (void *) megaCfg->mailbox64ptr,
 			     megaCfg->dma_handle64);
-	scsi_unregister (pSHost);
 
 #ifdef CONFIG_PROC_FS
 	if (megaCfg->controller_proc_dir_entry) {
@@ -2785,12 +2788,21 @@
 #endif
 
 	/*
+	 *	Release the controller memory. A word of warning this frees
+	 *	hostdata and that includes megaCfg-> so be careful what you
+	 *	dereference beyond this point
+	 */
+	 
+	scsi_unregister (pSHost);
+
+	/*
 	 * Unregister the character device interface to the driver. Ideally this
 	 * should have been done in cleanup_module routine. Since this is hidden
 	 * in file "scsi_module.c", we do it here.
 	 * major is the major number of the character device returned by call to
 	 * register_chrdev() routine.
 	 */
+
 	unregister_chrdev (major, "megadev");
 	unregister_reboot_notifier (&mega_notifier);
 
@@ -4299,12 +4311,10 @@
 }
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
-static Scsi_Host_Template driver_template = MEGARAID;
-#include "scsi_module.c"
-#else
-#ifdef MODULE
+static
+#endif				/* LINUX VERSION 2.4.XX */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0) || defined(MODULE)
 Scsi_Host_Template driver_template = MEGARAID;
 
 #include "scsi_module.c"
-#endif				/* MODULE */
-#endif				/* LINUX VERSION 2.4.XX  test */
+#endif				/* LINUX VERSION 2.4.XX || MODULE */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)