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