linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	linux-serial@vger.kernel.org,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Tony Lindgren <tony@atomide.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 2/8] serial: core: Consolidate spin lock initialization code
Date: Fri, 14 Feb 2020 13:43:33 +0200	[thread overview]
Message-ID: <20200214114339.53897-3-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200214114339.53897-1-andriy.shevchenko@linux.intel.com>

We have two times duplicated excerpt where we initialize spin lock
for UART port. Consolidate it under uart_port_spin_lock_init() helper.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/tty/serial/serial_core.c | 34 +++++++++++++++-----------------
 1 file changed, 16 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index d956da0b6d9c..bb2287048108 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -1913,6 +1913,19 @@ static inline bool uart_console_enabled(struct uart_port *port)
 	return uart_console(port) && (port->cons->flags & CON_ENABLED);
 }
 
+/*
+ * Ensure that the serial console lock is initialised early.
+ * If this port is a console, then the spinlock is already initialised.
+ */
+static inline void uart_port_spin_lock_init(struct uart_port *port)
+{
+	if (uart_console_enabled(port))
+		return;
+
+	spin_lock_init(&port->lock);
+	lockdep_set_class(&port->lock, &port_lock_key);
+}
+
 #if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(CONFIG_CONSOLE_POLL)
 /**
  *	uart_console_write - write a console message to a serial port
@@ -2065,16 +2078,7 @@ uart_set_options(struct uart_port *port, struct console *co,
 	struct ktermios termios;
 	static struct ktermios dummy;
 
-	/*
-	 * Ensure that the serial console lock is initialised
-	 * early.
-	 * If this port is a console, then the spinlock is already
-	 * initialised.
-	 */
-	if (!uart_console_enabled(port)) {
-		spin_lock_init(&port->lock);
-		lockdep_set_class(&port->lock, &port_lock_key);
-	}
+	uart_port_spin_lock_init(port);
 
 	memset(&termios, 0, sizeof(struct ktermios));
 
@@ -2829,14 +2833,8 @@ int uart_add_one_port(struct uart_driver *drv, struct uart_port *uport)
 		goto out;
 	}
 
-	/*
-	 * If this port is a console, then the spinlock is already
-	 * initialised.
-	 */
-	if (!uart_console_enabled(uport)) {
-		spin_lock_init(&uport->lock);
-		lockdep_set_class(&uport->lock, &port_lock_key);
-	}
+	uart_port_spin_lock_init(uport);
+
 	if (uport->cons && uport->dev)
 		of_console_check(uport->dev->of_node, uport->cons->name, uport->line);
 
-- 
2.25.0


  parent reply	other threads:[~2020-02-14 11:43 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-14 11:43 [PATCH v2 0/8] serial: Disable DMA and PM on kernel console Andy Shevchenko
2020-02-14 11:43 ` [PATCH v2 1/8] serial: core: Introduce uart_console_enabled() helper Andy Shevchenko
2020-02-14 11:43 ` Andy Shevchenko [this message]
2020-02-14 11:43 ` [PATCH v2 3/8] serial: core: use octal permissions on module param Andy Shevchenko
2020-02-14 16:27   ` Greg Kroah-Hartman
2020-02-17  9:15     ` Andy Shevchenko
2020-02-14 11:43 ` [PATCH v2 4/8] serial: core: Allow detach and attach serial device for console Andy Shevchenko
2020-02-14 16:28   ` Greg Kroah-Hartman
2020-02-17 10:23     ` Andy Shevchenko
2020-02-14 11:43 ` [PATCH v2 5/8] serial: 8250_port: Don't use power management for kernel console Andy Shevchenko
2020-02-14 13:39   ` Russell King - ARM Linux admin
2020-02-14 17:13     ` Tony Lindgren
2020-02-14 18:09       ` Andy Shevchenko
2020-02-14 18:42         ` Tony Lindgren
2020-02-14 19:06           ` Tony Lindgren
2020-02-14 18:14   ` Tony Lindgren
2020-02-14 18:56     ` Andy Shevchenko
2020-02-14 19:02       ` Tony Lindgren
2020-02-14 11:43 ` [PATCH v2 6/8] serial: 8250_port: Disable DMA operations " Andy Shevchenko
2020-02-14 16:30   ` Greg Kroah-Hartman
2020-02-17  9:18     ` Andy Shevchenko
2020-02-14 11:43 ` [PATCH v2 7/8] serial: 8250_mtk: Remove duplicating code to disable DMA Andy Shevchenko
2020-02-14 11:43 ` [PATCH v2 8/8] serial: 8250_omap: " Andy Shevchenko
2020-02-14 16:33 ` [PATCH v2 0/8] serial: Disable DMA and PM on kernel console Greg Kroah-Hartman
2020-02-14 21:41   ` Tony Lindgren
2020-02-17 10:05     ` Andy Shevchenko

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=20200214114339.53897-3-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bigeasy@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-serial@vger.kernel.org \
    --cc=tony@atomide.com \
    /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).