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/tty_io.c | |
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/tty_io.c')
-rw-r--r-- | drivers/char/tty_io.c | 64 |
1 files changed, 24 insertions, 40 deletions
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; |