aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/tty/pty.c19
-rw-r--r--drivers/tty/tty_io.c37
-rw-r--r--include/linux/tty.h4
3 files changed, 23 insertions, 37 deletions
diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
index 25c9bc783722..ac723e3c031a 100644
--- a/drivers/tty/pty.c
+++ b/drivers/tty/pty.c
@@ -316,7 +316,7 @@ done:
316 * pty_common_install - set up the pty pair 316 * pty_common_install - set up the pty pair
317 * @driver: the pty driver 317 * @driver: the pty driver
318 * @tty: the tty being instantiated 318 * @tty: the tty being instantiated
319 * @bool: legacy, true if this is BSD style 319 * @legacy: true if this is BSD style
320 * 320 *
321 * Perform the initial set up for the tty/pty pair. Called from the 321 * Perform the initial set up for the tty/pty pair. Called from the
322 * tty layer when the port is first opened. 322 * tty layer when the port is first opened.
@@ -331,18 +331,17 @@ static int pty_common_install(struct tty_driver *driver, struct tty_struct *tty,
331 int idx = tty->index; 331 int idx = tty->index;
332 int retval = -ENOMEM; 332 int retval = -ENOMEM;
333 333
334 o_tty = alloc_tty_struct();
335 if (!o_tty)
336 goto err;
337 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL); 334 ports[0] = kmalloc(sizeof **ports, GFP_KERNEL);
338 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL); 335 ports[1] = kmalloc(sizeof **ports, GFP_KERNEL);
339 if (!ports[0] || !ports[1]) 336 if (!ports[0] || !ports[1])
340 goto err_free_tty; 337 goto err;
341 if (!try_module_get(driver->other->owner)) { 338 if (!try_module_get(driver->other->owner)) {
342 /* This cannot in fact currently happen */ 339 /* This cannot in fact currently happen */
343 goto err_free_tty; 340 goto err;
344 } 341 }
345 initialize_tty_struct(o_tty, driver->other, idx); 342 o_tty = alloc_tty_struct(driver->other, idx);
343 if (!o_tty)
344 goto err_put_module;
346 345
347 if (legacy) { 346 if (legacy) {
348 /* We always use new tty termios data so we can do this 347 /* We always use new tty termios data so we can do this
@@ -387,12 +386,12 @@ err_free_termios:
387 tty_free_termios(tty); 386 tty_free_termios(tty);
388err_deinit_tty: 387err_deinit_tty:
389 deinitialize_tty_struct(o_tty); 388 deinitialize_tty_struct(o_tty);
389 free_tty_struct(o_tty);
390err_put_module:
390 module_put(o_tty->driver->owner); 391 module_put(o_tty->driver->owner);
391err_free_tty: 392err:
392 kfree(ports[0]); 393 kfree(ports[0]);
393 kfree(ports[1]); 394 kfree(ports[1]);
394 free_tty_struct(o_tty);
395err:
396 return retval; 395 return retval;
397} 396}
398 397
diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
index 714320b5e525..8fbad3410c75 100644
--- a/drivers/tty/tty_io.c
+++ b/drivers/tty/tty_io.c
@@ -157,20 +157,6 @@ static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
157static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty); 157static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
158 158
159/** 159/**
160 * alloc_tty_struct - allocate a tty object
161 *
162 * Return a new empty tty structure. The data fields have not
163 * been initialized in any way but has been zeroed
164 *
165 * Locking: none
166 */
167
168struct tty_struct *alloc_tty_struct(void)
169{
170 return kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
171}
172
173/**
174 * free_tty_struct - free a disused tty 160 * free_tty_struct - free a disused tty
175 * @tty: tty struct to free 161 * @tty: tty struct to free
176 * 162 *
@@ -1455,12 +1441,11 @@ struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx)
1455 if (!try_module_get(driver->owner)) 1441 if (!try_module_get(driver->owner))
1456 return ERR_PTR(-ENODEV); 1442 return ERR_PTR(-ENODEV);
1457 1443
1458 tty = alloc_tty_struct(); 1444 tty = alloc_tty_struct(driver, idx);
1459 if (!tty) { 1445 if (!tty) {
1460 retval = -ENOMEM; 1446 retval = -ENOMEM;
1461 goto err_module_put; 1447 goto err_module_put;
1462 } 1448 }
1463 initialize_tty_struct(tty, driver, idx);
1464 1449
1465 tty_lock(tty); 1450 tty_lock(tty);
1466 retval = tty_driver_install_tty(driver, tty); 1451 retval = tty_driver_install_tty(driver, tty);
@@ -3003,19 +2988,21 @@ static struct device *tty_get_device(struct tty_struct *tty)
3003 2988
3004 2989
3005/** 2990/**
3006 * initialize_tty_struct 2991 * alloc_tty_struct
3007 * @tty: tty to initialize
3008 * 2992 *
3009 * This subroutine initializes a tty structure that has been newly 2993 * This subroutine allocates and initializes a tty structure.
3010 * allocated.
3011 * 2994 *
3012 * Locking: none - tty in question must not be exposed at this point 2995 * Locking: none - tty in question is not exposed at this point
3013 */ 2996 */
3014 2997
3015void initialize_tty_struct(struct tty_struct *tty, 2998struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx)
3016 struct tty_driver *driver, int idx)
3017{ 2999{
3018 memset(tty, 0, sizeof(struct tty_struct)); 3000 struct tty_struct *tty;
3001
3002 tty = kzalloc(sizeof(*tty), GFP_KERNEL);
3003 if (!tty)
3004 return NULL;
3005
3019 kref_init(&tty->kref); 3006 kref_init(&tty->kref);
3020 tty->magic = TTY_MAGIC; 3007 tty->magic = TTY_MAGIC;
3021 tty_ldisc_init(tty); 3008 tty_ldisc_init(tty);
@@ -3039,6 +3026,8 @@ void initialize_tty_struct(struct tty_struct *tty,
3039 tty->index = idx; 3026 tty->index = idx;
3040 tty_line_name(driver, idx, tty->name); 3027 tty_line_name(driver, idx, tty->name);
3041 tty->dev = tty_get_device(tty); 3028 tty->dev = tty_get_device(tty);
3029
3030 return tty;
3042} 3031}
3043 3032
3044/** 3033/**
diff --git a/include/linux/tty.h b/include/linux/tty.h
index 1c3316a47d7e..84132942902a 100644
--- a/include/linux/tty.h
+++ b/include/linux/tty.h
@@ -477,13 +477,11 @@ extern int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
477 unsigned int cmd, unsigned long arg); 477 unsigned int cmd, unsigned long arg);
478extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg); 478extern int tty_perform_flush(struct tty_struct *tty, unsigned long arg);
479extern void tty_default_fops(struct file_operations *fops); 479extern void tty_default_fops(struct file_operations *fops);
480extern struct tty_struct *alloc_tty_struct(void); 480extern struct tty_struct *alloc_tty_struct(struct tty_driver *driver, int idx);
481extern int tty_alloc_file(struct file *file); 481extern int tty_alloc_file(struct file *file);
482extern void tty_add_file(struct tty_struct *tty, struct file *file); 482extern void tty_add_file(struct tty_struct *tty, struct file *file);
483extern void tty_free_file(struct file *file); 483extern void tty_free_file(struct file *file);
484extern void free_tty_struct(struct tty_struct *tty); 484extern void free_tty_struct(struct tty_struct *tty);
485extern void initialize_tty_struct(struct tty_struct *tty,
486 struct tty_driver *driver, int idx);
487extern void deinitialize_tty_struct(struct tty_struct *tty); 485extern void deinitialize_tty_struct(struct tty_struct *tty);
488extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx); 486extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx);
489extern int tty_release(struct inode *inode, struct file *filp); 487extern int tty_release(struct inode *inode, struct file *filp);