Skip to contentSkip to conversation

kernel_thread() audit drivers/scsi/aacraid/rx.c

patch-kj maximilian attems 1 participant 1 message Jun 21, 2004

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Cleaned up error handling for releasing IRQ's, unmapping memory and freeing device memory (dev->queues). Also, audited kernel_thread() and took appropriate action for failure.

---

 linux-2.6.7-max/drivers/scsi/aacraid/rx.c |   25 ++++++++++++++++++++-----
 1 files changed, 20 insertions(+), 5 deletions(-)
drivers/scsi/aacraid/rx.c renamed from drivers/scsi/aacraid/rx.c~kernel_thread-aacraid-rx +20 -5
diff -puN drivers/scsi/aacraid/rx.c~kernel_thread-aacraid-rx drivers/scsi/aacraid/rx.c
@@ -390,14 +390,14 @@ int aac_rx_init(struct aac_dev *dev, uns
 	 */
 	if (rx_readl(dev, IndexRegs.Mailbox[7]) & SELF_TEST_FAILED) {
 		printk(KERN_ERR "%s%d: adapter self-test failed.\n", dev->name, instance);
-		return -1;
+		goto error_iounmap;
 	}
 	/*
 	 *	Check to see if the board panic'd while booting.
 	 */
 	if (rx_readl(dev, IndexRegs.Mailbox[7]) & KERNEL_PANIC) {
 		printk(KERN_ERR "%s%d: adapter kernel panic'd.\n", dev->name, instance);
-		return -1;
+		goto error_iounmap;
 	}
 	start = jiffies;
 	/*
@@ -409,7 +409,7 @@ int aac_rx_init(struct aac_dev *dev, uns
 		{
 			status = rx_readl(dev, IndexRegs.Mailbox[7]) >> 16;
 			printk(KERN_ERR "%s%d: adapter kernel failed to start, init status = %ld.\n", dev->name, instance, status);
-			return -1;
+			goto error_iounmap;
 		}
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		schedule_timeout(1);
@@ -417,7 +417,7 @@ int aac_rx_init(struct aac_dev *dev, uns
 	if (request_irq(dev->scsi_host_ptr->irq, aac_rx_intr, SA_SHIRQ|SA_INTERRUPT, "aacraid", (void *)dev)<0) 
 	{
 		printk(KERN_ERR "%s%d: Interrupt unavailable.\n", name, instance);
-		return -1;
+		goto error_iounmap;
 	}
 	/*
 	 *	Fill in the function dispatch table.
@@ -430,15 +430,30 @@ int aac_rx_init(struct aac_dev *dev, uns
 	dev->a_ops.adapter_check_health = aac_rx_check_health;
 
 	if (aac_init_adapter(dev) == NULL)
-		return -1;
+		goto error_irq;
 	/*
 	 *	Start any kernel threads needed
 	 */
 	dev->thread_pid = kernel_thread((int (*)(void *))aac_command_thread, dev, 0);
+	if (dev->thread_pid < 0) {
+		printk(KERN_ERR "aacraid: unable to create i960 command thread.\n");
+		goto error_kfree;
+	}
 	/*
 	 *	Tell the adapter that all is configured, and it can start
 	 *	accepting requests
 	 */
 	aac_rx_start_adapter(dev);
 	return 0;
+
+error_kfree:
+	kfree(dev->queues);
+
+error_irq:
+	free_irq(dev->scsi_host_ptr->irq, (void *)dev);
+
+error_iounmap:
+	iounmap(dev->regs.rx);
+
+	return -1;
 }

_