Commit 6cc6a67d authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] tty_driver refcounting

drivers/char/esp.c converted to dynamic allocation
parent 33621cc6
...@@ -109,7 +109,7 @@ static char serial_version[] __initdata = "2.2"; ...@@ -109,7 +109,7 @@ static char serial_version[] __initdata = "2.2";
static DECLARE_TASK_QUEUE(tq_esp); static DECLARE_TASK_QUEUE(tq_esp);
static struct tty_driver esp_driver; static struct tty_driver *esp_driver;
/* serial subtype definitions */ /* serial subtype definitions */
#define SERIAL_TYPE_NORMAL 1 #define SERIAL_TYPE_NORMAL 1
...@@ -2442,6 +2442,26 @@ static _INLINE_ int autoconfig(struct esp_struct * info, int *region_start) ...@@ -2442,6 +2442,26 @@ static _INLINE_ int autoconfig(struct esp_struct * info, int *region_start)
return (port_detected); return (port_detected);
} }
static struct tty_operations esp_ops = {
.open = esp_open,
.close = rs_close,
.write = rs_write,
.put_char = rs_put_char,
.flush_chars = rs_flush_chars,
.write_room = rs_write_room,
.chars_in_buffer = rs_chars_in_buffer,
.flush_buffer = rs_flush_buffer,
.ioctl = rs_ioctl,
.throttle = rs_throttle,
.unthrottle = rs_unthrottle,
.set_termios = rs_set_termios,
.stop = rs_stop,
.start = rs_start,
.hangup = esp_hangup,
.break_ctl = esp_break,
.wait_until_sent = rs_wait_until_sent,
};
/* /*
* The serial driver boot-time initialization code! * The serial driver boot-time initialization code!
*/ */
...@@ -2453,6 +2473,10 @@ int __init espserial_init(void) ...@@ -2453,6 +2473,10 @@ int __init espserial_init(void)
struct esp_struct *last_primary = 0; struct esp_struct *last_primary = 0;
int esp[] = {0x100,0x140,0x180,0x200,0x240,0x280,0x300,0x380}; int esp[] = {0x100,0x140,0x180,0x200,0x240,0x280,0x300,0x380};
esp_driver = alloc_tty_driver(NR_PORTS);
if (!esp_driver)
return -ENOMEM;
init_bh(ESP_BH, do_serial_bh); init_bh(ESP_BH, do_serial_bh);
for (i = 0; i < NR_PRIMARY; i++) { for (i = 0; i < NR_PRIMARY; i++) {
...@@ -2490,41 +2514,21 @@ int __init espserial_init(void) ...@@ -2490,41 +2514,21 @@ int __init espserial_init(void)
/* Initialize the tty_driver structure */ /* Initialize the tty_driver structure */
memset(&esp_driver, 0, sizeof(struct tty_driver)); esp_driver->owner = THIS_MODULE;
esp_driver.magic = TTY_DRIVER_MAGIC; esp_driver->name = "ttyP";
esp_driver.owner = THIS_MODULE; esp_driver->major = ESP_IN_MAJOR;
esp_driver.name = "ttyP"; esp_driver->minor_start = 0;
esp_driver.major = ESP_IN_MAJOR; esp_driver->type = TTY_DRIVER_TYPE_SERIAL;
esp_driver.minor_start = 0; esp_driver->subtype = SERIAL_TYPE_NORMAL;
esp_driver.num = NR_PORTS; esp_driver->init_termios = tty_std_termios;
esp_driver.type = TTY_DRIVER_TYPE_SERIAL; esp_driver->init_termios.c_cflag =
esp_driver.subtype = SERIAL_TYPE_NORMAL;
esp_driver.init_termios = tty_std_termios;
esp_driver.init_termios.c_cflag =
B9600 | CS8 | CREAD | HUPCL | CLOCAL; B9600 | CS8 | CREAD | HUPCL | CLOCAL;
esp_driver.flags = TTY_DRIVER_REAL_RAW; esp_driver->flags = TTY_DRIVER_REAL_RAW;
tty_set_operations(esp_driver, &esp_ops);
esp_driver.open = esp_open; if (tty_register_driver(esp_driver))
esp_driver.close = rs_close;
esp_driver.write = rs_write;
esp_driver.put_char = rs_put_char;
esp_driver.flush_chars = rs_flush_chars;
esp_driver.write_room = rs_write_room;
esp_driver.chars_in_buffer = rs_chars_in_buffer;
esp_driver.flush_buffer = rs_flush_buffer;
esp_driver.ioctl = rs_ioctl;
esp_driver.throttle = rs_throttle;
esp_driver.unthrottle = rs_unthrottle;
esp_driver.set_termios = rs_set_termios;
esp_driver.stop = rs_stop;
esp_driver.start = rs_start;
esp_driver.hangup = esp_hangup;
esp_driver.break_ctl = esp_break;
esp_driver.wait_until_sent = rs_wait_until_sent;
if (tty_register_driver(&esp_driver))
{ {
printk(KERN_ERR "Couldn't register esp serial driver"); printk(KERN_ERR "Couldn't register esp serial driver");
put_tty_driver(esp_driver);
return 1; return 1;
} }
...@@ -2533,7 +2537,8 @@ int __init espserial_init(void) ...@@ -2533,7 +2537,8 @@ int __init espserial_init(void)
if (!info) if (!info)
{ {
printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n"); printk(KERN_ERR "Couldn't allocate memory for esp serial device information\n");
tty_unregister_driver(&esp_driver); tty_unregister_driver(esp_driver);
put_tty_driver(esp_driver);
return 1; return 1;
} }
...@@ -2636,10 +2641,11 @@ static void __exit espserial_exit(void) ...@@ -2636,10 +2641,11 @@ static void __exit espserial_exit(void)
save_flags(flags); save_flags(flags);
cli(); cli();
remove_bh(ESP_BH); remove_bh(ESP_BH);
if ((e1 = tty_unregister_driver(&esp_driver))) if ((e1 = tty_unregister_driver(esp_driver)))
printk("SERIAL: failed to unregister serial driver (%d)\n", printk("SERIAL: failed to unregister serial driver (%d)\n",
e1); e1);
restore_flags(flags); restore_flags(flags);
put_tty_driver(esp_driver);
while (ports) { while (ports) {
if (ports->port) { if (ports->port) {
......
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