lkml.org 
[lkml]   [2019]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 03/58] serial_core: Un-ifdef sysrq SUPPORT_SYSRQ
Date
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
\
 
 \ /
  Last update: 2019-12-13 01:08    [W:0.043 / U:5.108 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site