Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
0146b693 85bbc003

+21 -20
+21 -19
drivers/tty/hvc/hvc_console.c
··· 313 313 if (!(hp = hvc_get_by_index(tty->index))) 314 314 return -ENODEV; 315 315 316 - spin_lock_irqsave(&hp->lock, flags); 316 + spin_lock_irqsave(&hp->port.lock, flags); 317 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 321 tty_kref_get(tty); 320 - spin_unlock_irqrestore(&hp->lock, flags); 321 322 hvc_kick(); 322 323 return 0; 323 324 } /* else count == 0 */ 325 + spin_unlock_irqrestore(&hp->port.lock, flags); 324 326 325 327 tty->driver_data = hp; 326 - spin_unlock_irqrestore(&hp->lock, flags); 327 - 328 328 tty_port_tty_set(&hp->port, tty); 329 329 330 330 if (hp->ops->notifier_add) ··· 367 367 368 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) { 373 - spin_unlock_irqrestore(&hp->lock, flags); 372 + if (--hp->port.count == 0) { 373 + spin_unlock_irqrestore(&hp->port.lock, flags); 374 374 /* We are done with the tty pointer now. */ 375 375 tty_port_tty_set(&hp->port, NULL); 376 376 ··· 387 387 */ 388 388 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT); 389 389 } else { 390 - if (hp->count < 0) 390 + if (hp->port.count < 0) 391 391 printk(KERN_ERR "hvc_close %X: oops, count is %d\n", 392 - hp->vtermno, hp->count); 393 - spin_unlock_irqrestore(&hp->lock, flags); 392 + hp->vtermno, hp->port.count); 393 + spin_unlock_irqrestore(&hp->port.lock, flags); 394 394 } 395 395 396 396 tty_kref_put(tty); ··· 409 409 /* cancel pending tty resize work */ 410 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 415 * The N_TTY line discipline has problems such that in a close vs 416 416 * open->hangup case this can be called after the final close so prevent 417 417 * that from happening for now. 418 418 */ 419 - if (hp->count <= 0) { 420 - spin_unlock_irqrestore(&hp->lock, flags); 419 + if (hp->port.count <= 0) { 420 + spin_unlock_irqrestore(&hp->port.lock, flags); 421 421 return; 422 422 } 423 423 424 - temp_open_count = hp->count; 425 - hp->count = 0; 426 - hp->n_outbuf = 0; 427 - spin_unlock_irqrestore(&hp->lock, flags); 424 + temp_open_count = hp->port.count; 425 + hp->port.count = 0; 426 + spin_unlock_irqrestore(&hp->port.lock, flags); 428 427 tty_port_tty_set(&hp->port, NULL); 428 + 429 + hp->n_outbuf = 0; 429 430 430 431 if (hp->ops->notifier_hangup) 431 432 hp->ops->notifier_hangup(hp, hp->data); ··· 475 474 if (!hp) 476 475 return -EPIPE; 477 476 478 - if (hp->count <= 0) 477 + /* FIXME what's this (unprotected) check for? */ 478 + if (hp->port.count <= 0) 479 479 return -EIO; 480 480 481 481 spin_lock_irqsave(&hp->lock, flags);
-1
drivers/tty/hvc/hvc_console.h
··· 49 49 struct tty_port port; 50 50 spinlock_t lock; 51 51 int index; 52 - int count; 53 52 int do_wakeup; 54 53 char *outbuf; 55 54 int outbuf_size;