Index: drivers/dahdi/tor2.c
===================================================================
--- drivers/dahdi/tor2.c	(revision 5117)
+++ drivers/dahdi/tor2.c	(working copy)
@@ -98,7 +98,7 @@
 	volatile unsigned char *mem8;	/* Virtual representation of 8 bit Xilinx memory area */
 	struct dahdi_span spans[SPANS_PER_CARD];		/* Spans */
 	struct tor2_span tspans[SPANS_PER_CARD];	/* Span data */
-	struct dahdi_chan **chans[SPANS_PER_CARD];		/* Pointers to blocks of 24(30/31) contiguous dahdi_chans for each span */
+	struct dahdi_chan **chans[SPANS_PER_CARD]; /* Pointers to card channels */
 	struct tor2_chan tchans[32 * SPANS_PER_CARD];	/* Channel user data */
 	unsigned char txsigs[SPANS_PER_CARD][16];	/* Copy of tx sig registers */
 	int loopupcnt[SPANS_PER_CARD];	/* loop up code counter */
@@ -257,7 +257,11 @@
 static void init_spans(struct tor2 *tor)
 {
 	int x, y, c;
+	/* TODO: a debug printk macro */
 	for (x = 0; x < SPANS_PER_CARD; x++) {
+		if (debug)
+			printk(KERN_DEBUG "%s: starting span %d.\n", 
+					__FUNCTION__, x);
 		sprintf(tor->spans[x].name, "Tor2/%d/%d", tor->num, x + 1);
 		snprintf(tor->spans[x].desc, sizeof(tor->spans[x].desc) - 1,
 			 "Tormenta 2 (PCI) Quad %s Card %d Span %d",
@@ -294,6 +298,9 @@
 		init_waitqueue_head(&tor->spans[x].maintq);
 		for (y=0;y<tor->spans[x].channels;y++) {
 			struct dahdi_chan *mychans = tor->chans[x][y];
+			if (debug)
+				printk(KERN_DEBUG "%s: span %d channel %d.\n", 
+						__FUNCTION__, x, y);
 			sprintf(mychans->name, "Tor2/%d/%d/%d", tor->num, x + 1, y + 1);
 			mychans->sigcap = DAHDI_SIG_EM | DAHDI_SIG_CLEAR | DAHDI_SIG_FXSLS | DAHDI_SIG_FXSGS | DAHDI_SIG_FXSKS |
  									 DAHDI_SIG_FXOLS | DAHDI_SIG_FXOGS | DAHDI_SIG_FXOKS | DAHDI_SIG_CAS | DAHDI_SIG_SF | DAHDI_SIG_EM_E1;
@@ -304,6 +311,8 @@
 			tor->tchans[c].tor = tor;
 		}
 	}
+	if (debug)
+		printk(KERN_DEBUG "%s: spans initialized.\n", __FUNCTION__);
 }
 
 static int __devinit tor2_launch(struct tor2 *tor)
@@ -349,6 +358,8 @@
 			if (tor->chans[x][f]) {
 				kfree(tor->chans[x][f]);
 			}
+			if (tor->chans[x])
+				kfree(tor->chans[x]);
 		}
 	}
 	kfree(tor);
@@ -357,6 +368,7 @@
 static int __devinit tor2_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 {
 	int res,x,f;
+	int ret = -ENODEV;
 	struct tor2 *tor;
 	unsigned long endjif;
 	volatile unsigned long *gpdata_io,*lasdata_io;
@@ -429,7 +441,7 @@
 		if (!cards[x]) break;
 	}
 	if (x >= MAX_TOR_CARDS) {
-		printk(KERN_DEBUG "No cards[] slot available!!\n");
+		printk(KERN_ERR "No cards[] slot available!!\n");
 		goto err_out_release_all;
 	}
 	tor->num = x;
@@ -450,21 +462,21 @@
 	while (le32_to_cpu(*gpdata_io) & (GPIO_INIT | GPIO_DONE) && (jiffies <= endjif));
 
 	if (endjif < jiffies) {
-		printk(KERN_DEBUG "Timeout waiting for INIT and DONE to go low\n");
+		printk(KERN_ERR "Timeout waiting for INIT and DONE to go low\n");
 		goto err_out_release_all;
 	}
-	if (debug) printk(KERN_DEBUG "fwload: Init and done gone to low\n");
+	if (debug) printk(KERN_ERR "fwload: Init and done gone to low\n");
 	gpdata |= GPIO_PROGRAM;
 	*gpdata_io = cpu_to_le32(gpdata);  /* de-activate the PROGRAM signal */
 	/* wait for INIT to go high (clearing done */
 	endjif = jiffies + 10;
 	while (!(le32_to_cpu(*gpdata_io) & GPIO_INIT) && (jiffies <= endjif));
 	if (endjif < jiffies) {
-		printk(KERN_DEBUG "Timeout waiting for INIT to go high\n");
+		printk(KERN_ERR "Timeout waiting for INIT to go high\n");
 		goto err_out_release_all;
 	}
 
-	if (debug) printk(KERN_DEBUG "fwload: Init went high (clearing done)\nNow loading...\n");
+	if (debug) printk(KERN_ERR "fwload: Init went high (clearing done)\nNow loading...\n");
 	/* assert WRITE signal */
 	gpdata &= ~GPIO_WRITE;
 	*gpdata_io = cpu_to_le32(gpdata);
@@ -491,12 +503,12 @@
 	while (jiffies < endjif); /* wait */
 	if (!(le32_to_cpu(*gpdata_io) & GPIO_INIT))
 	   {
-		printk(KERN_NOTICE "Drove Init low!! CRC Error!!!\n");
+		printk(KERN_ERR "Drove Init low!! CRC Error!!!\n");
 		goto err_out_release_all;
 	   }
 	if (!(le32_to_cpu(*gpdata_io) & GPIO_DONE))
 	   {
-		printk(KERN_DEBUG "Did not get DONE signal. Short file maybe??\n");
+		printk(KERN_ERR "Did not get DONE signal. Short file maybe??\n");
 		goto err_out_release_all;
 	   }
 	printk(KERN_INFO "Xilinx Chip successfully loaded, configured and started!!\n");
@@ -545,9 +557,18 @@
 	}
 
 	for (x = 0; x < SPANS_PER_CARD; x++) {
+		
+		if (!(tor->chans[x] = kmalloc(sizeof(*tor->chans[x]), GFP_KERNEL))) {
+			printk(KERN_ERR "tor2: Not enough memory for chans[%d]\n", x);
+			ret = -ENOMEM;
+			goto err_out_release_all;
+		}
 		for (f = 0; f < (tor->cardtype == TYPE_E1 ? 31 : 24); f++) {
 			if (!(tor->chans[x][f] = kmalloc(sizeof(*tor->chans[x][f]), GFP_KERNEL))) {
-				return -ENOMEM;
+				printk(KERN_ERR "tor2: Not enough memory for chans[%d][%d]\n", 
+						x, f);
+				ret = -ENOMEM;
+				goto err_out_release_all;
 			}
 			memset(tor->chans[x][f], 0, sizeof(*tor->chans[x][f]));
 		}
