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

[PATCH] tty_driver refcounting

drivers/char/pcmcia/synclink_cs.c converted to dynamic allocation
parent 9e5637f7
......@@ -495,7 +495,7 @@ MODULE_LICENSE("GPL");
static char *driver_name = "SyncLink PC Card driver";
static char *driver_version = "$Revision: 4.10 $";
static struct tty_driver serial_driver;
static struct tty_driver *serial_driver;
/* number of characters left in xmit buffer before we ask for more */
#define WAKEUP_CHARS 256
......@@ -3115,6 +3115,30 @@ static struct pcmcia_driver mgslpc_driver = {
.detach = mgslpc_detach,
};
static struct tty_operations mgslpc_ops = {
.open = mgslpc_open,
.close = mgslpc_close,
.write = mgslpc_write,
.put_char = mgslpc_put_char,
.flush_chars = mgslpc_flush_chars,
.write_room = mgslpc_write_room,
.chars_in_buffer = mgslpc_chars_in_buffer,
.flush_buffer = mgslpc_flush_buffer,
.ioctl = mgslpc_ioctl,
.throttle = mgslpc_throttle,
.unthrottle = mgslpc_unthrottle,
.send_xchar = mgslpc_send_xchar,
.break_ctl = mgslpc_break,
.wait_until_sent = mgslpc_wait_until_sent,
.read_proc = mgslpc_read_proc,
.set_termios = mgslpc_set_termios,
.stop = tx_pause,
.start = tx_release,
.hangup = mgslpc_hangup,
.tiocmget = tiocmget,
.tiocmset = tiocmset,
};
static int __init synclink_cs_init(void)
{
int error;
......@@ -3126,56 +3150,38 @@ static int __init synclink_cs_init(void)
printk("%s %s\n", driver_name, driver_version);
serial_driver = alloc_tty_driver(MAX_DEVICE_COUNT);
if (!serial_driver)
return -ENOMEM;
error = pcmcia_register_driver(&mgslpc_driver);
if (error)
if (error) {
put_tty_driver(serial_driver);
return error;
}
/* Initialize the tty_driver structure */
memset(&serial_driver, 0, sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.owner = THIS_MODULE;
serial_driver.driver_name = "synclink_cs";
serial_driver.name = "ttySLP";
serial_driver.major = ttymajor;
serial_driver.minor_start = 64;
serial_driver.num = MAX_DEVICE_COUNT;
serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
serial_driver.subtype = SERIAL_TYPE_NORMAL;
serial_driver.init_termios = tty_std_termios;
serial_driver.init_termios.c_cflag =
serial_driver->owner = THIS_MODULE;
serial_driver->driver_name = "synclink_cs";
serial_driver->name = "ttySLP";
serial_driver->major = ttymajor;
serial_driver->minor_start = 64;
serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
serial_driver->subtype = SERIAL_TYPE_NORMAL;
serial_driver->init_termios = tty_std_termios;
serial_driver->init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL;
serial_driver.flags = TTY_DRIVER_REAL_RAW;
serial_driver.open = mgslpc_open;
serial_driver.close = mgslpc_close;
serial_driver.write = mgslpc_write;
serial_driver.put_char = mgslpc_put_char;
serial_driver.flush_chars = mgslpc_flush_chars;
serial_driver.write_room = mgslpc_write_room;
serial_driver.chars_in_buffer = mgslpc_chars_in_buffer;
serial_driver.flush_buffer = mgslpc_flush_buffer;
serial_driver.ioctl = mgslpc_ioctl;
serial_driver.throttle = mgslpc_throttle;
serial_driver.unthrottle = mgslpc_unthrottle;
serial_driver.send_xchar = mgslpc_send_xchar;
serial_driver.break_ctl = mgslpc_break;
serial_driver.wait_until_sent = mgslpc_wait_until_sent;
serial_driver.read_proc = mgslpc_read_proc;
serial_driver.set_termios = mgslpc_set_termios;
serial_driver.stop = tx_pause;
serial_driver.start = tx_release;
serial_driver.hangup = mgslpc_hangup;
serial_driver.tiocmget = tiocmget;
serial_driver.tiocmset = tiocmset;
if (tty_register_driver(&serial_driver) < 0)
serial_driver->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(serial_driver, &mgslpc_ops);
if (tty_register_driver(serial_driver) < 0)
printk("%s(%d):Couldn't register serial driver\n",
__FILE__,__LINE__);
printk("%s %s, tty major#%d\n",
driver_name, driver_version,
serial_driver.major);
serial_driver->major);
return 0;
}
......@@ -3189,9 +3195,10 @@ static void __exit synclink_cs_exit(void)
while(mgslpc_device_list)
mgslpc_remove_device(mgslpc_device_list);
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",
__FILE__,__LINE__,rc);
put_tty_driver(serial_driver);
pcmcia_unregister_driver(&mgslpc_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