Commit 5d85b66a authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

arch/v850/kernel/{memcons,simcons}.c converted to dynamic allocation
parent 174cc1e5
...@@ -58,11 +58,12 @@ static void memcons_write (struct console *co, const char *buf, unsigned len) ...@@ -58,11 +58,12 @@ static void memcons_write (struct console *co, const char *buf, unsigned len)
len -= write (buf, len); len -= write (buf, len);
} }
extern struct tty_driver tty_driver; static struct tty_driver *tty_driver;
static struct tty_driver *memcons_device (struct console *co, int *index) static struct tty_driver *memcons_device (struct console *co, int *index)
{ {
*index = co->index; *index = co->index;
return &tty_driver; return tty_driver;
} }
static struct console memcons = static struct console memcons =
...@@ -82,8 +83,6 @@ void memcons_setup (void) ...@@ -82,8 +83,6 @@ void memcons_setup (void)
/* Higher level TTY interface. */ /* Higher level TTY interface. */
static struct tty_driver tty_driver = { 0 };
int memcons_tty_open (struct tty_struct *tty, struct file *filp) int memcons_tty_open (struct tty_struct *tty, struct file *filp)
{ {
return 0; return 0;
...@@ -106,21 +105,32 @@ int memcons_tty_chars_in_buffer (struct tty_struct *tty) ...@@ -106,21 +105,32 @@ int memcons_tty_chars_in_buffer (struct tty_struct *tty)
return 0; return 0;
} }
static struct tty_operations ops = {
.open = memcons_tty_open,
.write = memcons_tty_write,
.write_room = memcons_tty_write_room,
.chars_in_buffer = memcons_tty_chars_in_buffer,
};
int __init memcons_tty_init (void) int __init memcons_tty_init (void)
{ {
tty_driver.name = "memcons"; int err;
tty_driver.major = TTY_MAJOR; struct tty_driver *driver = alloc_tty_driver(1);
tty_driver.minor_start = 64; if (!driver)
tty_driver.num = 1; return -ENOMEM;
tty_driver.type = TTY_DRIVER_TYPE_SYSCONS;
driver->name = "memcons";
tty_driver.init_termios = tty_std_termios; driver->major = TTY_MAJOR;
driver->minor_start = 64;
tty_driver.open = memcons_tty_open; driver->type = TTY_DRIVER_TYPE_SYSCONS;
tty_driver.write = memcons_tty_write; driver->init_termios = tty_std_termios;
tty_driver.write_room = memcons_tty_write_room; tty_set_operations(driver, &ops);
tty_driver.chars_in_buffer = memcons_tty_chars_in_buffer; err = tty_register_driver(driver);
if (err) {
tty_register_driver (&tty_driver); put_tty_driver(driver);
return err;
}
tty_driver = driver;
return 0;
} }
__initcall (memcons_tty_init); __initcall (memcons_tty_init);
...@@ -35,11 +35,11 @@ static int simcons_read (struct console *co, const char *buf, unsigned len) ...@@ -35,11 +35,11 @@ static int simcons_read (struct console *co, const char *buf, unsigned len)
return V850_SIM_SYSCALL (read, 0, buf, len); return V850_SIM_SYSCALL (read, 0, buf, len);
} }
extern struct tty_driver tty_driver; static struct tty_driver *tty_driver;
static struct tty_driver *simcons_device (struct console *c, int *index) static struct tty_driver *simcons_device (struct console *c, int *index)
{ {
*index = c->index; *index = c->index;
return &tty_driver; return tty_driver;
} }
static struct console simcons = static struct console simcons =
...@@ -54,8 +54,6 @@ static struct console simcons = ...@@ -54,8 +54,6 @@ static struct console simcons =
/* Higher level TTY interface. */ /* Higher level TTY interface. */
static struct tty_driver tty_driver = { 0 };
int simcons_tty_open (struct tty_struct *tty, struct file *filp) int simcons_tty_open (struct tty_struct *tty, struct file *filp)
{ {
return 0; return 0;
...@@ -79,22 +77,32 @@ int simcons_tty_chars_in_buffer (struct tty_struct *tty) ...@@ -79,22 +77,32 @@ int simcons_tty_chars_in_buffer (struct tty_struct *tty)
return 0; return 0;
} }
static struct tty_operations ops = {
.open = simcons_tty_open,
.write = simcons_tty_write,
.write_room = simcons_tty_write_room,
.chars_in_buffer = simcons_tty_chars_in_buffer,
};
int __init simcons_tty_init (void) int __init simcons_tty_init (void)
{ {
tty_driver.name = "simcons"; struct tty_driver *driver = alloc_tty_driver(1);
tty_driver.major = TTY_MAJOR; int err;
tty_driver.minor_start = 64; if (!driver)
tty_driver.num = 1; return -ENOMEM;
tty_driver.type = TTY_DRIVER_TYPE_SYSCONS; driver->name = "simcons";
driver->major = TTY_MAJOR;
tty_driver.init_termios = tty_std_termios; driver->minor_start = 64;
driver->type = TTY_DRIVER_TYPE_SYSCONS;
tty_driver.open = simcons_tty_open; driver->init_termios = tty_std_termios;
tty_driver.write = simcons_tty_write; tty_set_operations(driver, &ops);
tty_driver.write_room = simcons_tty_write_room; err = tty_register_driver(driver);
tty_driver.chars_in_buffer = simcons_tty_chars_in_buffer; if (err) {
put_tty_driver(driver);
tty_register_driver (&tty_driver); return err;
}
tty_driver = driver;
return 0;
} }
__initcall (simcons_tty_init); __initcall (simcons_tty_init);
...@@ -139,8 +147,8 @@ void simcons_poll_tty (struct tty_struct *tty) ...@@ -139,8 +147,8 @@ void simcons_poll_tty (struct tty_struct *tty)
void simcons_poll_ttys (void) void simcons_poll_ttys (void)
{ {
if (tty_driver.ttys[0]) if (tty_driver && tty_driver->ttys[0])
simcons_poll_tty (tty_driver.ttys[0]); simcons_poll_tty (tty_driver->ttys[0]);
} }
void simcons_setup (void) void simcons_setup (void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment