diff options
| author | Jiri Slaby <jslaby@suse.cz> | 2012-04-02 07:54:23 -0400 |
|---|---|---|
| committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-09 14:28:18 -0400 |
| commit | 0146b6939074ebe14ece3604fd00e7be128a3812 (patch) | |
| tree | 4dba1ecf72b9a2af168e9e6a71b156344307ca2f /drivers/tty/hvc | |
| parent | 85bbc003b24335e253a392f6a9874103b77abb36 (diff) | |
TTY: HVC, use count from tty_port
Now, count is used from tty_port and protected by tty_port->lock.
n_outbuf is left unprotected in hvc_hangup now, because there is no
point to hold any lock, since other uses are unprotected too.
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Cc: linuxppc-dev@lists.ozlabs.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/tty/hvc')
| -rw-r--r-- | drivers/tty/hvc/hvc_console.c | 40 | ||||
| -rw-r--r-- | drivers/tty/hvc/hvc_console.h | 1 |
2 files changed, 21 insertions, 20 deletions
diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c index 92b7f5d5441..6c45cbf3fc9 100644 --- a/drivers/tty/hvc/hvc_console.c +++ b/drivers/tty/hvc/hvc_console.c | |||
| @@ -313,18 +313,18 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) | |||
| 313 | if (!(hp = hvc_get_by_index(tty->index))) | 313 | if (!(hp = hvc_get_by_index(tty->index))) |
| 314 | return -ENODEV; | 314 | return -ENODEV; |
| 315 | 315 | ||
| 316 | spin_lock_irqsave(&hp->lock, flags); | 316 | spin_lock_irqsave(&hp->port.lock, flags); |
| 317 | /* Check and then increment for fast path open. */ | 317 | /* Check and then increment for fast path open. */ |
| 318 | if (hp->count++ > 0) { | 318 | if (hp->port.count++ > 0) { |
| 319 | spin_unlock_irqrestore(&hp->port.lock, flags); | ||
| 320 | /* FIXME why taking a reference here? */ | ||
| 319 | tty_kref_get(tty); | 321 | tty_kref_get(tty); |
| 320 | spin_unlock_irqrestore(&hp->lock, flags); | ||
| 321 | hvc_kick(); | 322 | hvc_kick(); |
| 322 | return 0; | 323 | return 0; |
| 323 | } /* else count == 0 */ | 324 | } /* else count == 0 */ |
| 325 | spin_unlock_irqrestore(&hp->port.lock, flags); | ||
| 324 | 326 | ||
| 325 | tty->driver_data = hp; | 327 | tty->driver_data = hp; |
| 326 | spin_unlock_irqrestore(&hp->lock, flags); | ||
| 327 | |||
| 328 | tty_port_tty_set(&hp->port, tty); | 328 | tty_port_tty_set(&hp->port, tty); |
| 329 | 329 | ||
| 330 | if (hp->ops->notifier_add) | 330 | if (hp->ops->notifier_add) |
| @@ -367,10 +367,10 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) | |||
| 367 | 367 | ||
| 368 | hp = tty->driver_data; | 368 | hp = tty->driver_data; |
| 369 | 369 | ||
| 370 | spin_lock_irqsave(&hp->lock, flags); | 370 | spin_lock_irqsave(&hp->port.lock, flags); |
| 371 | 371 | ||
| 372 | if (--hp->count == 0) { | 372 | if (--hp->port.count == 0) { |
| 373 | spin_unlock_irqrestore(&hp->lock, flags); | 373 | spin_unlock_irqrestore(&hp->port.lock, flags); |
| 374 | /* We are done with the tty pointer now. */ | 374 | /* We are done with the tty pointer now. */ |
| 375 | tty_port_tty_set(&hp->port, NULL); | 375 | tty_port_tty_set(&hp->port, NULL); |
| 376 | 376 | ||
| @@ -387,10 +387,10 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) | |||
| 387 | */ | 387 | */ |
| 388 | tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); | 388 | tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); |
| 389 | } else { | 389 | } else { |
| 390 | if (hp->count < 0) | 390 | if (hp->port.count < 0) |
| 391 | printk(KERN_ERR "hvc_close %X: oops, count is %d\n", | 391 | printk(KERN_ERR "hvc_close %X: oops, count is %d\n", |
| 392 | hp->vtermno, hp->count); | 392 | hp->vtermno, hp->port.count); |
| 393 | spin_unlock_irqrestore(&hp->lock, flags); | 393 | spin_unlock_irqrestore(&hp->port.lock, flags); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | tty_kref_put(tty); | 396 | tty_kref_put(tty); |
| @@ -409,24 +409,25 @@ static void hvc_hangup(struct tty_struct *tty) | |||
| 409 | /* cancel pending tty resize work */ | 409 | /* cancel pending tty resize work */ |
| 410 | cancel_work_sync(&hp->tty_resize); | 410 | cancel_work_sync(&hp->tty_resize); |
| 411 | 411 | ||
| 412 | spin_lock_irqsave(&hp->lock, flags); | 412 | spin_lock_irqsave(&hp->port.lock, flags); |
| 413 | 413 | ||
| 414 | /* | 414 | /* |
| 415 | * The N_TTY line discipline has problems such that in a close vs | 415 | * The N_TTY line discipline has problems such that in a close vs |
| 416 | * open->hangup case this can be called after the final close so prevent | 416 | * open->hangup case this can be called after the final close so prevent |
| 417 | * that from happening for now. | 417 | * that from happening for now. |
| 418 | */ | 418 | */ |
| 419 | if (hp->count <= 0) { | 419 | if (hp->port.count <= 0) { |
| 420 | spin_unlock_irqrestore(&hp->lock, flags); | 420 | spin_unlock_irqrestore(&hp->port.lock, flags); |
| 421 | return; | 421 | return; |
| 422 | } | 422 | } |
| 423 | 423 | ||
| 424 | temp_open_count = hp->count; | 424 | temp_open_count = hp->port.count; |
| 425 | hp->count = 0; | 425 | hp->port.count = 0; |
| 426 | hp->n_outbuf = 0; | 426 | spin_unlock_irqrestore(&hp->port.lock, flags); |
| 427 | spin_unlock_irqrestore(&hp->lock, flags); | ||
| 428 | tty_port_tty_set(&hp->port, NULL); | 427 | tty_port_tty_set(&hp->port, NULL); |
| 429 | 428 | ||
| 429 | hp->n_outbuf = 0; | ||
| 430 | |||
| 430 | if (hp->ops->notifier_hangup) | 431 | if (hp->ops->notifier_hangup) |
| 431 | hp->ops->notifier_hangup(hp, hp->data); | 432 | hp->ops->notifier_hangup(hp, hp->data); |
| 432 | 433 | ||
| @@ -474,7 +475,8 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count | |||
| 474 | if (!hp) | 475 | if (!hp) |
| 475 | return -EPIPE; | 476 | return -EPIPE; |
| 476 | 477 | ||
| 477 | if (hp->count <= 0) | 478 | /* FIXME what's this (unprotected) check for? */ |
| 479 | if (hp->port.count <= 0) | ||
| 478 | return -EIO; | 480 | return -EIO; |
| 479 | 481 | ||
| 480 | spin_lock_irqsave(&hp->lock, flags); | 482 | spin_lock_irqsave(&hp->lock, flags); |
diff --git a/drivers/tty/hvc/hvc_console.h b/drivers/tty/hvc/hvc_console.h index 594a28fe0da..674d23cb919 100644 --- a/drivers/tty/hvc/hvc_console.h +++ b/drivers/tty/hvc/hvc_console.h | |||
| @@ -49,7 +49,6 @@ struct hvc_struct { | |||
| 49 | struct tty_port port; | 49 | struct tty_port port; |
| 50 | spinlock_t lock; | 50 | spinlock_t lock; |
| 51 | int index; | 51 | int index; |
| 52 | int count; | ||
| 53 | int do_wakeup; | 52 | int do_wakeup; |
| 54 | char *outbuf; | 53 | char *outbuf; |
| 55 | int outbuf_size; | 54 | int outbuf_size; |
