msm: smd_pkt: Logging update

Update the error conditions to log appropriate error messages. Update
the log messages to log device information. Add support to enable
and disable logging in a more granular fashion.

Change-Id: I9da188f0639f8573b058d84cc46f379133cfce54
Signed-off-by: Karthikeyan Ramasubramanian <kramasub@codeaurora.org>
diff --git a/arch/arm/mach-msm/smd_pkt.c b/arch/arm/mach-msm/smd_pkt.c
index 9ef4028..5f835a2 100644
--- a/arch/arm/mach-msm/smd_pkt.c
+++ b/arch/arm/mach-msm/smd_pkt.c
@@ -88,24 +88,65 @@
 static int msm_smd_pkt_debug_mask;
 module_param_named(debug_mask, msm_smd_pkt_debug_mask,
 		int, S_IRUGO | S_IWUSR | S_IWGRP);
+
+enum {
+	SMD_PKT_STATUS = 1U << 0,
+	SMD_PKT_READ = 1U << 1,
+	SMD_PKT_WRITE = 1U << 2,
+	SMD_PKT_READ_DUMP_BUFFER = 1U << 3,
+	SMD_PKT_WRITE_DUMP_BUFFER = 1U << 4,
+	SMD_PKT_POLL = 1U << 5,
+};
+
 #define DEBUG
 
 #ifdef DEBUG
-#define D_DUMP_BUFFER(prestr, cnt, buf) \
+#define D_STATUS(x...) \
 do { \
-	if (msm_smd_pkt_debug_mask) \
-		print_hex_dump(KERN_DEBUG, prestr, \
-				DUMP_PREFIX_NONE, 16, 1, \
-				buf, cnt, 1); \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_STATUS) \
+		pr_info("Status: "x); \
+} while (0)
+
+#define D_READ(x...) \
+do { \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_READ) \
+		pr_info("Read: "x); \
+} while (0)
+
+#define D_WRITE(x...) \
+do { \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_WRITE) \
+		pr_info("Write: "x); \
+} while (0)
+
+#define D_READ_DUMP_BUFFER(prestr, cnt, buf) \
+do { \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_READ_DUMP_BUFFER) \
+		print_hex_dump(KERN_INFO, prestr, \
+			       DUMP_PREFIX_NONE, 16, 1, \
+			       buf, cnt, 1); \
+} while (0)
+
+#define D_WRITE_DUMP_BUFFER(prestr, cnt, buf) \
+do { \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_WRITE_DUMP_BUFFER) \
+		print_hex_dump(KERN_INFO, prestr, \
+			       DUMP_PREFIX_NONE, 16, 1, \
+			       buf, cnt, 1); \
+} while (0)
+
+#define D_POLL(x...) \
+do { \
+	if (msm_smd_pkt_debug_mask & SMD_PKT_POLL) \
+		pr_info("Poll: "x); \
 } while (0)
 #else
-#define D_DUMP_BUFFER(prestr, cnt, buf) do {} while (0)
-#endif
-
-#ifdef DEBUG
-#define D(x...) if (msm_smd_pkt_debug_mask) printk(x)
-#else
-#define D(x...) do {} while (0)
+#define D_STATUS(x...) do {} while (0)
+#define D_READ(x...) do {} while (0)
+#define D_WRITE(x...) do {} while (0)
+#define D_READ_DUMP_BUFFER(prestr, cnt, buf) do {} while (0)
+#define D_WRITE_DUMP_BUFFER(prestr, cnt, buf) do {} while (0)
+#define D_POLL(x...) do {} while (0)
 #endif
 
 static ssize_t open_timeout_store(struct device *d,
@@ -171,6 +212,7 @@
 	wake_up(&smd_pkt_devp->ch_read_wait_queue);
 	wake_up(&smd_pkt_devp->ch_write_wait_queue);
 	wake_up_interruptible(&smd_pkt_devp->ch_opened_wait_queue);
+	D_STATUS("%s smd_pkt_dev id:%d\n", __func__, smd_pkt_devp->i);
 }
 
 static void loopback_probe_worker(struct work_struct *work)
@@ -195,9 +237,12 @@
 	smd_pkt_devp = container_of(work, struct smd_pkt_dev,
 				    packet_arrival_work);
 	mutex_lock(&smd_pkt_devp->ch_lock);
-	if (smd_pkt_devp->ch)
+	if (smd_pkt_devp->ch) {
+		D_READ("%s locking smd_pkt_dev id:%d wakelock\n",
+			__func__, smd_pkt_devp->i);
 		wake_lock_timeout(&smd_pkt_devp->pa_wake_lock,
 				  WAKELOCK_TIMEOUT);
+	}
 	mutex_unlock(&smd_pkt_devp->ch_lock);
 }
 
@@ -213,15 +258,20 @@
 
 	switch (cmd) {
 	case TIOCMGET:
+		D_STATUS("%s TIOCMGET command on smd_pkt_dev id:%d\n",
+			 __func__, smd_pkt_devp->i);
 		ret = smd_tiocmget(smd_pkt_devp->ch);
 		break;
 	case TIOCMSET:
+		D_STATUS("%s TIOCSET command on smd_pkt_dev id:%d\n",
+			 __func__, smd_pkt_devp->i);
 		ret = smd_tiocmset(smd_pkt_devp->ch, arg, ~arg);
 		break;
 	case SMD_PKT_IOCTL_BLOCKING_WRITE:
 		ret = get_user(smd_pkt_devp->blocking_write, (int *)arg);
 		break;
 	default:
+		pr_err("%s: Unrecognized ioctl command %d\n", __func__, cmd);
 		ret = -1;
 	}
 
@@ -240,18 +290,27 @@
 	struct smd_channel *chl;
 	unsigned long flags;
 
-	D(KERN_ERR "%s: read %i bytes\n",
-	  __func__, count);
-
 	smd_pkt_devp = file->private_data;
 
-	if (!smd_pkt_devp || !smd_pkt_devp->ch)
+	if (!smd_pkt_devp) {
+		pr_err("%s on NULL smd_pkt_dev\n", __func__);
 		return -EINVAL;
+	}
+
+	if (!smd_pkt_devp->ch) {
+		pr_err("%s on a closed smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
+		return -EINVAL;
+	}
 
 	if (smd_pkt_devp->do_reset_notification) {
 		/* notify client that a reset occurred */
+		pr_err("%s notifying reset for smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
 		return notify_reset(smd_pkt_devp);
 	}
+	D_READ("Begin %s on smd_pkt_dev id:%d buffer_size %d\n",
+		__func__, smd_pkt_devp->i, count);
 
 	chl = smd_pkt_devp->ch;
 wait_for_packet:
@@ -260,20 +319,19 @@
 				      smd_read_avail(chl)) ||
 				     smd_pkt_devp->has_reset);
 
-	if (smd_pkt_devp->has_reset)
+	if (smd_pkt_devp->has_reset) {
+		pr_err("%s notifying reset for smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
 		return notify_reset(smd_pkt_devp);
+	}
 
 	if (r < 0) {
 		/* qualify error message */
 		if (r != -ERESTARTSYS) {
 			/* we get this anytime a signal comes in */
-			printk(KERN_ERR "ERROR:%s:%i:%s: "
-			       "wait_event_interruptible ret %i\n",
-			       __FILE__,
-			       __LINE__,
-			       __func__,
-			       r
-				);
+			pr_err("%s: wait_event_interruptible on smd_pkt_dev"
+			       " id:%d ret %i\n",
+				__func__, smd_pkt_devp->i, r);
 		}
 		return r;
 	}
@@ -284,13 +342,16 @@
 	pkt_size = smd_cur_packet_size(smd_pkt_devp->ch);
 
 	if (!pkt_size) {
-		D(KERN_ERR "%s: Nothing to read\n", __func__);
+		pr_err("%s: No data on smd_pkt_dev id:%d, False wakeup\n",
+			__func__, smd_pkt_devp->i);
 		mutex_unlock(&smd_pkt_devp->rx_lock);
 		goto wait_for_packet;
 	}
 
 	if (pkt_size > count) {
-		pr_err("packet size %i > buffer size %i,", pkt_size, count);
+		pr_err("%s: failure on smd_pkt_dev id: %d - packet size %d"
+		       " > buffer size %d,", __func__, smd_pkt_devp->i,
+			pkt_size, count);
 		mutex_unlock(&smd_pkt_devp->rx_lock);
 		return -ETOOSMALL;
 	}
@@ -302,8 +363,12 @@
 					 (pkt_size - bytes_read));
 		if (r < 0) {
 			mutex_unlock(&smd_pkt_devp->rx_lock);
-			if (smd_pkt_devp->has_reset)
+			if (smd_pkt_devp->has_reset) {
+				pr_err("%s notifying reset for smd_pkt_dev"
+				       " id:%d\n", __func__, smd_pkt_devp->i);
 				return notify_reset(smd_pkt_devp);
+			}
+			pr_err("%s Error while reading %d\n", __func__, r);
 			return r;
 		}
 		bytes_read += r;
@@ -313,10 +378,12 @@
 				   smd_pkt_devp->has_reset);
 		if (smd_pkt_devp->has_reset) {
 			mutex_unlock(&smd_pkt_devp->rx_lock);
+			pr_err("%s notifying reset for smd_pkt_dev  id:%d\n",
+				__func__, smd_pkt_devp->i);
 			return notify_reset(smd_pkt_devp);
 		}
 	} while (pkt_size != bytes_read);
-	D_DUMP_BUFFER("read: ", bytes_read, buf);
+	D_READ_DUMP_BUFFER("Read: ", (bytes_read > 16 ? 16 : bytes_read), buf);
 	mutex_unlock(&smd_pkt_devp->rx_lock);
 
 	mutex_lock(&smd_pkt_devp->ch_lock);
@@ -325,12 +392,14 @@
 	    !smd_cur_packet_size(smd_pkt_devp->ch)) {
 		wake_unlock(&smd_pkt_devp->pa_wake_lock);
 		smd_pkt_devp->poll_mode = 0;
+		D_READ("%s unlocked smd_pkt_dev id:%d wakelock\n",
+			__func__, smd_pkt_devp->i);
 	}
 	spin_unlock_irqrestore(&smd_pkt_devp->pa_spinlock, flags);
 	mutex_unlock(&smd_pkt_devp->ch_lock);
 
-	D(KERN_ERR "%s: just read %i bytes\n",
-	  __func__, bytes_read);
+	D_READ("Finished %s on smd_pkt_dev id:%d  %d bytes\n",
+		__func__, smd_pkt_devp->i, bytes_read);
 
 	/* check and wakeup read threads waiting on this device */
 	check_and_wakeup_reader(smd_pkt_devp);
@@ -347,24 +416,33 @@
 	struct smd_pkt_dev *smd_pkt_devp;
 	DEFINE_WAIT(write_wait);
 
-	D(KERN_ERR "%s: writting %i bytes\n",
-	  __func__, count);
-
 	smd_pkt_devp = file->private_data;
 
-	if (!smd_pkt_devp || !smd_pkt_devp->ch)
+	if (!smd_pkt_devp) {
+		pr_err("%s on NULL smd_pkt_dev\n", __func__);
 		return -EINVAL;
+	}
+
+	if (!smd_pkt_devp->ch) {
+		pr_err("%s on a closed smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
+		return -EINVAL;
+	}
 
 	if (smd_pkt_devp->do_reset_notification) {
+		pr_err("%s notifying reset for smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
 		/* notify client that a reset occurred */
 		return notify_reset(smd_pkt_devp);
 	}
+	D_WRITE("Begin %s on smd_pkt_dev id:%d data_size %d\n",
+		__func__, smd_pkt_devp->i, count);
 
 	mutex_lock(&smd_pkt_devp->tx_lock);
 	if (!smd_pkt_devp->blocking_write) {
 		if (smd_write_avail(smd_pkt_devp->ch) < count) {
-			D(KERN_ERR "%s: Not enough space to write\n",
-				   __func__);
+			pr_err("%s: Not enough space in smd_pkt_dev id:%d\n",
+				   __func__, smd_pkt_devp->i);
 			mutex_unlock(&smd_pkt_devp->tx_lock);
 			return -ENOMEM;
 		}
@@ -373,7 +451,8 @@
 	r = smd_write_start(smd_pkt_devp->ch, count);
 	if (r < 0) {
 		mutex_unlock(&smd_pkt_devp->tx_lock);
-		pr_err("%s: Error %d @ smd_write_start\n", __func__, r);
+		pr_err("%s: Error:%d in smd_pkt_dev id:%d @ smd_write_start\n",
+			__func__, r, smd_pkt_devp->i);
 		return r;
 	}
 
@@ -391,6 +470,8 @@
 
 		if (smd_pkt_devp->has_reset) {
 			mutex_unlock(&smd_pkt_devp->tx_lock);
+			pr_err("%s notifying reset for smd_pkt_dev id:%d\n",
+				__func__, smd_pkt_devp->i);
 			return notify_reset(smd_pkt_devp);
 		} else {
 			r = smd_write_segment(smd_pkt_devp->ch,
@@ -398,17 +479,22 @@
 					      (count - bytes_written), 1);
 			if (r < 0) {
 				mutex_unlock(&smd_pkt_devp->tx_lock);
-				if (smd_pkt_devp->has_reset)
+				if (smd_pkt_devp->has_reset) {
+					pr_err("%s notifying reset for"
+					       " smd_pkt_dev id:%d\n",
+						__func__, smd_pkt_devp->i);
 					return notify_reset(smd_pkt_devp);
+				}
 			}
 			bytes_written += r;
 		}
 	} while (bytes_written != count);
 	smd_write_end(smd_pkt_devp->ch);
 	mutex_unlock(&smd_pkt_devp->tx_lock);
-
-	D(KERN_ERR "%s: just wrote %i bytes\n",
-	       __func__, count);
+	D_WRITE_DUMP_BUFFER("Write: ",
+			    (bytes_written > 16 ? 16 : bytes_written), buf);
+	D_WRITE("Finished %s on smd_pkt_dev id:%d %d bytes\n",
+		__func__, smd_pkt_devp->i, count);
 
 	return count;
 }
@@ -419,13 +505,18 @@
 	unsigned int mask = 0;
 
 	smd_pkt_devp = file->private_data;
-	if (!smd_pkt_devp)
+	if (!smd_pkt_devp) {
+		pr_err("%s on a NULL device\n", __func__);
 		return POLLERR;
+	}
 
 	smd_pkt_devp->poll_mode = 1;
 	poll_wait(file, &smd_pkt_devp->ch_read_wait_queue, wait);
-	if (smd_read_avail(smd_pkt_devp->ch))
+	if (smd_read_avail(smd_pkt_devp->ch)) {
 		mask |= POLLIN | POLLRDNORM;
+		D_POLL("%s sets POLLIN for smd_pkt_dev id: %d\n",
+			__func__, smd_pkt_devp->i);
+	}
 
 	return mask;
 }
@@ -435,18 +526,27 @@
 	int sz;
 	unsigned long flags;
 
-	if (!smd_pkt_devp || !smd_pkt_devp->ch)
+	if (!smd_pkt_devp) {
+		pr_err("%s on a NULL device\n", __func__);
 		return;
+	}
+
+	if (!smd_pkt_devp->ch) {
+		pr_err("%s on a closed smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
+		return;
+	}
 
 	sz = smd_cur_packet_size(smd_pkt_devp->ch);
 	if (sz == 0) {
-		D(KERN_ERR "%s: packet size is 0\n", __func__);
+		D_READ("%s: No packet in smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
 		return;
 	}
 	if (!smd_read_avail(smd_pkt_devp->ch)) {
-		D(KERN_ERR "%s: packet size is %i - "
-		  "but the data isn't here\n",
-		  __func__, sz);
+		D_READ("%s: packet size is %d in smd_pkt_dev id:%d -"
+			" but the data isn't here\n",
+			__func__, sz, smd_pkt_devp->i);
 		return;
 	}
 
@@ -456,20 +556,28 @@
 	wake_lock(&smd_pkt_devp->pa_wake_lock);
 	spin_unlock_irqrestore(&smd_pkt_devp->pa_spinlock, flags);
 	schedule_work(&smd_pkt_devp->packet_arrival_work);
-	D(KERN_ERR "%s: after wake_up\n", __func__);
+	D_READ("%s: wake_up smd_pkt_dev id:%d\n", __func__, smd_pkt_devp->i);
 }
 
 static void check_and_wakeup_writer(struct smd_pkt_dev *smd_pkt_devp)
 {
 	int sz;
 
-	if (!smd_pkt_devp || !smd_pkt_devp->ch)
+	if (!smd_pkt_devp) {
+		pr_err("%s on a NULL device\n", __func__);
 		return;
+	}
+
+	if (!smd_pkt_devp->ch) {
+		pr_err("%s on a closed smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
+		return;
+	}
 
 	sz = smd_write_avail(smd_pkt_devp->ch);
 	if (sz) {
-		D(KERN_ERR "%s: %d bytes Write Space available\n",
-			    __func__, sz);
+		D_WRITE("%s: %d bytes write space in smd_pkt_dev id:%d\n",
+			__func__, sz, smd_pkt_devp->i);
 		smd_disable_read_intr(smd_pkt_devp->ch);
 		wake_up(&smd_pkt_devp->ch_write_wait_queue);
 	}
@@ -479,31 +587,32 @@
 {
 	struct smd_pkt_dev *smd_pkt_devp = priv;
 
-	if (smd_pkt_devp->ch == 0)
+	if (smd_pkt_devp->ch == 0) {
+		pr_err("%s on a closed smd_pkt_dev id:%d\n",
+			__func__, smd_pkt_devp->i);
 		return;
+	}
 
 	switch (event) {
 	case SMD_EVENT_DATA: {
-		D(KERN_ERR "%s: data\n", __func__);
+		D_STATUS("%s: DATA event in smd_pkt_dev id:%d\n",
+			 __func__, smd_pkt_devp->i);
 		check_and_wakeup_reader(smd_pkt_devp);
 		if (smd_pkt_devp->blocking_write)
 			check_and_wakeup_writer(smd_pkt_devp);
-		D(KERN_ERR "%s: data after check_and_wakeup\n", __func__);
 		break;
 	}
 	case SMD_EVENT_OPEN:
-		D(KERN_ERR "%s: smd opened\n",
-		  __func__);
-
+		D_STATUS("%s: OPEN event in smd_pkt_dev id:%d\n",
+			  __func__, smd_pkt_devp->i);
 		smd_pkt_devp->has_reset = 0;
 		smd_pkt_devp->is_open = 1;
 		wake_up_interruptible(&smd_pkt_devp->ch_opened_wait_queue);
 		break;
 	case SMD_EVENT_CLOSE:
+		D_STATUS("%s: CLOSE event in smd_pkt_dev id:%d\n",
+			  __func__, smd_pkt_devp->i);
 		smd_pkt_devp->is_open = 0;
-		printk(KERN_ERR "%s: smd closed\n",
-		       __func__);
-
 		/* put port into reset state */
 		clean_and_signal(smd_pkt_devp);
 		if (smd_pkt_devp->i == LOOPBACK_INX)
@@ -591,6 +700,8 @@
 	for (i = 0; i < NUM_SMD_PKT_PORTS; i++) {
 		if (!strncmp(pdev->name, smd_ch_name[i], SMD_MAX_CH_NAME_LEN)) {
 			complete_all(&smd_pkt_devp[i]->ch_allocated);
+			D_STATUS("%s allocated SMD ch for smd_pkt_dev id:%d\n",
+				 __func__, i);
 			break;
 		}
 	}
@@ -614,8 +725,11 @@
 
 	smd_pkt_devp = container_of(inode->i_cdev, struct smd_pkt_dev, cdev);
 
-	if (!smd_pkt_devp)
+	if (!smd_pkt_devp) {
+		pr_err("%s on a NULL device\n", __func__);
 		return -EINVAL;
+	}
+	D_STATUS("Begin %s on smd_pkt_dev id:%d\n", __func__, smd_pkt_devp->i);
 
 	wake_lock_init(&smd_pkt_devp->pa_wake_lock, WAKE_LOCK_SUSPEND,
 			smd_pkt_dev_name[smd_pkt_devp->i]);
@@ -643,6 +757,9 @@
 			smd_pkt_devp->pil = pil_get(peripheral);
 			if (IS_ERR(smd_pkt_devp->pil)) {
 				r = PTR_ERR(smd_pkt_devp->pil);
+				pr_err("%s failed on smd_pkt_dev id:%d -"
+				       " pil_get failed for %s\n", __func__,
+					smd_pkt_devp->i, peripheral);
 				goto release_pd;
 			}
 
@@ -672,8 +789,9 @@
 				if (r == 0)
 					r = -ETIMEDOUT;
 				if (r < 0) {
-					pr_err("%s: wait failed for smd port:"
-					       " %d\n", __func__, r);
+					pr_err("%s: wait on smd_pkt_dev id:%d"
+					       " allocation failed rc:%d\n",
+						__func__, smd_pkt_devp->i, r);
 					goto release_pil;
 				}
 			}
@@ -697,16 +815,19 @@
 			r = -ETIMEDOUT;
 
 		if (r < 0) {
-			pr_err("%s: wait failed for smd open: %d\n",
-			       __func__, r);
+			pr_err("%s: wait on smd_pkt_dev id:%d OPEN event failed"
+			       " rc:%d\n", __func__, smd_pkt_devp->i, r);
 		} else if (!smd_pkt_devp->is_open) {
-			pr_err("%s: Invalid open notification\n", __func__);
+			pr_err("%s: Invalid OPEN event on smd_pkt_dev id:%d\n",
+				__func__, smd_pkt_devp->i);
 			r = -ENODEV;
 		} else {
 			smd_disable_read_intr(smd_pkt_devp->ch);
 			smd_pkt_devp->ch_size =
 				smd_write_avail(smd_pkt_devp->ch);
 			r = 0;
+			D_STATUS("Finished %s on smd_pkt_dev id:%d\n",
+				 __func__, smd_pkt_devp->i);
 		}
 	}
 release_pil:
@@ -730,8 +851,12 @@
 	int r = 0;
 	struct smd_pkt_dev *smd_pkt_devp = file->private_data;
 
-	if (!smd_pkt_devp)
+	if (!smd_pkt_devp) {
+		pr_err("%s on a NULL device\n", __func__);
 		return -EINVAL;
+	}
+	D_STATUS("Begin %s on smd_pkt_dev id:%d\n",
+		 __func__, smd_pkt_devp->i);
 
 	clean_and_signal(smd_pkt_devp);
 
@@ -750,6 +875,8 @@
 	smd_pkt_devp->has_reset = 0;
 	smd_pkt_devp->do_reset_notification = 0;
 	wake_lock_destroy(&smd_pkt_devp->pa_wake_lock);
+	D_STATUS("Finished %s on smd_pkt_dev id:%d\n",
+		 __func__, smd_pkt_devp->i);
 
 	return r;
 }
@@ -774,22 +901,14 @@
 			       NUM_SMD_PKT_PORTS,
 			       DEVICE_NAME);
 	if (IS_ERR_VALUE(r)) {
-		printk(KERN_ERR "ERROR:%s:%i:%s: "
-		       "alloc_chrdev_region() ret %i.\n",
-		       __FILE__,
-		       __LINE__,
-		       __func__,
-		       r);
+		pr_err("%s: alloc_chrdev_region() failed ret:%i\n",
+		       __func__, r);
 		goto error0;
 	}
 
 	smd_pkt_classp = class_create(THIS_MODULE, DEVICE_NAME);
 	if (IS_ERR(smd_pkt_classp)) {
-		printk(KERN_ERR "ERROR:%s:%i:%s: "
-		       "class_create() ENOMEM\n",
-		       __FILE__,
-		       __LINE__,
-		       __func__);
+		pr_err("%s: class_create() failed ENOMEM\n", __func__);
 		r = -ENOMEM;
 		goto error1;
 	}
@@ -798,10 +917,8 @@
 		smd_pkt_devp[i] = kzalloc(sizeof(struct smd_pkt_dev),
 					 GFP_KERNEL);
 		if (IS_ERR(smd_pkt_devp[i])) {
-			printk(KERN_ERR "ERROR:%s:%i:%s kmalloc() ENOMEM\n",
-			       __FILE__,
-			       __LINE__,
-			       __func__);
+			pr_err("%s: kzalloc() failed for smd_pkt_dev id:%d\n",
+				__func__, i);
 			r = -ENOMEM;
 			goto error2;
 		}
@@ -827,11 +944,8 @@
 			     1);
 
 		if (IS_ERR_VALUE(r)) {
-			printk(KERN_ERR "%s:%i:%s: cdev_add() ret %i\n",
-			       __FILE__,
-			       __LINE__,
-			       __func__,
-			       r);
+			pr_err("%s: cdev_add() failed for smd_pkt_dev id:%d"
+			       " ret:%i\n", __func__, i, r);
 			kfree(smd_pkt_devp[i]);
 			goto error2;
 		}
@@ -844,11 +958,8 @@
 				      smd_pkt_dev_name[i]);
 
 		if (IS_ERR(smd_pkt_devp[i]->devicep)) {
-			printk(KERN_ERR "%s:%i:%s: "
-			       "device_create() ENOMEM\n",
-			       __FILE__,
-			       __LINE__,
-			       __func__);
+			pr_err("%s: device_create() failed for smd_pkt_dev"
+			       " id:%d\n", __func__, i);
 			r = -ENOMEM;
 			cdev_del(&smd_pkt_devp[i]->cdev);
 			kfree(smd_pkt_devp[i]);
@@ -856,13 +967,13 @@
 		}
 		if (device_create_file(smd_pkt_devp[i]->devicep,
 					&dev_attr_open_timeout))
-			pr_err("%s: unable to create device attr on #%d\n",
-				__func__, i);
+			pr_err("%s: unable to create device attr for"
+			       " smd_pkt_dev id:%d\n", __func__, i);
 	}
 
 	INIT_DELAYED_WORK(&loopback_work, loopback_probe_worker);
 
-	D(KERN_INFO "SMD Packet Port Driver Initialized.\n");
+	D_STATUS("SMD Packet Port Driver Initialized.\n");
 	return 0;
 
  error2: