Commit 3ba30f30 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

drivers/s390/net/ctctty.c converted to dynamic allocation
parent 90a9326e
...@@ -70,7 +70,7 @@ typedef struct { ...@@ -70,7 +70,7 @@ typedef struct {
/* Description of one CTC-tty */ /* Description of one CTC-tty */
typedef struct { typedef struct {
struct tty_driver ctc_tty_device; /* tty-device */ struct tty_driver *ctc_tty_device; /* tty-device */
ctc_tty_info info[CTC_TTY_MAX_DEVICES]; /* Private data */ ctc_tty_info info[CTC_TTY_MAX_DEVICES]; /* Private data */
} ctc_tty_driver; } ctc_tty_driver;
...@@ -1130,6 +1130,21 @@ ctc_tty_task(unsigned long arg) ...@@ -1130,6 +1130,21 @@ ctc_tty_task(unsigned long arg)
spin_unlock_irqrestore(&ctc_tty_lock, saveflags); spin_unlock_irqrestore(&ctc_tty_lock, saveflags);
} }
static struct tty_operations ctc_ops = {
.open = ctc_tty_open,
.close = ctc_tty_close,
.write = ctc_tty_write,
.flush_chars = ctc_tty_flush_chars,
.write_room = ctc_tty_write_room,
.chars_in_buffer = ctc_tty_chars_in_buffer,
.flush_buffer = ctc_tty_flush_buffer,
.ioctl = ctc_tty_ioctl,
.throttle = ctc_tty_throttle,
.unthrottle = ctc_tty_unthrottle,
.set_termios = ctc_tty_set_termios,
.hangup = ctc_tty_hangup,
};
int int
ctc_tty_init(void) ctc_tty_init(void)
{ {
...@@ -1143,41 +1158,31 @@ ctc_tty_init(void) ...@@ -1143,41 +1158,31 @@ ctc_tty_init(void)
return -ENOMEM; return -ENOMEM;
} }
memset(driver, 0, sizeof(ctc_tty_driver)); memset(driver, 0, sizeof(ctc_tty_driver));
device = &driver->ctc_tty_device; device = alloc_tty_driver(CTC_TTY_MAX_DEVICES);
if (!device) {
kfree(driver);
printk(KERN_WARNING "Out of memory in ctc_tty_modem_init\n");
return -ENOMEM;
}
device->magic = TTY_DRIVER_MAGIC;
device->devfs_name = "ctc/" CTC_TTY_NAME; device->devfs_name = "ctc/" CTC_TTY_NAME;
device->name = CTC_TTY_NAME; device->name = CTC_TTY_NAME;
device->major = CTC_TTY_MAJOR; device->major = CTC_TTY_MAJOR;
device->minor_start = 0; device->minor_start = 0;
device->num = CTC_TTY_MAX_DEVICES;
device->type = TTY_DRIVER_TYPE_SERIAL; device->type = TTY_DRIVER_TYPE_SERIAL;
device->subtype = SERIAL_TYPE_NORMAL; device->subtype = SERIAL_TYPE_NORMAL;
device->init_termios = tty_std_termios; device->init_termios = tty_std_termios;
device->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL; device->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
device->flags = TTY_DRIVER_REAL_RAW; device->flags = TTY_DRIVER_REAL_RAW;
device->open = ctc_tty_open; device->driver_name = "ctc_tty",
device->close = ctc_tty_close; tty_set_operations(device, &ctc_ops);
device->write = ctc_tty_write;
device->put_char = NULL;
device->flush_chars = ctc_tty_flush_chars;
device->write_room = ctc_tty_write_room;
device->chars_in_buffer = ctc_tty_chars_in_buffer;
device->flush_buffer = ctc_tty_flush_buffer;
device->ioctl = ctc_tty_ioctl;
device->throttle = ctc_tty_throttle;
device->unthrottle = ctc_tty_unthrottle;
device->set_termios = ctc_tty_set_termios;
device->stop = NULL;
device->start = NULL;
device->hangup = ctc_tty_hangup;
device->driver_name = "ctc_tty";
if (tty_register_driver(device)) { if (tty_register_driver(device)) {
printk(KERN_WARNING "ctc_tty: Couldn't register serial-device\n"); printk(KERN_WARNING "ctc_tty: Couldn't register serial-device\n");
put_tty_driver(device);
kfree(driver); kfree(driver);
return -1; return -1;
} }
driver->ctc_tty_device = device;
for (i = 0; i < CTC_TTY_MAX_DEVICES; i++) { for (i = 0; i < CTC_TTY_MAX_DEVICES; i++) {
info = &driver->info[i]; info = &driver->info[i];
init_MUTEX(&info->write_sem); init_MUTEX(&info->write_sem);
...@@ -1258,8 +1263,9 @@ ctc_tty_cleanup(void) { ...@@ -1258,8 +1263,9 @@ ctc_tty_cleanup(void) {
spin_lock_irqsave(&ctc_tty_lock, saveflags); spin_lock_irqsave(&ctc_tty_lock, saveflags);
ctc_tty_shuttingdown = 1; ctc_tty_shuttingdown = 1;
tty_unregister_driver(&driver->ctc_tty_device); tty_unregister_driver(driver->ctc_tty_device);
kfree(driver); kfree(driver);
put_tty_driver(driver->ctc_tty_device);
driver = NULL; driver = NULL;
spin_unlock_irqrestore(&ctc_tty_lock, saveflags); spin_unlock_irqrestore(&ctc_tty_lock, saveflags);
} }
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