Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty-2.6:
tty_port,usb-console: Fix usb serial console open/close regression
tty: cpm_uart: use resource_size()
tty_buffer: Fix distinct type warning
hvc_console: Fix race between hvc_close and hvc_remove
uartlite: Fix build on sparc.
tty: Take a 256 byte padding into account when buffering below sub-page units
Revert "tty: Add a new VT mode which is like VT_PROCESS but doesn't require a VT_RELDISP ioctl call"

+53 -41
+21 -10
drivers/char/hvc_console.c
··· 312 312 spin_lock_irqsave(&hp->lock, flags); 313 313 /* Check and then increment for fast path open. */ 314 314 if (hp->count++ > 0) { 315 + tty_kref_get(tty); 315 316 spin_unlock_irqrestore(&hp->lock, flags); 316 317 hvc_kick(); 317 318 return 0; ··· 320 319 321 320 tty->driver_data = hp; 322 321 323 - hp->tty = tty; 322 + hp->tty = tty_kref_get(tty); 324 323 325 324 spin_unlock_irqrestore(&hp->lock, flags); 326 325 ··· 337 336 spin_lock_irqsave(&hp->lock, flags); 338 337 hp->tty = NULL; 339 338 spin_unlock_irqrestore(&hp->lock, flags); 339 + tty_kref_put(tty); 340 340 tty->driver_data = NULL; 341 341 kref_put(&hp->kref, destroy_hvc_struct); 342 342 printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); ··· 365 363 return; 366 364 367 365 hp = tty->driver_data; 366 + 368 367 spin_lock_irqsave(&hp->lock, flags); 368 + tty_kref_get(tty); 369 369 370 370 if (--hp->count == 0) { 371 371 /* We are done with the tty pointer now. */ 372 372 hp->tty = NULL; 373 373 spin_unlock_irqrestore(&hp->lock, flags); 374 + 375 + /* Put the ref obtained in hvc_open() */ 376 + tty_kref_put(tty); 374 377 375 378 if (hp->ops->notifier_del) 376 379 hp->ops->notifier_del(hp, hp->data); ··· 396 389 spin_unlock_irqrestore(&hp->lock, flags); 397 390 } 398 391 392 + tty_kref_put(tty); 399 393 kref_put(&hp->kref, destroy_hvc_struct); 400 394 } 401 395 ··· 432 424 spin_unlock_irqrestore(&hp->lock, flags); 433 425 434 426 if (hp->ops->notifier_hangup) 435 - hp->ops->notifier_hangup(hp, hp->data); 427 + hp->ops->notifier_hangup(hp, hp->data); 436 428 437 429 while(temp_open_count) { 438 430 --temp_open_count; 431 + tty_kref_put(tty); 439 432 kref_put(&hp->kref, destroy_hvc_struct); 440 433 } 441 434 } ··· 601 592 } 602 593 603 594 /* No tty attached, just skip */ 604 - tty = hp->tty; 595 + tty = tty_kref_get(hp->tty); 605 596 if (tty == NULL) 606 597 goto bail; 607 598 ··· 681 672 682 673 tty_flip_buffer_push(tty); 683 674 } 675 + if (tty) 676 + tty_kref_put(tty); 684 677 685 678 return poll_mask; 686 679 } ··· 818 807 struct tty_struct *tty; 819 808 820 809 spin_lock_irqsave(&hp->lock, flags); 821 - tty = hp->tty; 810 + tty = tty_kref_get(hp->tty); 822 811 823 812 if (hp->index < MAX_NR_HVC_CONSOLES) 824 813 vtermnos[hp->index] = -1; ··· 830 819 /* 831 820 * We 'put' the instance that was grabbed when the kref instance 832 821 * was initialized using kref_init(). Let the last holder of this 833 - * kref cause it to be removed, which will probably be the tty_hangup 822 + * kref cause it to be removed, which will probably be the tty_vhangup 834 823 * below. 835 824 */ 836 825 kref_put(&hp->kref, destroy_hvc_struct); 837 826 838 827 /* 839 - * This function call will auto chain call hvc_hangup. The tty should 840 - * always be valid at this time unless a simultaneous tty close already 841 - * cleaned up the hvc_struct. 828 + * This function call will auto chain call hvc_hangup. 842 829 */ 843 - if (tty) 844 - tty_hangup(tty); 830 + if (tty) { 831 + tty_vhangup(tty); 832 + tty_kref_put(tty); 833 + } 845 834 return 0; 846 835 } 847 836 EXPORT_SYMBOL_GPL(hvc_remove);
+2 -2
drivers/char/tty_buffer.c
··· 248 248 { 249 249 int copied = 0; 250 250 do { 251 - int goal = min(size - copied, TTY_BUFFER_PAGE); 251 + int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 252 252 int space = tty_buffer_request_room(tty, goal); 253 253 struct tty_buffer *tb = tty->buf.tail; 254 254 /* If there is no space then tb may be NULL */ ··· 285 285 { 286 286 int copied = 0; 287 287 do { 288 - int goal = min(size - copied, TTY_BUFFER_PAGE); 288 + int goal = min_t(size_t, size - copied, TTY_BUFFER_PAGE); 289 289 int space = tty_buffer_request_room(tty, goal); 290 290 struct tty_buffer *tb = tty->buf.tail; 291 291 /* If there is no space then tb may be NULL */
+1 -1
drivers/char/tty_port.c
··· 119 119 static void tty_port_shutdown(struct tty_port *port) 120 120 { 121 121 mutex_lock(&port->mutex); 122 - if (port->ops->shutdown && 122 + if (port->ops->shutdown && !port->console && 123 123 test_and_clear_bit(ASYNCB_INITIALIZED, &port->flags)) 124 124 port->ops->shutdown(port); 125 125 mutex_unlock(&port->mutex);
+19 -20
drivers/char/vt_ioctl.c
··· 888 888 ret = -EFAULT; 889 889 goto out; 890 890 } 891 - if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS && tmp.mode != VT_PROCESS_AUTO) { 891 + if (tmp.mode != VT_AUTO && tmp.mode != VT_PROCESS) { 892 892 ret = -EINVAL; 893 893 goto out; 894 894 } ··· 1622 1622 * telling it that it has acquired. Also check if it has died and 1623 1623 * clean up (similar to logic employed in change_console()) 1624 1624 */ 1625 - if (vc->vt_mode.mode == VT_PROCESS || vc->vt_mode.mode == VT_PROCESS_AUTO) { 1625 + if (vc->vt_mode.mode == VT_PROCESS) { 1626 1626 /* 1627 1627 * Send the signal as privileged - kill_pid() will 1628 1628 * tell us if the process has gone or something else ··· 1682 1682 * vt to auto control. 1683 1683 */ 1684 1684 vc = vc_cons[fg_console].d; 1685 - if (vc->vt_mode.mode == VT_PROCESS || vc->vt_mode.mode == VT_PROCESS_AUTO) { 1685 + if (vc->vt_mode.mode == VT_PROCESS) { 1686 1686 /* 1687 1687 * Send the signal as privileged - kill_pid() will 1688 1688 * tell us if the process has gone or something else ··· 1693 1693 */ 1694 1694 vc->vt_newvt = new_vc->vc_num; 1695 1695 if (kill_pid(vc->vt_pid, vc->vt_mode.relsig, 1) == 0) { 1696 - if(vc->vt_mode.mode == VT_PROCESS) 1697 - /* 1698 - * It worked. Mark the vt to switch to and 1699 - * return. The process needs to send us a 1700 - * VT_RELDISP ioctl to complete the switch. 1701 - */ 1702 - return; 1703 - } else { 1704 1696 /* 1705 - * The controlling process has died, so we revert back to 1706 - * normal operation. In this case, we'll also change back 1707 - * to KD_TEXT mode. I'm not sure if this is strictly correct 1708 - * but it saves the agony when the X server dies and the screen 1709 - * remains blanked due to KD_GRAPHICS! It would be nice to do 1710 - * this outside of VT_PROCESS but there is no single process 1711 - * to account for and tracking tty count may be undesirable. 1697 + * It worked. Mark the vt to switch to and 1698 + * return. The process needs to send us a 1699 + * VT_RELDISP ioctl to complete the switch. 1712 1700 */ 1713 - reset_vc(vc); 1701 + return; 1714 1702 } 1715 1703 1716 1704 /* 1717 - * Fall through to normal (VT_AUTO and VT_PROCESS_AUTO) handling of the switch... 1705 + * The controlling process has died, so we revert back to 1706 + * normal operation. In this case, we'll also change back 1707 + * to KD_TEXT mode. I'm not sure if this is strictly correct 1708 + * but it saves the agony when the X server dies and the screen 1709 + * remains blanked due to KD_GRAPHICS! It would be nice to do 1710 + * this outside of VT_PROCESS but there is no single process 1711 + * to account for and tracking tty count may be undesirable. 1712 + */ 1713 + reset_vc(vc); 1714 + 1715 + /* 1716 + * Fall through to normal (VT_AUTO) handling of the switch... 1718 1717 */ 1719 1718 } 1720 1719
+2 -2
drivers/serial/cpm_uart/cpm_uart_cpm2.c
··· 61 61 void __iomem *pram; 62 62 unsigned long offset; 63 63 struct resource res; 64 - unsigned long len; 64 + resource_size_t len; 65 65 66 66 /* Don't remap parameter RAM if it has already been initialized 67 67 * during console setup. ··· 74 74 if (of_address_to_resource(np, 1, &res)) 75 75 return NULL; 76 76 77 - len = 1 + res.end - res.start; 77 + len = resource_size(&res); 78 78 pram = ioremap(res.start, len); 79 79 if (!pram) 80 80 return NULL;
+1
drivers/usb/serial/console.c
··· 181 181 /* The console is special in terms of closing the device so 182 182 * indicate this port is now acting as a system console. */ 183 183 port->console = 1; 184 + port->port.console = 1; 184 185 185 186 mutex_unlock(&serial->disc_mutex); 186 187 return retval;
+6 -4
include/linux/tty.h
··· 70 70 71 71 /* 72 72 * We default to dicing tty buffer allocations to this many characters 73 - * in order to avoid multiple page allocations. We assume tty_buffer itself 74 - * is under 256 bytes. See tty_buffer_find for the allocation logic this 75 - * must match 73 + * in order to avoid multiple page allocations. We know the size of 74 + * tty_buffer itself but it must also be taken into account that the 75 + * the buffer is 256 byte aligned. See tty_buffer_find for the allocation 76 + * logic this must match 76 77 */ 77 78 78 - #define TTY_BUFFER_PAGE ((PAGE_SIZE - 256) / 2) 79 + #define TTY_BUFFER_PAGE (((PAGE_SIZE - sizeof(struct tty_buffer)) / 2) & ~0xFF) 79 80 80 81 81 82 struct tty_bufhead { ··· 224 223 wait_queue_head_t close_wait; /* Close waiters */ 225 224 wait_queue_head_t delta_msr_wait; /* Modem status change */ 226 225 unsigned long flags; /* TTY flags ASY_*/ 226 + unsigned char console:1; /* port is a console */ 227 227 struct mutex mutex; /* Locking */ 228 228 struct mutex buf_mutex; /* Buffer alloc lock */ 229 229 unsigned char *xmit_buf; /* Optional buffer */
+1 -2
include/linux/vt.h
··· 27 27 #define VT_SETMODE 0x5602 /* set mode of active vt */ 28 28 #define VT_AUTO 0x00 /* auto vt switching */ 29 29 #define VT_PROCESS 0x01 /* process controls switching */ 30 - #define VT_PROCESS_AUTO 0x02 /* process is notified of switching */ 30 + #define VT_ACKACQ 0x02 /* acknowledge switch */ 31 31 32 32 struct vt_stat { 33 33 unsigned short v_active; /* active vt */ ··· 38 38 #define VT_SENDSIG 0x5604 /* signal to send to bitmask of vts */ 39 39 40 40 #define VT_RELDISP 0x5605 /* release display */ 41 - #define VT_ACKACQ 0x02 /* acknowledge switch */ 42 41 43 42 #define VT_ACTIVATE 0x5606 /* make vt active */ 44 43 #define VT_WAITACTIVE 0x5607 /* wait for vt active */