aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tty_io.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-10-13 05:42:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-13 12:51:43 -0400
commit73ec06fc5f5c8e1097a7a4a4ab2d7c6c3a007e81 (patch)
tree2c244c8b0d853f82e479eaf72ca64d6c9209c6a6 /drivers/char/tty_io.c
parent8b0a88d5912ab549d5adac2c8498ecdaae5319a5 (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>
Diffstat (limited to 'drivers/char/tty_io.c')
-rw-r--r--drivers/char/tty_io.c52
1 files changed, 21 insertions, 31 deletions
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
1327int tty_init_dev(struct tty_driver *driver, int idx, 1327struct 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 */
1494end_init:
1495 return retval;
1496 1487
1497 /* Release locally allocated memory ... nothing placed in slots */ 1488 /* Release locally allocated memory ... nothing placed in slots */
1498free_mem_out: 1489free_mem_out:
@@ -1507,8 +1498,7 @@ free_mem_out:
1507 1498
1508fail_no_mem: 1499fail_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 */
1514release_mem_out: 1504release_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
1522void tty_free_termios(struct tty_struct *tty) 1512void tty_free_termios(struct tty_struct *tty)
@@ -1925,11 +1915,11 @@ retry_open:
1925 return -ENODEV; 1915 return -ENODEV;
1926 } 1916 }
1927got_driver: 1917got_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);