mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-25 13:14:07 +08:00
TTY: srmcons, convert to use tty_port
This is needed because the tty buffer will become a tty_port member later. That will help us to wipe out most of the races and checks for the tty pointer in hot paths. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Cc: Richard Henderson <rth@twiddle.net> Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru> Cc: Matt Turner <mattst88@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
ee024d494a
commit
54089d4cdc
@ -30,9 +30,8 @@ static int srm_is_registered_console = 0;
|
|||||||
#define MAX_SRM_CONSOLE_DEVICES 1 /* only support 1 console device */
|
#define MAX_SRM_CONSOLE_DEVICES 1 /* only support 1 console device */
|
||||||
|
|
||||||
struct srmcons_private {
|
struct srmcons_private {
|
||||||
struct tty_struct *tty;
|
struct tty_port port;
|
||||||
struct timer_list timer;
|
struct timer_list timer;
|
||||||
spinlock_t lock;
|
|
||||||
} srmcons_singleton;
|
} srmcons_singleton;
|
||||||
|
|
||||||
typedef union _srmcons_result {
|
typedef union _srmcons_result {
|
||||||
@ -68,20 +67,21 @@ static void
|
|||||||
srmcons_receive_chars(unsigned long data)
|
srmcons_receive_chars(unsigned long data)
|
||||||
{
|
{
|
||||||
struct srmcons_private *srmconsp = (struct srmcons_private *)data;
|
struct srmcons_private *srmconsp = (struct srmcons_private *)data;
|
||||||
|
struct tty_port *port = &srmconsp->port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int incr = 10;
|
int incr = 10;
|
||||||
|
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
if (spin_trylock(&srmcons_callback_lock)) {
|
if (spin_trylock(&srmcons_callback_lock)) {
|
||||||
if (!srmcons_do_receive_chars(srmconsp->tty))
|
if (!srmcons_do_receive_chars(port->tty))
|
||||||
incr = 100;
|
incr = 100;
|
||||||
spin_unlock(&srmcons_callback_lock);
|
spin_unlock(&srmcons_callback_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock(&srmconsp->lock);
|
spin_lock(&port->lock);
|
||||||
if (srmconsp->tty)
|
if (port->tty)
|
||||||
mod_timer(&srmconsp->timer, jiffies + incr);
|
mod_timer(&srmconsp->timer, jiffies + incr);
|
||||||
spin_unlock(&srmconsp->lock);
|
spin_unlock(&port->lock);
|
||||||
|
|
||||||
local_irq_restore(flags);
|
local_irq_restore(flags);
|
||||||
}
|
}
|
||||||
@ -157,18 +157,19 @@ static int
|
|||||||
srmcons_open(struct tty_struct *tty, struct file *filp)
|
srmcons_open(struct tty_struct *tty, struct file *filp)
|
||||||
{
|
{
|
||||||
struct srmcons_private *srmconsp = &srmcons_singleton;
|
struct srmcons_private *srmconsp = &srmcons_singleton;
|
||||||
|
struct tty_port *port = &srmconsp->port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
spin_lock_irqsave(&srmconsp->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
|
||||||
if (!srmconsp->tty) {
|
if (!port->tty) {
|
||||||
tty->driver_data = srmconsp;
|
tty->driver_data = srmconsp;
|
||||||
|
tty->port = port;
|
||||||
srmconsp->tty = tty;
|
port->tty = tty; /* XXX proper refcounting */
|
||||||
mod_timer(&srmconsp->timer, jiffies + 10);
|
mod_timer(&srmconsp->timer, jiffies + 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&srmconsp->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -177,16 +178,17 @@ static void
|
|||||||
srmcons_close(struct tty_struct *tty, struct file *filp)
|
srmcons_close(struct tty_struct *tty, struct file *filp)
|
||||||
{
|
{
|
||||||
struct srmcons_private *srmconsp = tty->driver_data;
|
struct srmcons_private *srmconsp = tty->driver_data;
|
||||||
|
struct tty_port *port = &srmconsp->port;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
|
|
||||||
spin_lock_irqsave(&srmconsp->lock, flags);
|
spin_lock_irqsave(&port->lock, flags);
|
||||||
|
|
||||||
if (tty->count == 1) {
|
if (tty->count == 1) {
|
||||||
srmconsp->tty = NULL;
|
port->tty = NULL;
|
||||||
del_timer(&srmconsp->timer);
|
del_timer(&srmconsp->timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock_irqrestore(&srmconsp->lock, flags);
|
spin_unlock_irqrestore(&port->lock, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -203,7 +205,7 @@ static const struct tty_operations srmcons_ops = {
|
|||||||
static int __init
|
static int __init
|
||||||
srmcons_init(void)
|
srmcons_init(void)
|
||||||
{
|
{
|
||||||
spin_lock_init(&srmcons_singleton.lock);
|
tty_port_init(&srmcons_singleton.port);
|
||||||
setup_timer(&srmcons_singleton.timer, srmcons_receive_chars,
|
setup_timer(&srmcons_singleton.timer, srmcons_receive_chars,
|
||||||
(unsigned long)&srmcons_singleton);
|
(unsigned long)&srmcons_singleton);
|
||||||
if (srm_is_registered_console) {
|
if (srm_is_registered_console) {
|
||||||
|
Loading…
Reference in New Issue
Block a user