Skip to content

Commit 47d4dfd

Browse files
KAGA-KOKOgregkh
authored andcommitted
serial: st-asc: Use port lock wrappers
When a serial port is used for kernel console output, then all modifications to the UART registers which are done from other contexts, e.g. getty, termios, are interference points for the kernel console. So far this has been ignored and the printk output is based on the principle of hope. The rework of the console infrastructure which aims to support threaded and atomic consoles, requires to mark sections which modify the UART registers as unsafe. This allows the atomic write function to make informed decisions and eventually to restore operational state. It also allows to prevent the regular UART code from modifying UART registers while printk output is in progress. All modifications of UART registers are guarded by the UART port lock, which provides an obvious synchronization point with the console infrastructure. To avoid adding this functionality to all UART drivers, wrap the spin_[un]lock*() invocations for uart_port::lock into helper functions which just contain the spin_[un]lock*() invocations for now. In a subsequent step these helpers will gain the console synchronization mechanisms. Converted with coccinelle. No functional change. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: John Ogness <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent e58d551 commit 47d4dfd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

drivers/tty/serial/st-asc.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ static irqreturn_t asc_interrupt(int irq, void *ptr)
319319
struct uart_port *port = ptr;
320320
u32 status;
321321

322-
spin_lock(&port->lock);
322+
uart_port_lock(port);
323323

324324
status = asc_in(port, ASC_STA);
325325

@@ -334,7 +334,7 @@ static irqreturn_t asc_interrupt(int irq, void *ptr)
334334
asc_transmit_chars(port);
335335
}
336336

337-
spin_unlock(&port->lock);
337+
uart_port_unlock(port);
338338

339339
return IRQ_HANDLED;
340340
}
@@ -452,10 +452,10 @@ static void asc_pm(struct uart_port *port, unsigned int state,
452452
* we can come to turning it off. Note this is not called with
453453
* the port spinlock held.
454454
*/
455-
spin_lock_irqsave(&port->lock, flags);
455+
uart_port_lock_irqsave(port, &flags);
456456
ctl = asc_in(port, ASC_CTL) & ~ASC_CTL_RUN;
457457
asc_out(port, ASC_CTL, ctl);
458-
spin_unlock_irqrestore(&port->lock, flags);
458+
uart_port_unlock_irqrestore(port, flags);
459459
clk_disable_unprepare(ascport->clk);
460460
break;
461461
}
@@ -480,7 +480,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
480480
baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
481481
cflag = termios->c_cflag;
482482

483-
spin_lock_irqsave(&port->lock, flags);
483+
uart_port_lock_irqsave(port, &flags);
484484

485485
/* read control register */
486486
ctrl_val = asc_in(port, ASC_CTL);
@@ -594,7 +594,7 @@ static void asc_set_termios(struct uart_port *port, struct ktermios *termios,
594594
/* write final value and enable port */
595595
asc_out(port, ASC_CTL, (ctrl_val | ASC_CTL_RUN));
596596

597-
spin_unlock_irqrestore(&port->lock, flags);
597+
uart_port_unlock_irqrestore(port, flags);
598598
}
599599

600600
static const char *asc_type(struct uart_port *port)
@@ -849,9 +849,9 @@ static void asc_console_write(struct console *co, const char *s, unsigned count)
849849
if (port->sysrq)
850850
locked = 0; /* asc_interrupt has already claimed the lock */
851851
else if (oops_in_progress)
852-
locked = spin_trylock_irqsave(&port->lock, flags);
852+
locked = uart_port_trylock_irqsave(port, &flags);
853853
else
854-
spin_lock_irqsave(&port->lock, flags);
854+
uart_port_lock_irqsave(port, &flags);
855855

856856
/*
857857
* Disable interrupts so we don't get the IRQ line bouncing
@@ -869,7 +869,7 @@ static void asc_console_write(struct console *co, const char *s, unsigned count)
869869
asc_out(port, ASC_INTEN, intenable);
870870

871871
if (locked)
872-
spin_unlock_irqrestore(&port->lock, flags);
872+
uart_port_unlock_irqrestore(port, flags);
873873
}
874874

875875
static int asc_console_setup(struct console *co, char *options)

0 commit comments

Comments
 (0)