mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-03-17 20:54:10 +00:00
serial: Fix locking for uart driver set_termios() method
The low-level uart driver may modify termios settings to override settings that are not compatible with the uart, such as CRTSCTS. Thus, callers of the low-level uart driver's set_termios() method must hold termios_rwsem write lock to prevent concurrent access to termios, in case such override occurs. The termios_rwsem lock requirement does not extend to console setup (ie., uart_set_options), as console setup cannot race with tty operations. Nor does this lock requirement extend to functions which cannot be concurrent with tty ioctls (ie., uart_port_startup() and uart_resume_port()). Further, always claim the port mutex to protect hardware re-reprogramming in the set_termios() uart driver method. Note this is unnecessary for console initialization in uart_set_options() which cannot be concurrent with other uart operations. Signed-off-by: Peter Hurley <peter@hurleysoftware.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
2e75891083
commit
7c8ab967e3
2 changed files with 11 additions and 3 deletions
|
@ -59,7 +59,9 @@ The core driver uses the info->tmpbuf_sem lock to prevent multi-threaded
|
||||||
access to the info->tmpbuf bouncebuffer used for port writes.
|
access to the info->tmpbuf bouncebuffer used for port writes.
|
||||||
|
|
||||||
The port_sem semaphore is used to protect against ports being added/
|
The port_sem semaphore is used to protect against ports being added/
|
||||||
removed or reconfigured at inappropriate times.
|
removed or reconfigured at inappropriate times. Since v2.6.27, this
|
||||||
|
semaphore has been the 'mutex' member of the tty_port struct, and
|
||||||
|
commonly referred to as the port mutex (or port->mutex).
|
||||||
|
|
||||||
|
|
||||||
uart_ops
|
uart_ops
|
||||||
|
@ -248,7 +250,7 @@ hardware.
|
||||||
Other flags may be used (eg, xon/xoff characters) if your
|
Other flags may be used (eg, xon/xoff characters) if your
|
||||||
hardware supports hardware "soft" flow control.
|
hardware supports hardware "soft" flow control.
|
||||||
|
|
||||||
Locking: none.
|
Locking: caller holds port->mutex
|
||||||
Interrupts: caller dependent.
|
Interrupts: caller dependent.
|
||||||
This call must not sleep
|
This call must not sleep
|
||||||
|
|
||||||
|
|
|
@ -436,7 +436,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
|
||||||
|
|
||||||
EXPORT_SYMBOL(uart_get_divisor);
|
EXPORT_SYMBOL(uart_get_divisor);
|
||||||
|
|
||||||
/* FIXME: Consistent locking policy */
|
/* Caller holds port mutex */
|
||||||
static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
|
static void uart_change_speed(struct tty_struct *tty, struct uart_state *state,
|
||||||
struct ktermios *old_termios)
|
struct ktermios *old_termios)
|
||||||
{
|
{
|
||||||
|
@ -1173,11 +1173,15 @@ uart_ioctl(struct tty_struct *tty, unsigned int cmd,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIOCSSERIAL:
|
case TIOCSSERIAL:
|
||||||
|
down_write(&tty->termios_rwsem);
|
||||||
ret = uart_set_info_user(tty, state, uarg);
|
ret = uart_set_info_user(tty, state, uarg);
|
||||||
|
up_write(&tty->termios_rwsem);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIOCSERCONFIG:
|
case TIOCSERCONFIG:
|
||||||
|
down_write(&tty->termios_rwsem);
|
||||||
ret = uart_do_autoconfig(tty, state);
|
ret = uart_do_autoconfig(tty, state);
|
||||||
|
up_write(&tty->termios_rwsem);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TIOCSERGWILD: /* obsolete */
|
case TIOCSERGWILD: /* obsolete */
|
||||||
|
@ -1278,7 +1282,9 @@ static void uart_set_termios(struct tty_struct *tty,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_lock(&state->port.mutex);
|
||||||
uart_change_speed(tty, state, old_termios);
|
uart_change_speed(tty, state, old_termios);
|
||||||
|
mutex_unlock(&state->port.mutex);
|
||||||
/* reload cflag from termios; port driver may have overriden flags */
|
/* reload cflag from termios; port driver may have overriden flags */
|
||||||
cflag = tty->termios.c_cflag;
|
cflag = tty->termios.c_cflag;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue