diff options
author | Alan Cox <alan@redhat.com> | 2008-10-13 05:42:00 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-10-13 12:51:42 -0400 |
commit | 99f1fe189daf8e99a847e420567e49dd7ee2aae7 (patch) | |
tree | 09db410aa2b32e74086593eb771c75efe553a585 /drivers/char | |
parent | 23499705753ab8b4c6b0b64e6c424a370bd900a1 (diff) |
tty: Clean up the tty_init_dev changes further
Fix up the naming, style and extract some bits of code into the driver
specific code
Signed-off-by: Alan Cox <alan@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/pty.c | 49 | ||||
-rw-r--r-- | drivers/char/tty_io.c | 64 |
2 files changed, 72 insertions, 41 deletions
diff --git a/drivers/char/pty.c b/drivers/char/pty.c index 328e8ac12306..6e148ade7353 100644 --- a/drivers/char/pty.c +++ b/drivers/char/pty.c | |||
@@ -391,6 +391,41 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file, | |||
391 | return -ENOIOCTLCMD; | 391 | return -ENOIOCTLCMD; |
392 | } | 392 | } |
393 | 393 | ||
394 | /** | ||
395 | * ptm_unix98_lookup - find a pty master | ||
396 | * @driver: ptm driver | ||
397 | * @idx: tty index | ||
398 | * | ||
399 | * Look up a pty master device. Called under the tty_mutex for now. | ||
400 | * This provides our locking. | ||
401 | */ | ||
402 | |||
403 | static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver, int idx) | ||
404 | { | ||
405 | struct tty_struct *tty = devpts_get_tty(idx); | ||
406 | if (tty) | ||
407 | tty = tty->link; | ||
408 | return tty; | ||
409 | } | ||
410 | |||
411 | /** | ||
412 | * pts_unix98_lookup - find a pty slave | ||
413 | * @driver: pts driver | ||
414 | * @idx: tty index | ||
415 | * | ||
416 | * Look up a pty master device. Called under the tty_mutex for now. | ||
417 | * This provides our locking. | ||
418 | */ | ||
419 | |||
420 | static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver, int idx) | ||
421 | { | ||
422 | struct tty_struct *tty = devpts_get_tty(idx); | ||
423 | /* Master must be open before slave */ | ||
424 | if (!tty) | ||
425 | return ERR_PTR(-EIO); | ||
426 | return tty; | ||
427 | } | ||
428 | |||
394 | static void pty_shutdown(struct tty_struct *tty) | 429 | static void pty_shutdown(struct tty_struct *tty) |
395 | { | 430 | { |
396 | /* We have our own method as we don't use the tty index */ | 431 | /* We have our own method as we don't use the tty index */ |
@@ -399,6 +434,7 @@ static void pty_shutdown(struct tty_struct *tty) | |||
399 | } | 434 | } |
400 | 435 | ||
401 | static const struct tty_operations ptm_unix98_ops = { | 436 | static const struct tty_operations ptm_unix98_ops = { |
437 | .lookup = ptm_unix98_lookup, | ||
402 | .open = pty_open, | 438 | .open = pty_open, |
403 | .close = pty_close, | 439 | .close = pty_close, |
404 | .write = pty_write, | 440 | .write = pty_write, |
@@ -411,6 +447,17 @@ static const struct tty_operations ptm_unix98_ops = { | |||
411 | .shutdown = pty_shutdown | 447 | .shutdown = pty_shutdown |
412 | }; | 448 | }; |
413 | 449 | ||
450 | static const struct tty_operations pty_unix98_ops = { | ||
451 | .lookup = pts_unix98_lookup, | ||
452 | .open = pty_open, | ||
453 | .close = pty_close, | ||
454 | .write = pty_write, | ||
455 | .write_room = pty_write_room, | ||
456 | .flush_buffer = pty_flush_buffer, | ||
457 | .chars_in_buffer = pty_chars_in_buffer, | ||
458 | .unthrottle = pty_unthrottle, | ||
459 | .set_termios = pty_set_termios, | ||
460 | }; | ||
414 | 461 | ||
415 | /** | 462 | /** |
416 | * ptmx_open - open a unix 98 pty master | 463 | * ptmx_open - open a unix 98 pty master |
@@ -517,7 +564,7 @@ static void __init unix98_pty_init(void) | |||
517 | pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | | 564 | pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | |
518 | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; | 565 | TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; |
519 | pts_driver->other = ptm_driver; | 566 | pts_driver->other = ptm_driver; |
520 | tty_set_operations(pts_driver, &pty_ops); | 567 | tty_set_operations(pts_driver, &pty_unix98_ops); |
521 | 568 | ||
522 | if (tty_register_driver(ptm_driver)) | 569 | if (tty_register_driver(ptm_driver)) |
523 | panic("Couldn't register Unix98 ptm driver"); | 570 | panic("Couldn't register Unix98 ptm driver"); |
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c index a5408496d301..ac41af8763d1 100644 --- a/drivers/char/tty_io.c +++ b/drivers/char/tty_io.c | |||
@@ -1204,53 +1204,38 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p) | |||
1204 | sprintf(p, "%s%d", driver->name, index + driver->name_base); | 1204 | sprintf(p, "%s%d", driver->name, index + driver->name_base); |
1205 | } | 1205 | } |
1206 | 1206 | ||
1207 | /* | 1207 | /** |
1208 | * find_tty() - find an existing tty, if any | 1208 | * tty_driver_lookup_tty() - find an existing tty, if any |
1209 | * @driver: the driver for the tty | 1209 | * @driver: the driver for the tty |
1210 | * @idx: the minor number | 1210 | * @idx: the minor number |
1211 | * | 1211 | * |
1212 | * Return the tty, if found or ERR_PTR() otherwise. | 1212 | * Return the tty, if found or ERR_PTR() otherwise. |
1213 | * | 1213 | * |
1214 | * Locking: tty_mutex must be held. If tty is found, the mutex must | 1214 | * Locking: tty_mutex must be held. If tty is found, the mutex must |
1215 | * be held until the 'fast-open' is also done. | 1215 | * be held until the 'fast-open' is also done. Will change once we |
1216 | * have refcounting in the driver and per driver locking | ||
1216 | */ | 1217 | */ |
1217 | struct tty_struct *find_tty(struct tty_driver *driver, int idx) | 1218 | struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver, int idx) |
1218 | { | 1219 | { |
1219 | struct tty_struct *tty; | 1220 | struct tty_struct *tty; |
1220 | 1221 | ||
1221 | /* check whether we're reopening an existing tty */ | 1222 | if (driver->ops->lookup) |
1222 | if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { | 1223 | return driver->ops->lookup(driver, idx); |
1223 | tty = devpts_get_tty(idx); | ||
1224 | /* | ||
1225 | * If we don't have a tty here on a slave open, it's because | ||
1226 | * the master already started the close process and there's | ||
1227 | * no relation between devpts file and tty anymore. | ||
1228 | */ | ||
1229 | if (!tty && driver->subtype == PTY_TYPE_SLAVE) | ||
1230 | return ERR_PTR(-EIO); | ||
1231 | 1224 | ||
1232 | /* | ||
1233 | * tty is safe on because we are called with tty_mutex held | ||
1234 | * and release_dev() won't change tty->count or tty->flags | ||
1235 | * without grabbing tty_mutex. | ||
1236 | */ | ||
1237 | if (tty && driver->subtype == PTY_TYPE_MASTER) | ||
1238 | tty = tty->link; | ||
1239 | } else | ||
1240 | tty = driver->ttys[idx]; | 1225 | tty = driver->ttys[idx]; |
1241 | return tty; | 1226 | return tty; |
1242 | } | 1227 | } |
1243 | 1228 | ||
1244 | /* | 1229 | /** |
1245 | * fast_tty_open() - fast re-open of an open tty | 1230 | * tty_reopen() - fast re-open of an open tty |
1246 | * @tty - the tty to open | 1231 | * @tty - the tty to open |
1247 | * | 1232 | * |
1248 | * Return 0 on success, -errno on error. | 1233 | * Return 0 on success, -errno on error. |
1249 | * | 1234 | * |
1250 | * Locking: tty_mutex must be held from the time the tty was found | 1235 | * Locking: tty_mutex must be held from the time the tty was found |
1251 | * till this open completes. | 1236 | * till this open completes. |
1252 | */ | 1237 | */ |
1253 | static int fast_tty_open(struct tty_struct *tty) | 1238 | static int tty_reopen(struct tty_struct *tty) |
1254 | { | 1239 | { |
1255 | struct tty_driver *driver = tty->driver; | 1240 | struct tty_driver *driver = tty->driver; |
1256 | 1241 | ||
@@ -1271,9 +1256,7 @@ static int fast_tty_open(struct tty_struct *tty) | |||
1271 | tty->count++; | 1256 | tty->count++; |
1272 | tty->driver = driver; /* N.B. why do this every time?? */ | 1257 | tty->driver = driver; /* N.B. why do this every time?? */ |
1273 | 1258 | ||
1274 | /* FIXME */ | 1259 | WARN_ON(!test_bit(TTY_LDISC, &tty->flags)); |
1275 | if (!test_bit(TTY_LDISC, &tty->flags)) | ||
1276 | printk(KERN_ERR "fast_tty_open: no ldisc\n"); | ||
1277 | 1260 | ||
1278 | return 0; | 1261 | return 0; |
1279 | } | 1262 | } |
@@ -1312,14 +1295,14 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
1312 | int retval = 0; | 1295 | int retval = 0; |
1313 | 1296 | ||
1314 | /* check whether we're reopening an existing tty */ | 1297 | /* check whether we're reopening an existing tty */ |
1315 | tty = find_tty(driver, idx); | 1298 | tty = tty_driver_lookup_tty(driver, idx); |
1316 | if (IS_ERR(tty)) { | 1299 | if (IS_ERR(tty)) { |
1317 | retval = PTR_ERR(tty); | 1300 | retval = PTR_ERR(tty); |
1318 | goto end_init; | 1301 | goto end_init; |
1319 | } | 1302 | } |
1320 | 1303 | ||
1321 | if (tty) { | 1304 | if (tty) { |
1322 | retval = fast_tty_open(tty); | 1305 | retval = tty_reopen(tty); |
1323 | if (retval) | 1306 | if (retval) |
1324 | return retval; | 1307 | return retval; |
1325 | *ret_tty = tty; | 1308 | *ret_tty = tty; |
@@ -1440,6 +1423,8 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
1440 | * All structures have been allocated, so now we install them. | 1423 | * All structures have been allocated, so now we install them. |
1441 | * Failures after this point use release_tty to clean up, so | 1424 | * Failures after this point use release_tty to clean up, so |
1442 | * there's no need to null out the local pointers. | 1425 | * there's no need to null out the local pointers. |
1426 | * | ||
1427 | * FIXME: We want a 'driver->install method ? | ||
1443 | */ | 1428 | */ |
1444 | if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) | 1429 | if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM)) |
1445 | driver->ttys[idx] = tty; | 1430 | driver->ttys[idx] = tty; |
@@ -1466,9 +1451,8 @@ int tty_init_dev(struct tty_driver *driver, int idx, | |||
1466 | 1451 | ||
1467 | if (retval) | 1452 | if (retval) |
1468 | goto release_mem_out; | 1453 | goto release_mem_out; |
1469 | success: | ||
1470 | *ret_tty = tty; | ||
1471 | 1454 | ||
1455 | *ret_tty = tty; | ||
1472 | /* All paths come through here to release the mutex */ | 1456 | /* All paths come through here to release the mutex */ |
1473 | end_init: | 1457 | end_init: |
1474 | return retval; | 1458 | return retval; |