linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: gregkh@linuxfoundation.org
Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH 03/24] n_hdlc: convert debuglevel use to pr_debug
Date: Wed, 19 Feb 2020 09:40:57 +0100	[thread overview]
Message-ID: <20200219084118.26491-3-jslaby@suse.cz> (raw)
In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz>

With pr_debug we have a fine-grained control about debugging prints. So
convert the use of global debuglevel variable and tests to a commonly
used pr_debug. And drop debuglevel completely.

This also implicitly adds a loglevel to the messages (KERN_DEBUG) as it
was missing on most of them.

And also use __func__ instead of function names explicitly typed.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/tty/n_hdlc.c | 79 +++++++++++++++++---------------------------
 1 file changed, 31 insertions(+), 48 deletions(-)

diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c
index 881da4d440c8..e37dab2528a1 100644
--- a/drivers/tty/n_hdlc.c
+++ b/drivers/tty/n_hdlc.c
@@ -160,10 +160,6 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *list);
 
 static struct n_hdlc *n_hdlc_alloc (void);
 
-/* debug level can be set by insmod for debugging purposes */
-#define DEBUG_LEVEL_INFO	1
-static int debuglevel;
-
 /* max frame size for memory allocations */
 static int maxframe = 4096;
 
@@ -310,11 +306,9 @@ static int n_hdlc_tty_open (struct tty_struct *tty)
 {
 	struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
 
-	if (debuglevel >= DEBUG_LEVEL_INFO)	
-		printk("%s(%d)n_hdlc_tty_open() called (device=%s)\n",
-		__FILE__,__LINE__,
-		tty->name);
-		
+	pr_debug("%s(%d)%s() called (device=%s)\n",
+			__FILE__, __LINE__, __func__, tty->name);
+
 	/* There should not be an existing table for this slot. */
 	if (n_hdlc) {
 		printk (KERN_ERR"n_hdlc_tty_open:tty already associated!\n" );
@@ -372,10 +366,9 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
 
 	tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list);
 	while (tbuf) {
-		if (debuglevel >= DEBUG_LEVEL_INFO)	
-			printk("%s(%d)sending frame %p, count=%d\n",
-				__FILE__,__LINE__,tbuf,tbuf->count);
-			
+		pr_debug("%s(%d)sending frame %p, count=%d\n",
+				__FILE__, __LINE__, tbuf, tbuf->count);
+
 		/* Send the next block of data to device */
 		set_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
 		actual = tty->ops->write(tty, tbuf->buf, tbuf->count);
@@ -391,10 +384,9 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
 			actual = tbuf->count;
 		
 		if (actual == tbuf->count) {
-			if (debuglevel >= DEBUG_LEVEL_INFO)	
-				printk("%s(%d)frame %p completed\n",
-					__FILE__,__LINE__,tbuf);
-					
+			pr_debug("%s(%d)frame %p completed\n",
+					__FILE__, __LINE__, tbuf);
+
 			/* free current transmit buffer */
 			n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, tbuf);
 
@@ -404,9 +396,8 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty)
 			/* get next pending transmit buffer */
 			tbuf = n_hdlc_buf_get(&n_hdlc->tx_buf_list);
 		} else {
-			if (debuglevel >= DEBUG_LEVEL_INFO)	
-				printk("%s(%d)frame %p pending\n",
-					__FILE__,__LINE__,tbuf);
+			pr_debug("%s(%d)frame %p pending\n",
+					__FILE__, __LINE__, tbuf);
 
 			/*
 			 * the buffer was not accepted by driver,
@@ -467,10 +458,9 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
 	register struct n_hdlc *n_hdlc = tty2n_hdlc (tty);
 	register struct n_hdlc_buf *buf;
 
-	if (debuglevel >= DEBUG_LEVEL_INFO)	
-		printk("%s(%d)n_hdlc_tty_receive() called count=%d\n",
-			__FILE__,__LINE__, count);
-		
+	pr_debug("%s(%d)%s() called count=%d\n",
+			__FILE__, __LINE__, __func__, count);
+
 	/* This can happen if stuff comes in on the backup tty */
 	if (!n_hdlc || tty != n_hdlc->tty)
 		return;
@@ -483,9 +473,8 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
 	}
 	
 	if ( count>maxframe ) {
-		if (debuglevel >= DEBUG_LEVEL_INFO)	
-			printk("%s(%d) rx count>maxframesize, data discarded\n",
-			       __FILE__,__LINE__);
+		pr_debug("%s(%d) rx count>maxframesize, data discarded\n",
+				__FILE__, __LINE__);
 		return;
 	}
 
@@ -500,9 +489,8 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data,
 	}
 	
 	if (!buf) {
-		if (debuglevel >= DEBUG_LEVEL_INFO)	
-			printk("%s(%d) no more rx buffers, data discarded\n",
-			       __FILE__,__LINE__);
+		pr_debug("%s(%d) no more rx buffers, data discarded\n",
+				__FILE__, __LINE__);
 		return;
 	}
 		
@@ -619,10 +607,9 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
 	DECLARE_WAITQUEUE(wait, current);
 	struct n_hdlc_buf *tbuf;
 
-	if (debuglevel >= DEBUG_LEVEL_INFO)	
-		printk("%s(%d)n_hdlc_tty_write() called count=%zd\n",
-			__FILE__,__LINE__,count);
-		
+	pr_debug("%s(%d)%s() called count=%zd\n", __FILE__, __LINE__, __func__,
+			count);
+
 	/* Verify pointers */
 	if (!n_hdlc)
 		return -EIO;
@@ -632,11 +619,8 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file,
 
 	/* verify frame size */
 	if (count > maxframe ) {
-		if (debuglevel & DEBUG_LEVEL_INFO)
-			printk (KERN_WARNING
-				"n_hdlc_tty_write: truncating user packet "
-				"from %lu to %d\n", (unsigned long) count,
-				maxframe );
+		pr_debug("%s: truncating user packet from %zu to %d\n",
+				__func__, count, maxframe);
 		count = maxframe;
 	}
 	
@@ -704,10 +688,8 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
 	unsigned long flags;
 	struct n_hdlc_buf *buf = NULL;
 
-	if (debuglevel >= DEBUG_LEVEL_INFO)	
-		printk("%s(%d)n_hdlc_tty_ioctl() called %d\n",
-			__FILE__,__LINE__,cmd);
-		
+	pr_debug("%s(%d)%s() called %d\n", __FILE__, __LINE__, __func__, cmd);
+
 	/* Verify the status of the device */
 	if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC)
 		return -EBADF;
@@ -822,8 +804,9 @@ static struct n_hdlc *n_hdlc_alloc(void)
 		buf = kmalloc(struct_size(buf, buf, maxframe), GFP_KERNEL);
 		if (buf)
 			n_hdlc_buf_put(&n_hdlc->rx_free_buf_list,buf);
-		else if (debuglevel >= DEBUG_LEVEL_INFO)	
-			printk("%s(%d)n_hdlc_alloc(), kalloc() failed for rx buffer %d\n",__FILE__,__LINE__, i);
+		else
+			pr_debug("%s(%d)%s(), kmalloc() failed for rx buffer %d\n",
+					__FILE__, __LINE__, __func__, i);
 	}
 	
 	/* allocate free tx buffer list */
@@ -831,8 +814,9 @@ static struct n_hdlc *n_hdlc_alloc(void)
 		buf = kmalloc(struct_size(buf, buf, maxframe), GFP_KERNEL);
 		if (buf)
 			n_hdlc_buf_put(&n_hdlc->tx_free_buf_list,buf);
-		else if (debuglevel >= DEBUG_LEVEL_INFO)	
-			printk("%s(%d)n_hdlc_alloc(), kalloc() failed for tx buffer %d\n",__FILE__,__LINE__, i);
+		else
+			pr_debug("%s(%d)%s(), kmalloc() failed for tx buffer %d\n",
+					__FILE__, __LINE__, __func__, i);
 	}
 	
 	/* Initialize the control block */
@@ -960,6 +944,5 @@ module_exit(n_hdlc_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Paul Fulghum paulkf@microgate.com");
-module_param(debuglevel, int, 0);
 module_param(maxframe, int, 0);
 MODULE_ALIAS_LDISC(N_HDLC);
-- 
2.25.0


  parent reply	other threads:[~2020-02-19  8:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-19  8:40 [PATCH 01/24] n_hdlc: remove tracing debug prints Jiri Slaby
2020-02-19  8:40 ` [PATCH 02/24] n_hdlc: remove unused macros Jiri Slaby
2020-02-19  8:40 ` Jiri Slaby [this message]
2020-02-19 12:20   ` [PATCH 03/24] n_hdlc: convert debuglevel use to pr_debug Joe Perches
2020-02-20 12:45     ` Greg KH
2020-02-21  8:16     ` Jiri Slaby
2020-02-19  8:40 ` [PATCH 04/24] n_hdlc: put init/exit strings directly to prints Jiri Slaby
2020-02-19  8:40 ` [PATCH 05/24] n_hdlc: cleanup messages during registration Jiri Slaby
2020-02-19  8:41 ` [PATCH 06/24] n_hdlc: use clamp() for maxframe Jiri Slaby
2020-02-19  8:41 ` [PATCH 07/24] n_hdlc: simplify freeing of buffer list Jiri Slaby
2020-02-19  8:41 ` [PATCH 08/24] n_hdlc: invert conditions in n_hdlc_tty_close and n_hdlc_tty_poll Jiri Slaby
2020-02-19  8:41 ` [PATCH 09/24] n_hdlc: remove unused flags Jiri Slaby
2020-02-19  8:41 ` [PATCH 10/24] n_hdlc: remove unused backup_tty Jiri Slaby
2020-02-19  8:41 ` [PATCH 11/24] n_hdlc: expand tty2n_hdlc macro Jiri Slaby
2020-02-19  8:41 ` [PATCH 12/24] n_hdlc: inline n_hdlc_release Jiri Slaby
2020-02-19  8:41 ` [PATCH 13/24] n_hdlc: remove cached tty Jiri Slaby
2020-02-19  8:41 ` [PATCH 14/24] n_hdlc: remove checking of n_hdlc Jiri Slaby
2020-02-19  8:41 ` [PATCH 15/24] n_hdlc: add helper for buffers allocation Jiri Slaby
2020-02-19  8:41 ` [PATCH 16/24] n_hdlc: move tty_ldisc_ops to the bottom Jiri Slaby
2020-02-19  8:41 ` [PATCH 17/24] n_hdlc: switch tbusy and woke_up to bools Jiri Slaby
2020-02-19  8:41 ` [PATCH 18/24] n_hdlc: remove unneeded ifdef Jiri Slaby
2020-02-19  8:41 ` [PATCH 19/24] n_hdlc: use __func__ and pr_ print helpers Jiri Slaby
2020-02-19  8:41 ` [PATCH 20/24] n_hdlc: remove useless whitespace at line wraps Jiri Slaby
2020-02-19  8:41 ` [PATCH 21/24] n_hdlc: remove spaces between function name and ( Jiri Slaby
2020-02-19  8:41 ` [PATCH 22/24] n_hdlc: add missing spaces after commas Jiri Slaby
2020-02-19  8:41 ` [PATCH 23/24] n_hdlc: fix whitespace around binary operators Jiri Slaby
2020-02-19  8:41 ` [PATCH 24/24] n_hdlc: wrap a comment properly Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200219084118.26491-3-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).