Commit f50308a8 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

drivers/char/specialix.c converted to dynamic allocation
parent c3527bf0
...@@ -176,7 +176,7 @@ DECLARE_TASK_QUEUE(tq_specialix); ...@@ -176,7 +176,7 @@ DECLARE_TASK_QUEUE(tq_specialix);
#undef RS_EVENT_WRITE_WAKEUP #undef RS_EVENT_WRITE_WAKEUP
#define RS_EVENT_WRITE_WAKEUP 0 #define RS_EVENT_WRITE_WAKEUP 0
static struct tty_driver specialix_driver; static struct tty_driver *specialix_driver;
static unsigned char * tmp_buf; static unsigned char * tmp_buf;
static DECLARE_MUTEX(tmp_buf_sem); static DECLARE_MUTEX(tmp_buf_sem);
...@@ -2151,48 +2151,54 @@ static void do_softint(void *private_) ...@@ -2151,48 +2151,54 @@ static void do_softint(void *private_)
} }
} }
static struct tty_operations sx_ops = {
.open = sx_open,
.close = sx_close,
.write = sx_write,
.put_char = sx_put_char,
.flush_chars = sx_flush_chars,
.write_room = sx_write_room,
.chars_in_buffer = sx_chars_in_buffer,
.flush_buffer = sx_flush_buffer,
.ioctl = sx_ioctl,
.throttle = sx_throttle,
.unthrottle = sx_unthrottle,
.set_termios = sx_set_termios,
.stop = sx_stop,
.start = sx_start,
.hangup = sx_hangup,
};
static int sx_init_drivers(void) static int sx_init_drivers(void)
{ {
int error; int error;
int i; int i;
specialix_driver = alloc_tty_driver(SX_NBOARD * SX_NPORT);
if (!specialix_driver) {
printk(KERN_ERR "sx: Couldn't allocate tty_driver.\n");
return 1;
}
if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) { if (!(tmp_buf = (unsigned char *) get_zeroed_page(GFP_KERNEL))) {
printk(KERN_ERR "sx: Couldn't get free page.\n"); printk(KERN_ERR "sx: Couldn't get free page.\n");
put_tty_driver(specialix_driver);
return 1; return 1;
} }
init_bh(SPECIALIX_BH, do_specialix_bh); init_bh(SPECIALIX_BH, do_specialix_bh);
memset(&specialix_driver, 0, sizeof(specialix_driver)); specialix_driver->owner = THIS_MODULE;
specialix_driver.magic = TTY_DRIVER_MAGIC; specialix_driver->name = "ttyW";
specialix_driver.owner = THIS_MODULE; specialix_driver->major = SPECIALIX_NORMAL_MAJOR;
specialix_driver.name = "ttyW"; specialix_driver->type = TTY_DRIVER_TYPE_SERIAL;
specialix_driver.major = SPECIALIX_NORMAL_MAJOR; specialix_driver->subtype = SERIAL_TYPE_NORMAL;
specialix_driver.num = SX_NBOARD * SX_NPORT; specialix_driver->init_termios = tty_std_termios;
specialix_driver.type = TTY_DRIVER_TYPE_SERIAL; specialix_driver->init_termios.c_cflag =
specialix_driver.subtype = SERIAL_TYPE_NORMAL;
specialix_driver.init_termios = tty_std_termios;
specialix_driver.init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL; B9600 | CS8 | CREAD | HUPCL | CLOCAL;
specialix_driver.flags = TTY_DRIVER_REAL_RAW; specialix_driver->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(specialix_driver, &sx_ops);
specialix_driver.open = sx_open;
specialix_driver.close = sx_close; if ((error = tty_register_driver(specialix_driver))) {
specialix_driver.write = sx_write; put_tty_driver(specialix_driver);
specialix_driver.put_char = sx_put_char;
specialix_driver.flush_chars = sx_flush_chars;
specialix_driver.write_room = sx_write_room;
specialix_driver.chars_in_buffer = sx_chars_in_buffer;
specialix_driver.flush_buffer = sx_flush_buffer;
specialix_driver.ioctl = sx_ioctl;
specialix_driver.throttle = sx_throttle;
specialix_driver.unthrottle = sx_unthrottle;
specialix_driver.set_termios = sx_set_termios;
specialix_driver.stop = sx_stop;
specialix_driver.start = sx_start;
specialix_driver.hangup = sx_hangup;
if ((error = tty_register_driver(&specialix_driver))) {
free_page((unsigned long)tmp_buf); free_page((unsigned long)tmp_buf);
printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n", printk(KERN_ERR "sx: Couldn't register specialix IO8+ driver, error = %d\n",
error); error);
...@@ -2218,7 +2224,8 @@ static int sx_init_drivers(void) ...@@ -2218,7 +2224,8 @@ static int sx_init_drivers(void)
static void sx_release_drivers(void) static void sx_release_drivers(void)
{ {
free_page((unsigned long)tmp_buf); free_page((unsigned long)tmp_buf);
tty_unregister_driver(&specialix_driver); tty_unregister_driver(specialix_driver);
put_tty_driver(specialix_driver);
} }
......
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