Commit 23f28a4e authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

drivers/char/synclink.c converted to dynamic allocation
parent 4dee1fc3
...@@ -932,7 +932,7 @@ static struct pci_driver synclink_pci_driver = { ...@@ -932,7 +932,7 @@ static struct pci_driver synclink_pci_driver = {
.remove = __devexit_p(synclink_remove_one), .remove = __devexit_p(synclink_remove_one),
}; };
static struct tty_driver serial_driver; static struct tty_driver *serial_driver;
/* number of characters left in xmit buffer before we ask for more */ /* number of characters left in xmit buffer before we ask for more */
#define WAKEUP_CHARS 256 #define WAKEUP_CHARS 256
...@@ -4431,6 +4431,30 @@ struct mgsl_struct* mgsl_allocate_device() ...@@ -4431,6 +4431,30 @@ struct mgsl_struct* mgsl_allocate_device()
} /* end of mgsl_allocate_device()*/ } /* end of mgsl_allocate_device()*/
static struct tty_operations mgsl_ops = {
.open = mgsl_open,
.close = mgsl_close,
.write = mgsl_write,
.put_char = mgsl_put_char,
.flush_chars = mgsl_flush_chars,
.write_room = mgsl_write_room,
.chars_in_buffer = mgsl_chars_in_buffer,
.flush_buffer = mgsl_flush_buffer,
.ioctl = mgsl_ioctl,
.throttle = mgsl_throttle,
.unthrottle = mgsl_unthrottle,
.send_xchar = mgsl_send_xchar,
.break_ctl = mgsl_break,
.wait_until_sent = mgsl_wait_until_sent,
.read_proc = mgsl_read_proc,
.set_termios = mgsl_set_termios,
.stop = mgsl_stop,
.start = mgsl_start,
.hangup = mgsl_hangup,
.tiocmget = tiocmget,
.tiocmset = tiocmset,
};
/* /*
* perform tty device initialization * perform tty device initialization
*/ */
...@@ -4438,52 +4462,29 @@ int mgsl_init_tty(void); ...@@ -4438,52 +4462,29 @@ int mgsl_init_tty(void);
int mgsl_init_tty() int mgsl_init_tty()
{ {
struct mgsl_struct *info; struct mgsl_struct *info;
/* Initialize the tty_driver structure */ serial_driver = alloc_tty_driver(mgsl_device_count);
if (!serial_driver)
memset(&serial_driver, 0, sizeof(struct tty_driver)); return -ENOMEM;
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.owner = THIS_MODULE; serial_driver->owner = THIS_MODULE;
serial_driver.driver_name = "synclink"; serial_driver->driver_name = "synclink";
serial_driver.name = "ttySL"; serial_driver->name = "ttySL";
serial_driver.major = ttymajor; serial_driver->major = ttymajor;
serial_driver.minor_start = 64; serial_driver->minor_start = 64;
serial_driver.num = mgsl_device_count; serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
serial_driver.type = TTY_DRIVER_TYPE_SERIAL; serial_driver->subtype = SERIAL_TYPE_NORMAL;
serial_driver.subtype = SERIAL_TYPE_NORMAL; serial_driver->init_termios = tty_std_termios;
serial_driver.init_termios = tty_std_termios; serial_driver->init_termios.c_cflag =
serial_driver.init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL; B9600 | CS8 | CREAD | HUPCL | CLOCAL;
serial_driver.flags = TTY_DRIVER_REAL_RAW; serial_driver->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(serial_driver, &mgsl_ops);
serial_driver.open = mgsl_open; if (tty_register_driver(serial_driver) < 0)
serial_driver.close = mgsl_close;
serial_driver.write = mgsl_write;
serial_driver.put_char = mgsl_put_char;
serial_driver.flush_chars = mgsl_flush_chars;
serial_driver.write_room = mgsl_write_room;
serial_driver.chars_in_buffer = mgsl_chars_in_buffer;
serial_driver.flush_buffer = mgsl_flush_buffer;
serial_driver.ioctl = mgsl_ioctl;
serial_driver.throttle = mgsl_throttle;
serial_driver.unthrottle = mgsl_unthrottle;
serial_driver.send_xchar = mgsl_send_xchar;
serial_driver.break_ctl = mgsl_break;
serial_driver.wait_until_sent = mgsl_wait_until_sent;
serial_driver.read_proc = mgsl_read_proc;
serial_driver.set_termios = mgsl_set_termios;
serial_driver.stop = mgsl_stop;
serial_driver.start = mgsl_start;
serial_driver.hangup = mgsl_hangup;
serial_driver.tiocmget = tiocmget;
serial_driver.tiocmset = tiocmset;
if (tty_register_driver(&serial_driver) < 0)
printk("%s(%d):Couldn't register serial driver\n", printk("%s(%d):Couldn't register serial driver\n",
__FILE__,__LINE__); __FILE__,__LINE__);
printk("%s %s, tty major#%d\n", printk("%s %s, tty major#%d\n",
driver_name, driver_version, driver_name, driver_version,
serial_driver.major); serial_driver->major);
return 0; return 0;
} }
...@@ -4572,10 +4573,11 @@ static void __exit synclink_exit(void) ...@@ -4572,10 +4573,11 @@ static void __exit synclink_exit(void)
printk("Unloading %s: %s\n", driver_name, driver_version); printk("Unloading %s: %s\n", driver_name, driver_version);
if ((rc = tty_unregister_driver(&serial_driver))) if ((rc = tty_unregister_driver(serial_driver)))
printk("%s(%d) failed to unregister tty driver err=%d\n", printk("%s(%d) failed to unregister tty driver err=%d\n",
__FILE__,__LINE__,rc); __FILE__,__LINE__,rc);
put_tty_driver(serial_driver);
info = mgsl_device_list; info = mgsl_device_list;
while(info) { while(info) {
#ifdef CONFIG_SYNCLINK_SYNCPPP #ifdef CONFIG_SYNCLINK_SYNCPPP
......
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