Commit 1d1ae830 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

net/irda/ircomm/ircomm_tty.c converted to dynamic allocation
parent 99a21ede
...@@ -74,10 +74,31 @@ static void ircomm_tty_flow_indication(void *instance, void *sap, ...@@ -74,10 +74,31 @@ static void ircomm_tty_flow_indication(void *instance, void *sap,
static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len, static int ircomm_tty_read_proc(char *buf, char **start, off_t offset, int len,
int *eof, void *unused); int *eof, void *unused);
#endif /* CONFIG_PROC_FS */ #endif /* CONFIG_PROC_FS */
static struct tty_driver driver; static struct tty_driver *driver;
hashbin_t *ircomm_tty = NULL; hashbin_t *ircomm_tty = NULL;
static struct tty_operations ops = {
.open = ircomm_tty_open,
.close = ircomm_tty_close,
.write = ircomm_tty_write,
.write_room = ircomm_tty_write_room,
.chars_in_buffer = ircomm_tty_chars_in_buffer,
.flush_buffer = ircomm_tty_flush_buffer,
.ioctl = ircomm_tty_ioctl,
.throttle = ircomm_tty_throttle,
.unthrottle = ircomm_tty_unthrottle,
.send_xchar = ircomm_tty_send_xchar,
.set_termios = ircomm_tty_set_termios,
.stop = ircomm_tty_stop,
.start = ircomm_tty_start,
.hangup = ircomm_tty_hangup,
.wait_until_sent = ircomm_tty_wait_until_sent,
#ifdef CONFIG_PROC_FS
.read_proc = ircomm_tty_read_proc,
#endif /* CONFIG_PROC_FS */
};
/* /*
* Function ircomm_tty_init() * Function ircomm_tty_init()
* *
...@@ -86,44 +107,29 @@ hashbin_t *ircomm_tty = NULL; ...@@ -86,44 +107,29 @@ hashbin_t *ircomm_tty = NULL;
*/ */
int __init ircomm_tty_init(void) int __init ircomm_tty_init(void)
{ {
driver = alloc_tty_driver(IRCOMM_TTY_PORTS);
if (!driver)
return -ENOMEM;
ircomm_tty = hashbin_new(HB_LOCK); ircomm_tty = hashbin_new(HB_LOCK);
if (ircomm_tty == NULL) { if (ircomm_tty == NULL) {
ERROR("%s(), can't allocate hashbin!\n", __FUNCTION__); ERROR("%s(), can't allocate hashbin!\n", __FUNCTION__);
put_tty_driver(driver);
return -ENOMEM; return -ENOMEM;
} }
memset(&driver, 0, sizeof(struct tty_driver)); driver->driver_name = "ircomm";
driver.magic = TTY_DRIVER_MAGIC; driver->name = "ircomm";
driver.driver_name = "ircomm"; driver->major = IRCOMM_TTY_MAJOR;
driver.name = "ircomm"; driver->minor_start = IRCOMM_TTY_MINOR;
driver.major = IRCOMM_TTY_MAJOR; driver->type = TTY_DRIVER_TYPE_SERIAL;
driver.minor_start = IRCOMM_TTY_MINOR; driver->subtype = SERIAL_TYPE_NORMAL;
driver.num = IRCOMM_TTY_PORTS; driver->init_termios = tty_std_termios;
driver.type = TTY_DRIVER_TYPE_SERIAL; driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
driver.subtype = SERIAL_TYPE_NORMAL; driver->flags = TTY_DRIVER_REAL_RAW;
driver.init_termios = tty_std_termios; tty_set_operations(driver, &ops);
driver.init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; if (tty_register_driver(driver)) {
driver.flags = TTY_DRIVER_REAL_RAW;
driver.open = ircomm_tty_open;
driver.close = ircomm_tty_close;
driver.write = ircomm_tty_write;
driver.write_room = ircomm_tty_write_room;
driver.chars_in_buffer = ircomm_tty_chars_in_buffer;
driver.flush_buffer = ircomm_tty_flush_buffer;
driver.ioctl = ircomm_tty_ioctl;
driver.throttle = ircomm_tty_throttle;
driver.unthrottle = ircomm_tty_unthrottle;
driver.send_xchar = ircomm_tty_send_xchar;
driver.set_termios = ircomm_tty_set_termios;
driver.stop = ircomm_tty_stop;
driver.start = ircomm_tty_start;
driver.hangup = ircomm_tty_hangup;
driver.wait_until_sent = ircomm_tty_wait_until_sent;
#ifdef CONFIG_PROC_FS
driver.read_proc = ircomm_tty_read_proc;
#endif /* CONFIG_PROC_FS */
if (tty_register_driver(&driver)) {
ERROR("%s(): Couldn't register serial driver\n", __FUNCTION__); ERROR("%s(): Couldn't register serial driver\n", __FUNCTION__);
put_tty_driver(driver);
return -1; return -1;
} }
return 0; return 0;
...@@ -154,13 +160,14 @@ void __exit ircomm_tty_cleanup(void) ...@@ -154,13 +160,14 @@ void __exit ircomm_tty_cleanup(void)
IRDA_DEBUG(4, "%s()\n", __FUNCTION__ ); IRDA_DEBUG(4, "%s()\n", __FUNCTION__ );
ret = tty_unregister_driver(&driver); ret = tty_unregister_driver(driver);
if (ret) { if (ret) {
ERROR("%s(), failed to unregister driver\n", __FUNCTION__); ERROR("%s(), failed to unregister driver\n", __FUNCTION__);
return; return;
} }
hashbin_delete(ircomm_tty, (FREE_FUNC) __ircomm_tty_cleanup); hashbin_delete(ircomm_tty, (FREE_FUNC) __ircomm_tty_cleanup);
put_tty_driver(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