Commit 8e46bef9 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

drivers/char/istallion.c converted to dynamic allocation
parent aade9842
......@@ -170,7 +170,7 @@ static char *stli_drvname = "istallion";
static char *stli_drvversion = "5.6.0";
static char *stli_serialname = "ttyE";
static struct tty_driver stli_serial;
static struct tty_driver *stli_serial;
/*
* We will need to allocate a temporary write buffer for chars that
......@@ -847,13 +847,14 @@ static void __exit istallion_module_exit(void)
del_timer(&stli_timerlist);
}
i = tty_unregister_driver(&stli_serial);
i = tty_unregister_driver(stli_serial);
if (i) {
printk("STALLION: failed to un-register tty driver, "
"errno=%d,%d\n", -i);
restore_flags(flags);
return;
}
put_tty_driver(stli_serial);
for (i = 0; i < 4; i++)
devfs_remove("staliomem/%d", i);
devfs_remove("staliomem");
......@@ -5237,6 +5238,28 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
return(rc);
}
static struct tty_operations stli_ops = {
.open = stli_open,
.close = stli_close,
.write = stli_write,
.put_char = stli_putchar,
.flush_chars = stli_flushchars,
.write_room = stli_writeroom,
.chars_in_buffer = stli_charsinbuffer,
.ioctl = stli_ioctl,
.set_termios = stli_settermios,
.throttle = stli_throttle,
.unthrottle = stli_unthrottle,
.stop = stli_stop,
.start = stli_start,
.hangup = stli_hangup,
.flush_buffer = stli_flushbuffer,
.break_ctl = stli_breakctl,
.wait_until_sent = stli_waituntilsent,
.send_xchar = stli_sendxchar,
.read_proc = stli_readproc,
};
/*****************************************************************************/
int __init stli_init(void)
......@@ -5246,6 +5269,10 @@ int __init stli_init(void)
stli_initbrds();
stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
if (!stli_serial)
return -ENOMEM;
/*
* Allocate a temporary write buffer.
*/
......@@ -5276,41 +5303,22 @@ int __init stli_init(void)
/*
* Set up the tty driver structure and register us as a driver.
*/
memset(&stli_serial, 0, sizeof(struct tty_driver));
stli_serial.magic = TTY_DRIVER_MAGIC;
stli_serial.owner = THIS_MODULE;
stli_serial.driver_name = stli_drvname;
stli_serial.name = stli_serialname;
stli_serial.major = STL_SERIALMAJOR;
stli_serial.minor_start = 0;
stli_serial.num = STL_MAXBRDS * STL_MAXPORTS;
stli_serial.type = TTY_DRIVER_TYPE_SERIAL;
stli_serial.subtype = SERIAL_TYPE_NORMAL;
stli_serial.init_termios = stli_deftermios;
stli_serial.flags = TTY_DRIVER_REAL_RAW;
stli_serial.open = stli_open;
stli_serial.close = stli_close;
stli_serial.write = stli_write;
stli_serial.put_char = stli_putchar;
stli_serial.flush_chars = stli_flushchars;
stli_serial.write_room = stli_writeroom;
stli_serial.chars_in_buffer = stli_charsinbuffer;
stli_serial.ioctl = stli_ioctl;
stli_serial.set_termios = stli_settermios;
stli_serial.throttle = stli_throttle;
stli_serial.unthrottle = stli_unthrottle;
stli_serial.stop = stli_stop;
stli_serial.start = stli_start;
stli_serial.hangup = stli_hangup;
stli_serial.flush_buffer = stli_flushbuffer;
stli_serial.break_ctl = stli_breakctl;
stli_serial.wait_until_sent = stli_waituntilsent;
stli_serial.send_xchar = stli_sendxchar;
stli_serial.read_proc = stli_readproc;
if (tty_register_driver(&stli_serial))
stli_serial->owner = THIS_MODULE;
stli_serial->driver_name = stli_drvname;
stli_serial->name = stli_serialname;
stli_serial->major = STL_SERIALMAJOR;
stli_serial->minor_start = 0;
stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
stli_serial->subtype = SERIAL_TYPE_NORMAL;
stli_serial->init_termios = stli_deftermios;
stli_serial->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(stli_serial, &stli_ops);
if (tty_register_driver(stli_serial)) {
put_tty_driver(stli_serial);
printk(KERN_ERR "STALLION: failed to register serial driver\n");
return -EBUSY;
}
return(0);
}
......
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