From patchwork Wed Feb 19 08:40:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F7FFC34022 for ; Wed, 19 Feb 2020 08:43:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 46713208E4 for ; Wed, 19 Feb 2020 08:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726270AbgBSInG (ORCPT ); Wed, 19 Feb 2020 03:43:06 -0500 Received: from mx2.suse.de ([195.135.220.15]:44240 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726484AbgBSIlW (ORCPT ); Wed, 19 Feb 2020 03:41:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4AB35AE5E; Wed, 19 Feb 2020 08:41:20 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 03/24] n_hdlc: convert debuglevel use to pr_debug Date: Wed, 19 Feb 2020 09:40:57 +0100 Message-Id: <20200219084118.26491-3-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 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 --- 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); From patchwork Wed Feb 19 08:40:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214280 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05A51C34050 for ; Wed, 19 Feb 2020 08:41:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2029208E4 for ; Wed, 19 Feb 2020 08:41:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbgBSIlW (ORCPT ); Wed, 19 Feb 2020 03:41:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:44244 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726497AbgBSIlW (ORCPT ); Wed, 19 Feb 2020 03:41:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 543E5AEAC; Wed, 19 Feb 2020 08:41:20 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 04/24] n_hdlc: put init/exit strings directly to prints Date: Wed, 19 Feb 2020 09:40:58 +0100 Message-Id: <20200219084118.26491-4-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org These strings were put aside from prints to save some bytes after module load or when built-in -- they were freed after module load (__init ones) or when the driver is selected as built-in (__exit ones). The savings are negligible, but the code readability is worse by the order of magnitude. So put the strings where they belong. Note that it also used to make little sense putting const data in .data (the __exit case). While at it, switch to pr_info, pr_err, not using the KERN_INFO and _ERR directly. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index e37dab2528a1..b651b5ba64ee 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -889,13 +889,6 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list) return buf; } /* end of n_hdlc_buf_get() */ -static const char hdlc_banner[] __initconst = - KERN_INFO "HDLC line discipline maxframe=%u\n"; -static const char hdlc_register_ok[] __initconst = - KERN_INFO "N_HDLC line discipline registered.\n"; -static const char hdlc_register_fail[] __initconst = - KERN_ERR "error registering line discipline: %d\n"; - static int __init n_hdlc_init(void) { int status; @@ -906,37 +899,28 @@ static int __init n_hdlc_init(void) else if (maxframe > 65535) maxframe = 65535; - printk(hdlc_banner, maxframe); + pr_info("HDLC line discipline maxframe=%d\n", maxframe); status = tty_register_ldisc(N_HDLC, &n_hdlc_ldisc); if (!status) - printk(hdlc_register_ok); + pr_info("N_HDLC line discipline registered.\n"); else - printk(hdlc_register_fail, status); + pr_err("error registering line discipline: %d\n", status); return status; } /* end of init_module() */ -#ifdef CONFIG_SPARC -#undef __exitdata -#define __exitdata -#endif - -static const char hdlc_unregister_ok[] __exitdata = - KERN_INFO "N_HDLC: line discipline unregistered\n"; -static const char hdlc_unregister_fail[] __exitdata = - KERN_ERR "N_HDLC: can't unregister line discipline (err = %d)\n"; - static void __exit n_hdlc_exit(void) { /* Release tty registration of line discipline */ int status = tty_unregister_ldisc(N_HDLC); if (status) - printk(hdlc_unregister_fail, status); + pr_err("N_HDLC: can't unregister line discipline (err = %d)\n", + status); else - printk(hdlc_unregister_ok); + pr_info("N_HDLC: line discipline unregistered\n"); } module_init(n_hdlc_init); From patchwork Wed Feb 19 08:40:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214270 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEA8EC34050 for ; Wed, 19 Feb 2020 08:43:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8238A208E4 for ; Wed, 19 Feb 2020 08:43:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726651AbgBSIlW (ORCPT ); Wed, 19 Feb 2020 03:41:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:44252 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbgBSIlW (ORCPT ); Wed, 19 Feb 2020 03:41:22 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9FDF5AEC5; Wed, 19 Feb 2020 08:41:20 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 05/24] n_hdlc: cleanup messages during registration Date: Wed, 19 Feb 2020 09:40:59 +0100 Message-Id: <20200219084118.26491-5-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org 1) n_hdlc prints two lines during registration. Squeeze it into one. 2) prefix the error message with "N_HDLC: ", so that it's clear which ldisc failed to register. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index b651b5ba64ee..87f22e57e4f6 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -899,13 +899,13 @@ static int __init n_hdlc_init(void) else if (maxframe > 65535) maxframe = 65535; - pr_info("HDLC line discipline maxframe=%d\n", maxframe); - status = tty_register_ldisc(N_HDLC, &n_hdlc_ldisc); if (!status) - pr_info("N_HDLC line discipline registered.\n"); + pr_info("N_HDLC line discipline registered with maxframe=%d\n", + maxframe); else - pr_err("error registering line discipline: %d\n", status); + pr_err("N_HDLC: error registering line discipline: %d\n", + status); return status; From patchwork Wed Feb 19 08:41:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC8C9C3404D for ; Wed, 19 Feb 2020 08:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 92D83208E4 for ; Wed, 19 Feb 2020 08:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726712AbgBSIlX (ORCPT ); Wed, 19 Feb 2020 03:41:23 -0500 Received: from mx2.suse.de ([195.135.220.15]:44278 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726643AbgBSIlX (ORCPT ); Wed, 19 Feb 2020 03:41:23 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 45DFFAF22; Wed, 19 Feb 2020 08:41:21 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 07/24] n_hdlc: simplify freeing of buffer list Date: Wed, 19 Feb 2020 09:41:01 +0100 Message-Id: <20200219084118.26491-7-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org n_hdlc_release contains four loops to free each buffer list. Create a helper (n_hdlc_free_buf_list) and call it for every list instead. It makes n_hdlc_release more readable. We are switching from "for (;;)" to "do {} while (buf)" which avoids the "if (buf)" completely -- kfree is a nop for NULL pointers. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 45 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 31 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index a713a98fea2e..07ba42badd7a 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -215,6 +215,16 @@ static struct tty_ldisc_ops n_hdlc_ldisc = { .flush_buffer = flush_rx_queue, }; +static void n_hdlc_free_buf_list(struct n_hdlc_buf_list *list) +{ + struct n_hdlc_buf *buf; + + do { + buf = n_hdlc_buf_get(list); + kfree(buf); + } while (buf); +} + /** * n_hdlc_release - release an n_hdlc per device line discipline info structure * @n_hdlc - per device line discipline info structure @@ -222,7 +232,6 @@ static struct tty_ldisc_ops n_hdlc_ldisc = { static void n_hdlc_release(struct n_hdlc *n_hdlc) { struct tty_struct *tty = n_hdlc2tty (n_hdlc); - struct n_hdlc_buf *buf; /* Ensure that the n_hdlcd process is not hanging on select()/poll() */ wake_up_interruptible (&tty->read_wait); @@ -231,37 +240,11 @@ static void n_hdlc_release(struct n_hdlc *n_hdlc) if (tty->disc_data == n_hdlc) tty->disc_data = NULL; /* Break the tty->n_hdlc link */ - /* Release transmit and receive buffers */ - for(;;) { - buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); - if (buf) { - kfree(buf); - } else - break; - } - for(;;) { - buf = n_hdlc_buf_get(&n_hdlc->tx_free_buf_list); - if (buf) { - kfree(buf); - } else - break; - } - for(;;) { - buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list); - if (buf) { - kfree(buf); - } else - break; - } - for(;;) { - buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list); - if (buf) { - kfree(buf); - } else - break; - } + n_hdlc_free_buf_list(&n_hdlc->rx_free_buf_list); + n_hdlc_free_buf_list(&n_hdlc->tx_free_buf_list); + n_hdlc_free_buf_list(&n_hdlc->rx_buf_list); + n_hdlc_free_buf_list(&n_hdlc->tx_buf_list); kfree(n_hdlc); - } /* end of n_hdlc_release() */ /** From patchwork Wed Feb 19 08:41:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E8D3C34051 for ; Wed, 19 Feb 2020 08:42:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 414A6208E4 for ; Wed, 19 Feb 2020 08:42:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726731AbgBSIlY (ORCPT ); Wed, 19 Feb 2020 03:41:24 -0500 Received: from mx2.suse.de ([195.135.220.15]:44310 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726681AbgBSIlY (ORCPT ); Wed, 19 Feb 2020 03:41:24 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3E3D2B03B; Wed, 19 Feb 2020 08:41:22 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 10/24] n_hdlc: remove unused backup_tty Date: Wed, 19 Feb 2020 09:41:04 +0100 Message-Id: <20200219084118.26491-10-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org It's only set to NULL and never properly used. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index d0e538ba51ea..ae6b9a45ae81 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -125,7 +125,6 @@ struct n_hdlc_buf_list { * struct n_hdlc - per device instance data structure * @magic - magic value for structure * @tty - ptr to TTY structure - * @backup_tty - TTY to use if tty gets closed * @tbusy - reentrancy flag for tx wakeup code * @woke_up - FIXME: describe this field * @tx_buf_list - list of pending transmit frame buffers @@ -136,7 +135,6 @@ struct n_hdlc_buf_list { struct n_hdlc { int magic; struct tty_struct *tty; - struct tty_struct *backup_tty; int tbusy; int woke_up; struct n_hdlc_buf_list tx_buf_list; @@ -267,15 +265,9 @@ static void n_hdlc_tty_close(struct tty_struct *tty) clear_bit(TTY_NO_WRITE_SPLIT,&tty->flags); #endif tty->disc_data = NULL; - if (tty == n_hdlc->backup_tty) - n_hdlc->backup_tty = NULL; if (tty != n_hdlc->tty) return; - if (n_hdlc->backup_tty) { - n_hdlc->tty = n_hdlc->backup_tty; - } else { - n_hdlc_release (n_hdlc); - } + n_hdlc_release (n_hdlc); } /* end of n_hdlc_tty_close() */ /** From patchwork Wed Feb 19 08:41:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C28DAC34022 for ; Wed, 19 Feb 2020 08:42:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A03C224658 for ; Wed, 19 Feb 2020 08:42:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726707AbgBSImh (ORCPT ); Wed, 19 Feb 2020 03:42:37 -0500 Received: from mx2.suse.de ([195.135.220.15]:44320 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726691AbgBSIlZ (ORCPT ); Wed, 19 Feb 2020 03:41:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 923DBADA1; Wed, 19 Feb 2020 08:41:22 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 11/24] n_hdlc: expand tty2n_hdlc macro Date: Wed, 19 Feb 2020 09:41:05 +0100 Message-Id: <20200219084118.26491-11-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org It's simple tty->disc_data, but it obfuscates code. So expand it to all locations and drop it. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index ae6b9a45ae81..67162611af58 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -175,12 +175,11 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *cp, char *fp, int count); static void n_hdlc_tty_wakeup(struct tty_struct *tty); -#define tty2n_hdlc(tty) ((struct n_hdlc *) ((tty)->disc_data)) #define n_hdlc2tty(n_hdlc) ((n_hdlc)->tty) static void flush_rx_queue(struct tty_struct *tty) { - struct n_hdlc *n_hdlc = tty2n_hdlc(tty); + struct n_hdlc *n_hdlc = tty->disc_data; struct n_hdlc_buf *buf; while ((buf = n_hdlc_buf_get(&n_hdlc->rx_buf_list))) @@ -189,7 +188,7 @@ static void flush_rx_queue(struct tty_struct *tty) static void flush_tx_queue(struct tty_struct *tty) { - struct n_hdlc *n_hdlc = tty2n_hdlc(tty); + struct n_hdlc *n_hdlc = tty->disc_data; struct n_hdlc_buf *buf; while ((buf = n_hdlc_buf_get(&n_hdlc->tx_buf_list))) @@ -252,7 +251,7 @@ static void n_hdlc_release(struct n_hdlc *n_hdlc) */ static void n_hdlc_tty_close(struct tty_struct *tty) { - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + struct n_hdlc *n_hdlc = tty->disc_data; if (!n_hdlc) return; @@ -278,7 +277,7 @@ static void n_hdlc_tty_close(struct tty_struct *tty) */ static int n_hdlc_tty_open (struct tty_struct *tty) { - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + struct n_hdlc *n_hdlc = tty->disc_data; pr_debug("%s(%d)%s() called (device=%s)\n", __FILE__, __LINE__, __func__, tty->name); @@ -402,7 +401,7 @@ static void n_hdlc_send_frames(struct n_hdlc *n_hdlc, struct tty_struct *tty) */ static void n_hdlc_tty_wakeup(struct tty_struct *tty) { - struct n_hdlc *n_hdlc = tty2n_hdlc(tty); + struct n_hdlc *n_hdlc = tty->disc_data; if (!n_hdlc) return; @@ -429,7 +428,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty) static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, char *flags, int count) { - register struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + register struct n_hdlc *n_hdlc = tty->disc_data; register struct n_hdlc_buf *buf; pr_debug("%s(%d)%s() called count=%d\n", @@ -494,7 +493,7 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, __u8 __user *buf, size_t nr) { - struct n_hdlc *n_hdlc = tty2n_hdlc(tty); + struct n_hdlc *n_hdlc = tty->disc_data; int ret = 0; struct n_hdlc_buf *rbuf; DECLARE_WAITQUEUE(wait, current); @@ -576,7 +575,7 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, const unsigned char *data, size_t count) { - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + struct n_hdlc *n_hdlc = tty->disc_data; int error = 0; DECLARE_WAITQUEUE(wait, current); struct n_hdlc_buf *tbuf; @@ -613,7 +612,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, } schedule(); - n_hdlc = tty2n_hdlc (tty); + n_hdlc = tty->disc_data; if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || tty != n_hdlc->tty) { printk("n_hdlc_tty_write: %p invalid after wait!\n", n_hdlc); @@ -656,7 +655,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) { - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + struct n_hdlc *n_hdlc = tty->disc_data; int error = 0; int count; unsigned long flags; @@ -725,7 +724,7 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file, static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, poll_table *wait) { - struct n_hdlc *n_hdlc = tty2n_hdlc (tty); + struct n_hdlc *n_hdlc = tty->disc_data; __poll_t mask = 0; if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC || tty != n_hdlc->tty) From patchwork Wed Feb 19 08:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214274 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 028BAC3404D for ; Wed, 19 Feb 2020 08:42:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D608B21D56 for ; Wed, 19 Feb 2020 08:42:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727460AbgBSImU (ORCPT ); Wed, 19 Feb 2020 03:42:20 -0500 Received: from mx2.suse.de ([195.135.220.15]:44280 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726715AbgBSIlZ (ORCPT ); Wed, 19 Feb 2020 03:41:25 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9ACC1AEAC; Wed, 19 Feb 2020 08:41:23 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 14/24] n_hdlc: remove checking of n_hdlc Date: Wed, 19 Feb 2020 09:41:08 +0100 Message-Id: <20200219084118.26491-14-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org We got rid of backup_tty recently. Also, the tty layer ensures not to call other ldisc hooks after ldisc close. That means, all those tests are superfluous now so remove them. Note that we remove the magic check in write after schedule too. The tty cannot change during schedule. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 2ac702974b57..2709d18364eb 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -227,9 +227,6 @@ static void n_hdlc_tty_close(struct tty_struct *tty) { struct n_hdlc *n_hdlc = tty->disc_data; - if (!n_hdlc) - return; - if (n_hdlc->magic != HDLC_MAGIC) { printk(KERN_WARNING "n_hdlc: trying to close unopened tty!\n"); return; @@ -383,11 +380,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty) { struct n_hdlc *n_hdlc = tty->disc_data; - if (!n_hdlc) - return; - n_hdlc_send_frames (n_hdlc, tty); - } /* end of n_hdlc_tty_wakeup() */ /** @@ -409,10 +402,6 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, 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) - return; - /* verify line is using HDLC discipline */ if (n_hdlc->magic != HDLC_MAGIC) { printk("%s(%d) line not using HDLC discipline\n", @@ -473,10 +462,6 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, struct n_hdlc_buf *rbuf; DECLARE_WAITQUEUE(wait, current); - /* Validate the pointers */ - if (!n_hdlc) - return -EIO; - /* verify user access to buffer */ if (!access_ok(buf, nr)) { printk(KERN_WARNING "%s(%d) n_hdlc_tty_read() can't verify user " @@ -558,10 +543,6 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, pr_debug("%s(%d)%s() called count=%zd\n", __FILE__, __LINE__, __func__, count); - /* Verify pointers */ - if (!n_hdlc) - return -EIO; - if (n_hdlc->magic != HDLC_MAGIC) return -EIO; @@ -586,14 +567,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, break; } schedule(); - - n_hdlc = tty->disc_data; - if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC) { - printk("n_hdlc_tty_write: %p invalid after wait!\n", n_hdlc); - error = -EIO; - break; - } - + if (signal_pending(current)) { error = -EINTR; break; @@ -638,7 +612,7 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file, 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) + if (n_hdlc->magic != HDLC_MAGIC) return -EBADF; switch (cmd) { @@ -701,7 +675,7 @@ static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, struct n_hdlc *n_hdlc = tty->disc_data; __poll_t mask = 0; - if (!n_hdlc || n_hdlc->magic != HDLC_MAGIC) + if (n_hdlc->magic != HDLC_MAGIC) return 0; /* From patchwork Wed Feb 19 08:41:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45BFCC34050 for ; Wed, 19 Feb 2020 08:42:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2120E21D56 for ; Wed, 19 Feb 2020 08:42:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726767AbgBSImO (ORCPT ); Wed, 19 Feb 2020 03:42:14 -0500 Received: from mx2.suse.de ([195.135.220.15]:44300 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726736AbgBSIl0 (ORCPT ); Wed, 19 Feb 2020 03:41:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 4D88CAF22; Wed, 19 Feb 2020 08:41:24 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 16/24] n_hdlc: move tty_ldisc_ops to the bottom Date: Wed, 19 Feb 2020 09:41:10 +0100 Message-Id: <20200219084118.26491-16-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org This makes forward declarations unnecessary. So drop them. Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 46 +++++++++++++++----------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 4276931fd071..615abe582cac 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -157,22 +157,6 @@ static struct n_hdlc *n_hdlc_alloc (void); /* max frame size for memory allocations */ static int maxframe = 4096; -/* TTY callbacks */ - -static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, - __u8 __user *buf, size_t nr); -static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, - const unsigned char *buf, size_t nr); -static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file, - unsigned int cmd, unsigned long arg); -static __poll_t n_hdlc_tty_poll(struct tty_struct *tty, struct file *filp, - poll_table *wait); -static int n_hdlc_tty_open(struct tty_struct *tty); -static void n_hdlc_tty_close(struct tty_struct *tty); -static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *cp, - char *fp, int count); -static void n_hdlc_tty_wakeup(struct tty_struct *tty); - static void flush_rx_queue(struct tty_struct *tty) { struct n_hdlc *n_hdlc = tty->disc_data; @@ -191,21 +175,6 @@ static void flush_tx_queue(struct tty_struct *tty) n_hdlc_buf_put(&n_hdlc->tx_free_buf_list, buf); } -static struct tty_ldisc_ops n_hdlc_ldisc = { - .owner = THIS_MODULE, - .magic = TTY_LDISC_MAGIC, - .name = "hdlc", - .open = n_hdlc_tty_open, - .close = n_hdlc_tty_close, - .read = n_hdlc_tty_read, - .write = n_hdlc_tty_write, - .ioctl = n_hdlc_tty_ioctl, - .poll = n_hdlc_tty_poll, - .receive_buf = n_hdlc_tty_receive, - .write_wakeup = n_hdlc_tty_wakeup, - .flush_buffer = flush_rx_queue, -}; - static void n_hdlc_free_buf_list(struct n_hdlc_buf_list *list) { struct n_hdlc_buf *buf; @@ -810,6 +779,21 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *buf_list) return buf; } /* end of n_hdlc_buf_get() */ +static struct tty_ldisc_ops n_hdlc_ldisc = { + .owner = THIS_MODULE, + .magic = TTY_LDISC_MAGIC, + .name = "hdlc", + .open = n_hdlc_tty_open, + .close = n_hdlc_tty_close, + .read = n_hdlc_tty_read, + .write = n_hdlc_tty_write, + .ioctl = n_hdlc_tty_ioctl, + .poll = n_hdlc_tty_poll, + .receive_buf = n_hdlc_tty_receive, + .write_wakeup = n_hdlc_tty_wakeup, + .flush_buffer = flush_rx_queue, +}; + static int __init n_hdlc_init(void) { int status; From patchwork Wed Feb 19 08:41:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69012C34050 for ; Wed, 19 Feb 2020 08:42:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F912208E4 for ; Wed, 19 Feb 2020 08:42:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726803AbgBSIl1 (ORCPT ); Wed, 19 Feb 2020 03:41:27 -0500 Received: from mx2.suse.de ([195.135.220.15]:44328 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726773AbgBSIl0 (ORCPT ); Wed, 19 Feb 2020 03:41:26 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 467EEB03B; Wed, 19 Feb 2020 08:41:25 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 19/24] n_hdlc: use __func__ and pr_ print helpers Date: Wed, 19 Feb 2020 09:41:13 +0100 Message-Id: <20200219084118.26491-19-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org * we mark the message in n_hdlc_tty_receive as error * we use __func__ instead of explicit function name * we switch the remaining prints to pr_* helpers Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index cf8485beaccd..048e5a155bea 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -197,7 +197,7 @@ static void n_hdlc_tty_close(struct tty_struct *tty) struct n_hdlc *n_hdlc = tty->disc_data; if (n_hdlc->magic != HDLC_MAGIC) { - printk(KERN_WARNING "n_hdlc: trying to close unopened tty!\n"); + pr_warn("n_hdlc: trying to close unopened tty!\n"); return; } #if defined(TTY_NO_WRITE_SPLIT) @@ -231,13 +231,13 @@ static int n_hdlc_tty_open (struct tty_struct *tty) /* There should not be an existing table for this slot. */ if (n_hdlc) { - printk (KERN_ERR"n_hdlc_tty_open:tty already associated!\n" ); + pr_err("%s: tty already associated!\n", __func__); return -EEXIST; } n_hdlc = n_hdlc_alloc(); if (!n_hdlc) { - printk (KERN_ERR "n_hdlc_alloc failed\n"); + pr_err("%s: n_hdlc_alloc failed\n", __func__); return -ENFILE; } @@ -371,8 +371,8 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, /* verify line is using HDLC discipline */ if (n_hdlc->magic != HDLC_MAGIC) { - printk("%s(%d) line not using HDLC discipline\n", - __FILE__,__LINE__); + pr_err("%s(%d) line not using HDLC discipline\n", + __FILE__, __LINE__); return; } @@ -431,8 +431,8 @@ static ssize_t n_hdlc_tty_read(struct tty_struct *tty, struct file *file, /* verify user access to buffer */ if (!access_ok(buf, nr)) { - printk(KERN_WARNING "%s(%d) n_hdlc_tty_read() can't verify user " - "buffer\n", __FILE__, __LINE__); + pr_warn("%s(%d) %s() can't verify user buffer\n", + __FILE__, __LINE__, __func__); return -EFAULT; } From patchwork Wed Feb 19 08:41:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214276 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5686C34022 for ; Wed, 19 Feb 2020 08:42:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C9005222D9 for ; Wed, 19 Feb 2020 08:42:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726593AbgBSImF (ORCPT ); Wed, 19 Feb 2020 03:42:05 -0500 Received: from mx2.suse.de ([195.135.220.15]:44320 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726787AbgBSIl1 (ORCPT ); Wed, 19 Feb 2020 03:41:27 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 00008AEAC; Wed, 19 Feb 2020 08:41:25 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 21/24] n_hdlc: remove spaces between function name and ( Date: Wed, 19 Feb 2020 09:41:15 +0100 Message-Id: <20200219084118.26491-21-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index ee27573b0624..d52bcfa7f8e4 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -152,7 +152,7 @@ static struct n_hdlc_buf *n_hdlc_buf_get(struct n_hdlc_buf_list *list); /* Local functions */ -static struct n_hdlc *n_hdlc_alloc (void); +static struct n_hdlc *n_hdlc_alloc(void); /* max frame size for memory allocations */ static int maxframe = 4096; @@ -222,7 +222,7 @@ static void n_hdlc_tty_close(struct tty_struct *tty) * * Returns 0 if success, otherwise error code */ -static int n_hdlc_tty_open (struct tty_struct *tty) +static int n_hdlc_tty_open(struct tty_struct *tty) { struct n_hdlc *n_hdlc = tty->disc_data; @@ -347,7 +347,7 @@ static void n_hdlc_tty_wakeup(struct tty_struct *tty) { struct n_hdlc *n_hdlc = tty->disc_data; - n_hdlc_send_frames (n_hdlc, tty); + n_hdlc_send_frames(n_hdlc, tty); } /* end of n_hdlc_tty_wakeup() */ /** @@ -406,7 +406,7 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, n_hdlc_buf_put(&n_hdlc->rx_buf_list, buf); /* wake up any blocked reads and perform async signalling */ - wake_up_interruptible (&tty->read_wait); + wake_up_interruptible(&tty->read_wait); if (tty->fasync != NULL) kill_fasync(&tty->fasync, SIGIO, POLL_IN); From patchwork Wed Feb 19 08:41:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D41B9C34022 for ; Wed, 19 Feb 2020 08:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B3407208E4 for ; Wed, 19 Feb 2020 08:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726828AbgBSIl3 (ORCPT ); Wed, 19 Feb 2020 03:41:29 -0500 Received: from mx2.suse.de ([195.135.220.15]:44278 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726797AbgBSIl2 (ORCPT ); Wed, 19 Feb 2020 03:41:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 9CEB2AD88; Wed, 19 Feb 2020 08:41:26 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 23/24] n_hdlc: fix whitespace around binary operators Date: Wed, 19 Feb 2020 09:41:17 +0100 Message-Id: <20200219084118.26491-23-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index 7ae4347a946f..b74a8ecc65b5 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -376,7 +376,7 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, return; } - if ( count>maxframe ) { + if (count > maxframe) { pr_debug("%s(%d) rx count>maxframesize, data discarded\n", __FILE__, __LINE__); return; @@ -400,7 +400,7 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, /* copy received data to HDLC buffer */ memcpy(buf->buf, data, count); - buf->count=count; + buf->count = count; /* add HDLC buffer to list of received frames */ n_hdlc_buf_put(&n_hdlc->rx_buf_list, buf); @@ -514,7 +514,7 @@ static ssize_t n_hdlc_tty_write(struct tty_struct *tty, struct file *file, return -EIO; /* verify frame size */ - if (count > maxframe ) { + if (count > maxframe) { pr_debug("%s: truncating user packet from %zu to %d\n", __func__, count, maxframe); count = maxframe; From patchwork Wed Feb 19 08:41:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 214278 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4795CC34022 for ; Wed, 19 Feb 2020 08:42:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2BC522464E for ; Wed, 19 Feb 2020 08:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726821AbgBSIl2 (ORCPT ); Wed, 19 Feb 2020 03:41:28 -0500 Received: from mx2.suse.de ([195.135.220.15]:44300 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbgBSIl2 (ORCPT ); Wed, 19 Feb 2020 03:41:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E9A3BAED8; Wed, 19 Feb 2020 08:41:26 +0000 (UTC) From: Jiri Slaby To: gregkh@linuxfoundation.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Slaby Subject: [PATCH 24/24] n_hdlc: wrap a comment properly Date: Wed, 19 Feb 2020 09:41:18 +0100 Message-Id: <20200219084118.26491-24-jslaby@suse.cz> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200219084118.26491-1-jslaby@suse.cz> References: <20200219084118.26491-1-jslaby@suse.cz> MIME-Version: 1.0 Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Signed-off-by: Jiri Slaby --- drivers/tty/n_hdlc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/tty/n_hdlc.c b/drivers/tty/n_hdlc.c index b74a8ecc65b5..cd1319d26c45 100644 --- a/drivers/tty/n_hdlc.c +++ b/drivers/tty/n_hdlc.c @@ -385,8 +385,10 @@ static void n_hdlc_tty_receive(struct tty_struct *tty, const __u8 *data, /* get a free HDLC buffer */ buf = n_hdlc_buf_get(&n_hdlc->rx_free_buf_list); if (!buf) { - /* no buffers in free list, attempt to allocate another rx buffer */ - /* unless the maximum count has been reached */ + /* + * no buffers in free list, attempt to allocate another rx + * buffer unless the maximum count has been reached + */ if (n_hdlc->rx_buf_list.count < MAX_RX_BUF_COUNT) buf = kmalloc(struct_size(buf, buf, maxframe), GFP_ATOMIC);