All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Safonov <dima@arista.com>
To: linux-kernel@vger.kernel.org
Cc: Dmitry Safonov <0x7f454c46@gmail.com>,
	Dmitry Safonov <dima@arista.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jiri Slaby <jslaby@suse.com>,
	Vasiliy Khoruzhick <vasilykh@arista.com>,
	linux-serial@vger.kernel.org
Subject: [PATCH 03/58] serial_core: Un-ifdef sysrq SUPPORT_SYSRQ
Date: Fri, 13 Dec 2019 00:06:02 +0000	[thread overview]
Message-ID: <20191213000657.931618-4-dima@arista.com> (raw)
In-Reply-To: <20191213000657.931618-1-dima@arista.com>

The SUPPORT_SYSRQ is messy: every .c source should define it before
including "serial_core.h" if sysrq is supported or struct uart_port will
differ in sizes. Also this prevents moving to serial_core.c functions:
uart_handle_sysrq_char(), uart_prepare_sysrq_char(),
uart_unlock_and_check_sysrq().

It doesn't save many bytes in the structure, and a better way to reduce
it's size would be making rs485 and iso7816 pointers.

Introduce `has_sysrq` member to be used by serial line drivers further.

Signed-off-by: Dmitry Safonov <dima@arista.com>
---
 include/linux/serial_core.h | 77 +++++++++++++++++++++----------------
 1 file changed, 43 insertions(+), 34 deletions(-)

diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index bbbe57bf5163..5f761c399282 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -240,14 +240,13 @@ struct uart_port {
 	resource_size_t		mapsize;
 	struct device		*dev;			/* parent device */
 
-#if defined(CONFIG_SERIAL_CORE_CONSOLE) || defined(SUPPORT_SYSRQ)
 	unsigned long		sysrq;			/* sysrq timeout */
 	unsigned int		sysrq_ch;		/* char for sysrq */
-#endif
+	unsigned char		has_sysrq;
 
 	unsigned char		hub6;			/* this should be in the 8250 driver */
 	unsigned char		suspended;
-	unsigned char		unused[2];
+	unsigned char		unused;
 	const char		*name;			/* port name */
 	struct attribute_group	*attr_group;		/* port specific attributes */
 	const struct attribute_group **tty_groups;	/* all attributes (serial core use only) */
@@ -461,31 +460,46 @@ extern void uart_handle_cts_change(struct uart_port *uport,
 extern void uart_insert_char(struct uart_port *port, unsigned int status,
 		 unsigned int overrun, unsigned int ch, unsigned int flag);
 
-#if defined(SUPPORT_SYSRQ) && defined(CONFIG_MAGIC_SYSRQ_SERIAL)
 static inline int
 uart_handle_sysrq_char(struct uart_port *port, unsigned int ch)
 {
-	if (port->sysrq) {
-		if (ch && time_before(jiffies, port->sysrq)) {
-			handle_sysrq(ch);
-			port->sysrq = 0;
-			return 1;
-		}
+	if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
+		return 0;
+
+	if (!port->has_sysrq && !IS_ENABLED(SUPPORT_SYSRQ))
+		return 0;
+
+	if (!port->sysrq)
+		return 0;
+
+	if (ch && time_before(jiffies, port->sysrq)) {
+		handle_sysrq(ch);
 		port->sysrq = 0;
+		return 1;
 	}
+	port->sysrq = 0;
+
 	return 0;
 }
 static inline int
 uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch)
 {
-	if (port->sysrq) {
-		if (ch && time_before(jiffies, port->sysrq)) {
-			port->sysrq_ch = ch;
-			port->sysrq = 0;
-			return 1;
-		}
+	if (!IS_ENABLED(CONFIG_MAGIC_SYSRQ_SERIAL))
+		return 0;
+
+	if (!port->has_sysrq && !IS_ENABLED(SUPPORT_SYSRQ))
+		return 0;
+
+	if (!port->sysrq)
+		return 0;
+
+	if (ch && time_before(jiffies, port->sysrq)) {
+		port->sysrq_ch = ch;
 		port->sysrq = 0;
+		return 1;
 	}
+	port->sysrq = 0;
+
 	return 0;
 }
 static inline void
@@ -493,6 +507,11 @@ uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
 {
 	int sysrq_ch;
 
+	if (!port->has_sysrq && !IS_ENABLED(SUPPORT_SYSRQ)) {
+		spin_unlock_irqrestore(&port->lock, irqflags);
+		return;
+	}
+
 	sysrq_ch = port->sysrq_ch;
 	port->sysrq_ch = 0;
 
@@ -501,17 +520,6 @@ uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
 	if (sysrq_ch)
 		handle_sysrq(sysrq_ch);
 }
-#else
-static inline int
-uart_handle_sysrq_char(struct uart_port *port, unsigned int ch) { return 0; }
-static inline int
-uart_prepare_sysrq_char(struct uart_port *port, unsigned int ch) { return 0; }
-static inline void
-uart_unlock_and_check_sysrq(struct uart_port *port, unsigned long irqflags)
-{
-	spin_unlock_irqrestore(&port->lock, irqflags);
-}
-#endif
 
 /*
  * We do the SysRQ and SAK checking like this...
@@ -523,15 +531,16 @@ static inline int uart_handle_break(struct uart_port *port)
 	if (port->handle_break)
 		port->handle_break(port);
 
-#ifdef SUPPORT_SYSRQ
-	if (port->cons && port->cons->index == port->line) {
-		if (!port->sysrq) {
-			port->sysrq = jiffies + HZ*5;
-			return 1;
+	if (port->has_sysrq || IS_ENABLED(SUPPORT_SYSRQ)) {
+		if (port->cons && port->cons->index == port->line) {
+			if (!port->sysrq) {
+				port->sysrq = jiffies + HZ*5;
+				return 1;
+			}
+			port->sysrq = 0;
 		}
-		port->sysrq = 0;
 	}
-#endif
+
 	if (port->flags & UPF_SAK)
 		do_SAK(state->port.tty);
 	return 0;
-- 
2.24.0


  parent reply	other threads:[~2019-12-13  0:07 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-13  0:05 [PATCH 00/58] serial/sysrq: Cleanup ifdeffery Dmitry Safonov
2019-12-13  0:05 ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 01/58] sysrq: Remove sysrq_handler_registered Dmitry Safonov
2019-12-13  0:06 ` [PATCH 02/58] serial: Move sysrq members above Dmitry Safonov
2019-12-13  7:17   ` Greg Kroah-Hartman
2019-12-13  0:06 ` Dmitry Safonov [this message]
2019-12-13  7:18   ` [PATCH 03/58] serial_core: Un-ifdef sysrq SUPPORT_SYSRQ Greg Kroah-Hartman
2019-12-17 13:48   ` Greg Kroah-Hartman
2019-12-17 13:51   ` Greg Kroah-Hartman
2019-12-13  0:06 ` [PATCH 04/58] tty/serial: Migrate aspeed_vuart to use has_sysrq Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  1:32   ` Andrew Jeffery
2019-12-13  1:32     ` Andrew Jeffery
2019-12-13  0:06 ` [PATCH 05/58] tty/serial: Migrate 8250_fsl " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 06/58] tty/serial: Migrate bcm63xx_uart " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 07/58] tty/serial: Migrate 8250_omap " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 08/58] tty/serial: Migrate 8250_port " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 09/58] tty/serial: Migrate amba-pl01* " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 10/58] tty/serial: Migrate apbuart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 11/58] tty/serial: Migrate arc_uart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 12/58] tty/serial: Migrate atmel_serial " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 13/58] tty/serial: Migrate clps711x " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 14/58] tty/serial: Migrate cpm_uart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 15/58] tty/serial: Migrate dz " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 16/58] tty/serial: Migrate efm32-uart " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 17/58] tty/serial: Migrate fsl_linflexuart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 18/58] tty/serial: Migrate fsl_lpuart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 19/58] tty/serial: Migrate imx " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 20/58] tty/serial: Migrate ip22zilog " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 21/58] tty/serial: Migrate meson_uart " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 22/58] tty/serial: Migrate milbeaut_usio " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 23/58] tty/serial: Migrate mpc52xx_uart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 24/58] tty/serial: Don't zero port->sysrq Dmitry Safonov
2019-12-13  0:06 ` [PATCH 25/58] tty/serial: Migrate msm_serial to use has_sysrq Dmitry Safonov
2019-12-13  0:06 ` [PATCH 26/58] tty/serial: Migrate mux " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 27/58] tty/serial: Migrate mxs-auart " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 28/58] tty/serial: Migrate omap-serial " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 29/58] tty/serial: Migrate pch_uart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 30/58] tty/serial: Don't check port->sysrq Dmitry Safonov
2019-12-13  0:06 ` [PATCH 31/58] tty/serial: Migrate pmac_zilog to use has_sysrq Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 32/58] tty/serial: Migrate pnx8xxx_uart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 33/58] serial/f81534: Don't check port->sysrq Dmitry Safonov
2019-12-16 12:10   ` Johan Hovold
2019-12-16 16:36     ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 34/58] tty/serial: Migrate pxa to use has_sysrq Dmitry Safonov
2019-12-13  0:06 ` [PATCH 35/58] tty/serial: Migrate qcom_geni_serial " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 36/58] tty/serial: Migrate sa1100 " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 37/58] tty/serial: Migrate samsung_tty " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 38/58] tty/serial: Migrate sb1250-duart " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 39/58] tty/serial: Migrate sccnxp " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 40/58] tty/serial: Migrate serial_txx9 " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 41/58] tty/serial: Migrate sh-sci " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 42/58] tty/serial: Migrate sprd_serial " Dmitry Safonov
2019-12-16  2:30   ` Chunyan Zhang
2019-12-13  0:06 ` [PATCH 43/58] tty/serial: Migrate st-asc " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 44/58] tty/serial: Migrate stm32-usart " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 45/58] tty/serial: Migrate sunhv " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 46/58] tty/serial: Migrate sunsab " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 47/58] tty/serial: Migrate sunsu " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 48/58] tty/serial: Migrate sunzilog " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 49/58] serial/ucc_uart: Remove ifdef SUPPORT_SYSRQ Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 50/58] tty/serial: Migrate vr41xx_siu to use has_sysrq Dmitry Safonov
2019-12-13  0:06 ` [PATCH 51/58] tty/serial: Migrate vt8500_serial " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 52/58] tty/serial: Migrate xilinx_uartps " Dmitry Safonov
2019-12-13  0:06   ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 53/58] tty/serial: Migrate zs " Dmitry Safonov
2019-12-13  0:06 ` [PATCH 54/58] serial_core: Remove SUPPORT_SYSRQ ifdeffery Dmitry Safonov
2019-12-17 14:27   ` Greg Kroah-Hartman
2019-12-17 15:50     ` Dmitry Safonov
2019-12-13  0:06 ` [PATCH 55/58] usb/serial: Don't handle break when CONFIG_MAGIC_SYSRQ is disabled Dmitry Safonov
2019-12-13  0:06 ` [PATCH 56/58] serial_core: Move sysrq functions from header file Dmitry Safonov
2019-12-13  0:06 ` [PATCH 57/58] sysctl/sysrq: Remove __sysrq_enabled copy Dmitry Safonov
2019-12-13  0:06 ` [PATCH 58/58] serial/sysrq: Add MAGIC_SYSRQ_SERIAL_SEQUENCE Dmitry Safonov
2019-12-13  5:47 ` [PATCH 00/58] serial/sysrq: Cleanup ifdeffery Christophe Leroy
2019-12-13  5:47   ` Christophe Leroy
2019-12-13 16:41   ` Dmitry Safonov
2019-12-13 16:41     ` Dmitry Safonov

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=20191213000657.931618-4-dima@arista.com \
    --to=dima@arista.com \
    --cc=0x7f454c46@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jslaby@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=vasilykh@arista.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.