aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Slaby <jslaby@suse.cz>2012-06-04 07:35:30 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-06-13 20:30:15 -0400
commitd03702a27df017d1807fd4809f03adaa8e37005f (patch)
treee6ac398d123921fcf98adfae9d8d5bdf4e5380b3
parent5d249bc6a61e7a434c69e0d0becc77a803c8c5e8 (diff)
PTY: add tty_port
This has *no* function in the PTY driver yet. However as the tty buffers will move to the tty_port structure, we will need tty_port for all TTYs in the system, PTY inclusive. For PTYs this is ensured by allocating 2 tty_port's in pty_install, i.e. where the tty->link is allocated. Both tty_port's are properly assigned to each end of the tty. Freeing is done at the same place where tty is freed, i.e. in tty->ops->cleanup. This means BTW that tty_port does not outlive TTY in PTY. This might be a subject to change in the future if we see some problems. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/tty/pty.c25
1 files changed, 21 insertions, 4 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 881888f0a445..b50fc1c01415 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -286,12 +286,15 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
286 bool legacy) 286 bool legacy)
287{ 287{
288 struct tty_struct *o_tty; 288 struct tty_struct *o_tty;
289 struct tty_port *ports[2];
289 int idx = tty->index; 290 int idx = tty->index;
290 int retval = -ENOMEM; 291 int retval = -ENOMEM;
291 292
292 o_tty = alloc_tty_struct(); 293 o_tty = alloc_tty_struct();
293 if (!o_tty) 294 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
294 goto err; 295 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
296 if (!o_tty || !ports[0] || !ports[1])
297 goto err_free_tty;
295 if (!try_module_get(driver->other->owner)) { 298 if (!try_module_get(driver->other->owner)) {
296 /* This cannot in fact currently happen */ 299 /* This cannot in fact currently happen */
297 goto err_free_tty; 300 goto err_free_tty;
@@ -335,6 +338,10 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
335 /* Establish the links in both directions */ 338 /* Establish the links in both directions */
336 tty->link = o_tty; 339 tty->link = o_tty;
337 o_tty->link = tty; 340 o_tty->link = tty;
341 tty_port_init(ports[0]);
342 tty_port_init(ports[1]);
343 o_tty->port = ports[0];
344 tty->port = ports[1];
338 345
339 tty_driver_kref_get(driver); 346 tty_driver_kref_get(driver);
340 tty->count++; 347 tty->count++;
@@ -348,11 +355,17 @@ err_deinit_tty:
348 deinitialize_tty_struct(o_tty); 355 deinitialize_tty_struct(o_tty);
349 module_put(o_tty->driver->owner); 356 module_put(o_tty->driver->owner);
350err_free_tty: 357err_free_tty:
358 kfree(ports[0]);
359 kfree(ports[1]);
351 free_tty_struct(o_tty); 360 free_tty_struct(o_tty);
352err:
353 return retval; 361 return retval;
354} 362}
355 363
364static void pty_cleanup(struct tty_struct *tty)
365{
366 kfree(tty->port);
367}
368
356/* Traditional BSD devices */ 369/* Traditional BSD devices */
357#ifdef CONFIG_LEGACY_PTYS 370#ifdef CONFIG_LEGACY_PTYS
358 371
@@ -391,6 +404,7 @@ static const struct tty_operations master_pty_ops_bsd = {
391 .unthrottle = pty_unthrottle, 404 .unthrottle = pty_unthrottle,
392 .set_termios = pty_set_termios, 405 .set_termios = pty_set_termios,
393 .ioctl = pty_bsd_ioctl, 406 .ioctl = pty_bsd_ioctl,
407 .cleanup = pty_cleanup,
394 .resize = pty_resize 408 .resize = pty_resize
395}; 409};
396 410
@@ -404,6 +418,7 @@ static const struct tty_operations slave_pty_ops_bsd = {
404 .chars_in_buffer = pty_chars_in_buffer, 418 .chars_in_buffer = pty_chars_in_buffer,
405 .unthrottle = pty_unthrottle, 419 .unthrottle = pty_unthrottle,
406 .set_termios = pty_set_termios, 420 .set_termios = pty_set_termios,
421 .cleanup = pty_cleanup,
407 .resize = pty_resize 422 .resize = pty_resize
408}; 423};
409 424
@@ -555,6 +570,7 @@ static const struct tty_operations ptm_unix98_ops = {
555 .set_termios = pty_set_termios, 570 .set_termios = pty_set_termios,
556 .ioctl = pty_unix98_ioctl, 571 .ioctl = pty_unix98_ioctl,
557 .shutdown = pty_unix98_shutdown, 572 .shutdown = pty_unix98_shutdown,
573 .cleanup = pty_cleanup,
558 .resize = pty_resize 574 .resize = pty_resize
559}; 575};
560 576
@@ -570,7 +586,8 @@ static const struct tty_operations pty_unix98_ops = {
570 .chars_in_buffer = pty_chars_in_buffer, 586 .chars_in_buffer = pty_chars_in_buffer,
571 .unthrottle = pty_unthrottle, 587 .unthrottle = pty_unthrottle,
572 .set_termios = pty_set_termios, 588 .set_termios = pty_set_termios,
573 .shutdown = pty_unix98_shutdown 589 .shutdown = pty_unix98_shutdown,
590 .cleanup = pty_cleanup,
574}; 591};
575 592
576/** 593/**