diff options
| author | Alan Cox <alan@redhat.com> | 2008-10-13 05:42:29 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-13 12:51:43 -0400 |
| commit | 73ec06fc5f5c8e1097a7a4a4ab2d7c6c3a007e81 (patch) | |
| tree | 2c244c8b0d853f82e479eaf72ca64d6c9209c6a6 | |
| parent | 8b0a88d5912ab549d5adac2c8498ecdaae5319a5 (diff) | |
tty: Finish fixing up the init_dev interface to use ERR_PTR
Original suggestion and proposal from Sukadev Bhattiprolu.
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
| -rw-r--r-- | drivers/char/pty.c | 6 | ||||
| -rw-r--r-- | drivers/char/tty_io.c | 52 | ||||
| -rw-r--r-- | include/linux/tty.h | 4 |
3 files changed, 27 insertions, 35 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 4e6490bda751..c98450023030 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c | |||
| @@ -501,11 +501,13 @@ static int __ptmx_open(struct inode *inode, struct file *filp) | |||
| 501 | return index; | 501 | return index; |
| 502 | 502 | ||
| 503 | mutex_lock(&tty_mutex); | 503 | mutex_lock(&tty_mutex); |
| 504 | retval = tty_init_dev(ptm_driver, index, &tty, 1); | 504 | tty = tty_init_dev(ptm_driver, index, 1); |
| 505 | mutex_unlock(&tty_mutex); | 505 | mutex_unlock(&tty_mutex); |
| 506 | 506 | ||
| 507 | if (retval) | 507 | if (IS_ERR(tty)) { |
| 508 | retval = PTR_ERR(tty); | ||
| 508 | goto out; | 509 | goto out; |
| 510 | } | ||
| 509 | 511 | ||
| 510 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ | 512 | set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */ |
| 511 | filp->private_data = tty; | 513 | filp->private_data = tty; |
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index 888380f573dc..b0ad4880c3a8 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
| @@ -1324,35 +1324,32 @@ static int tty_reopen(struct tty_struct *tty) | |||
| 1324 | * relaxed for the (most common) case of reopening a tty. | 1324 | * relaxed for the (most common) case of reopening a tty. |
| 1325 | */ | 1325 | */ |
| 1326 | 1326 | ||
| 1327 | int tty_init_dev(struct tty_driver *driver, int idx, | 1327 | struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, |
| 1328 | struct tty_struct **ret_tty, int first_ok) | 1328 | int first_ok) |
| 1329 | { | 1329 | { |
| 1330 | struct tty_struct *tty, *o_tty; | 1330 | struct tty_struct *tty, *o_tty; |
| 1331 | struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; | 1331 | struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; |
| 1332 | struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; | 1332 | struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc; |
| 1333 | int retval = 0; | 1333 | int retval; |
| 1334 | 1334 | ||
| 1335 | /* check whether we're reopening an existing tty */ | 1335 | /* check whether we're reopening an existing tty */ |
| 1336 | tty = tty_driver_lookup_tty(driver, idx); | 1336 | tty = tty_driver_lookup_tty(driver, idx); |
| 1337 | if (IS_ERR(tty)) { | 1337 | |
| 1338 | retval = PTR_ERR(tty); | 1338 | if (IS_ERR(tty)) |
| 1339 | goto end_init; | 1339 | return tty; |
| 1340 | } | ||
| 1341 | 1340 | ||
| 1342 | if (tty) { | 1341 | if (tty) { |
| 1343 | retval = tty_reopen(tty); | 1342 | retval = tty_reopen(tty); |
| 1344 | if (retval) | 1343 | if (retval) |
| 1345 | return retval; | 1344 | return ERR_PTR(retval); |
| 1346 | *ret_tty = tty; | 1345 | return tty; |
| 1347 | return 0; | ||
| 1348 | } | 1346 | } |
| 1349 | 1347 | ||
| 1350 | /* Check if pty master is being opened multiple times */ | 1348 | /* Check if pty master is being opened multiple times */ |
| 1351 | if (driver->subtype == PTY_TYPE_MASTER && | 1349 | if (driver->subtype == PTY_TYPE_MASTER && |
| 1352 | (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) { | 1350 | (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok) |
| 1353 | retval = -EIO; | 1351 | return ERR_PTR(-EIO); |
| 1354 | goto end_init; | 1352 | |
| 1355 | } | ||
| 1356 | /* | 1353 | /* |
| 1357 | * First time open is complex, especially for PTY devices. | 1354 | * First time open is complex, especially for PTY devices. |
| 1358 | * This code guarantees that either everything succeeds and the | 1355 | * This code guarantees that either everything succeeds and the |
| @@ -1361,10 +1358,8 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
| 1361 | * and locked termios may be retained.) | 1358 | * and locked termios may be retained.) |
| 1362 | */ | 1359 | */ |
| 1363 | 1360 | ||
| 1364 | if (!try_module_get(driver->owner)) { | 1361 | if (!try_module_get(driver->owner)) |
| 1365 | retval = -ENODEV; | 1362 | return ERR_PTR(-ENODEV); |
| 1366 | goto end_init; | ||
| 1367 | } | ||
| 1368 | 1363 | ||
| 1369 | o_tty = NULL; | 1364 | o_tty = NULL; |
| 1370 | tp = o_tp = NULL; | 1365 | tp = o_tp = NULL; |
| @@ -1475,7 +1470,8 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
| 1475 | tty_driver_kref_get(driver); | 1470 | tty_driver_kref_get(driver); |
| 1476 | tty->count++; | 1471 | tty->count++; |
| 1477 | 1472 | ||
| 1478 | if (tty_driver_install_tty(driver, tty) < 0) | 1473 | retval = tty_driver_install_tty(driver, tty); |
| 1474 | if (retval < 0) | ||
| 1479 | goto release_mem_out; | 1475 | goto release_mem_out; |
| 1480 | 1476 | ||
| 1481 | /* | 1477 | /* |
| @@ -1485,14 +1481,9 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
| 1485 | */ | 1481 | */ |
| 1486 | 1482 | ||
| 1487 | retval = tty_ldisc_setup(tty, o_tty); | 1483 | retval = tty_ldisc_setup(tty, o_tty); |
| 1488 | |||
| 1489 | if (retval) | 1484 | if (retval) |
| 1490 | goto release_mem_out; | 1485 | goto release_mem_out; |
| 1491 | 1486 | return tty; | |
| 1492 | *ret_tty = tty; | ||
| 1493 | /* All paths come through here to release the mutex */ | ||
| 1494 | end_init: | ||
| 1495 | return retval; | ||
| 1496 | 1487 | ||
| 1497 | /* Release locally allocated memory ... nothing placed in slots */ | 1488 | /* Release locally allocated memory ... nothing placed in slots */ |
| 1498 | free_mem_out: | 1489 | free_mem_out: |
| @@ -1507,8 +1498,7 @@ free_mem_out: | |||
| 1507 | 1498 | ||
| 1508 | fail_no_mem: | 1499 | fail_no_mem: |
| 1509 | module_put(driver->owner); | 1500 | module_put(driver->owner); |
| 1510 | retval = -ENOMEM; | 1501 | return ERR_PTR(-ENOMEM); |
| 1511 | goto end_init; | ||
| 1512 | 1502 | ||
| 1513 | /* call the tty release_tty routine to clean out this slot */ | 1503 | /* call the tty release_tty routine to clean out this slot */ |
| 1514 | release_mem_out: | 1504 | release_mem_out: |
| @@ -1516,7 +1506,7 @@ release_mem_out: | |||
| 1516 | printk(KERN_INFO "tty_init_dev: ldisc open failed, " | 1506 | printk(KERN_INFO "tty_init_dev: ldisc open failed, " |
| 1517 | "clearing slot %d\n", idx); | 1507 | "clearing slot %d\n", idx); |
| 1518 | release_tty(tty, idx); | 1508 | release_tty(tty, idx); |
| 1519 | goto end_init; | 1509 | return ERR_PTR(retval); |
| 1520 | } | 1510 | } |
| 1521 | 1511 | ||
| 1522 | void tty_free_termios(struct tty_struct *tty) | 1512 | void tty_free_termios(struct tty_struct *tty) |
| @@ -1925,11 +1915,11 @@ retry_open: | |||
| 1925 | return -ENODEV; | 1915 | return -ENODEV; |
| 1926 | } | 1916 | } |
| 1927 | got_driver: | 1917 | got_driver: |
| 1928 | retval = tty_init_dev(driver, index, &tty, 0); | 1918 | tty = tty_init_dev(driver, index, 0); |
| 1929 | mutex_unlock(&tty_mutex); | 1919 | mutex_unlock(&tty_mutex); |
| 1930 | tty_driver_kref_put(driver); | 1920 | tty_driver_kref_put(driver); |
| 1931 | if (retval) | 1921 | if (IS_ERR(tty)) |
| 1932 | return retval; | 1922 | return PTR_ERR(tty); |
| 1933 | 1923 | ||
| 1934 | filp->private_data = tty; | 1924 | filp->private_data = tty; |
| 1935 | file_move(filp, &tty->tty_files); | 1925 | file_move(filp, &tty->tty_files); |
diff --git a/include/linux/tty.h b/include/linux/tty.h index 6cc7ccc93c69..54523a37e956 100644 --- a/include/linux/tty.h +++ b/include/linux/tty.h | |||
| @@ -401,8 +401,8 @@ extern dev_t tty_devnum(struct tty_struct *tty); | |||
| 401 | extern void proc_clear_tty(struct task_struct *p); | 401 | extern void proc_clear_tty(struct task_struct *p); |
| 402 | extern struct tty_struct *get_current_tty(void); | 402 | extern struct tty_struct *get_current_tty(void); |
| 403 | extern void tty_default_fops(struct file_operations *fops); | 403 | extern void tty_default_fops(struct file_operations *fops); |
| 404 | extern int tty_init_dev(struct tty_driver *driver, int idx, | 404 | extern struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx, |
| 405 | struct tty_struct **ret_tty, int first_ok); | 405 | int first_ok); |
| 406 | extern void tty_release_dev(struct file *filp); | 406 | extern void tty_release_dev(struct file *filp); |
| 407 | 407 | ||
| 408 | extern struct mutex tty_mutex; | 408 | extern struct mutex tty_mutex; |
