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

Merge tag 'usb-serial-5.7-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next

Johan writes:

USB-serial updates for 5.7-rc1

Here are the USB-serial updates for 5.7-rc1, including:

- support for a new family of Fintek devices
- fix for an io-edgeport slab-out-of-bounds access
- fixes for a couple of kernel-doc issues

Included are also various clean ups and some new modem device ids.

All but the io-edgeport fix have been in linux-next with no reported
issues.

* tag 'usb-serial-5.7-rc1' of https://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial:
USB: serial: io_edgeport: fix slab-out-of-bounds read in edge_interrupt_callback
USB: serial: option: add Wistron Neweb D19Q1
USB: serial: option: add BroadMobi BM806U
USB: serial: option: add support for ASKEY WWHC050
USB: serial: f81232: add control driver for F81534A
USB: serial: fix tty cleanup-op kernel-doc
USB: serial: clean up carrier-detect helper
USB: serial: f81232: set F81534A serial port with RS232 mode
USB: serial: f81232: add F81534A support
USB: serial: f81232: use devm_kzalloc for port data
USB: serial: f81232: add tx_empty function
USB: serial: f81232: extract LSR handler
USB: serial: digi_acceleport: remove redundant assignment to pointer priv
USB: serial: relax unthrottle memory barrier

+332 -46
+1 -1
drivers/usb/serial/digi_acceleport.c
··· 1472 1472 struct usb_serial_port *port = urb->context; 1473 1473 struct usb_serial *serial = port->serial; 1474 1474 struct tty_struct *tty; 1475 - struct digi_port *priv = usb_get_serial_port_data(port); 1475 + struct digi_port *priv; 1476 1476 unsigned char *buf = urb->transfer_buffer; 1477 1477 int opcode, line, status, val; 1478 1478 unsigned long flags;
+318 -36
drivers/usb/serial/f81232.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 3 * Fintek F81232 USB to serial adaptor driver 4 + * Fintek F81532A/534A/535/536 USB to 2/4/8/12 serial adaptor driver 4 5 * 5 6 * Copyright (C) 2012 Greg Kroah-Hartman (gregkh@linuxfoundation.org) 6 7 * Copyright (C) 2012 Linux Foundation ··· 22 21 #include <linux/usb/serial.h> 23 22 #include <linux/serial_reg.h> 24 23 25 - static const struct usb_device_id id_table[] = { 26 - { USB_DEVICE(0x1934, 0x0706) }, 24 + #define F81232_ID \ 25 + { USB_DEVICE(0x1934, 0x0706) } /* 1 port UART device */ 26 + 27 + #define F81534A_SERIES_ID \ 28 + { USB_DEVICE(0x2c42, 0x1602) }, /* In-Box 2 port UART device */ \ 29 + { USB_DEVICE(0x2c42, 0x1604) }, /* In-Box 4 port UART device */ \ 30 + { USB_DEVICE(0x2c42, 0x1605) }, /* In-Box 8 port UART device */ \ 31 + { USB_DEVICE(0x2c42, 0x1606) }, /* In-Box 12 port UART device */ \ 32 + { USB_DEVICE(0x2c42, 0x1608) }, /* Non-Flash type */ \ 33 + { USB_DEVICE(0x2c42, 0x1632) }, /* 2 port UART device */ \ 34 + { USB_DEVICE(0x2c42, 0x1634) }, /* 4 port UART device */ \ 35 + { USB_DEVICE(0x2c42, 0x1635) }, /* 8 port UART device */ \ 36 + { USB_DEVICE(0x2c42, 0x1636) } /* 12 port UART device */ 37 + 38 + #define F81534A_CTRL_ID \ 39 + { USB_DEVICE(0x2c42, 0x16f8) } /* Global control device */ 40 + 41 + static const struct usb_device_id f81232_id_table[] = { 42 + F81232_ID, 27 43 { } /* Terminating entry */ 28 44 }; 29 - MODULE_DEVICE_TABLE(usb, id_table); 45 + 46 + static const struct usb_device_id f81534a_id_table[] = { 47 + F81534A_SERIES_ID, 48 + { } /* Terminating entry */ 49 + }; 50 + 51 + static const struct usb_device_id f81534a_ctrl_id_table[] = { 52 + F81534A_CTRL_ID, 53 + { } /* Terminating entry */ 54 + }; 55 + 56 + static const struct usb_device_id combined_id_table[] = { 57 + F81232_ID, 58 + F81534A_SERIES_ID, 59 + F81534A_CTRL_ID, 60 + { } /* Terminating entry */ 61 + }; 62 + MODULE_DEVICE_TABLE(usb, combined_id_table); 30 63 31 64 /* Maximum baudrate for F81232 */ 32 65 #define F81232_MAX_BAUDRATE 1500000 ··· 70 35 #define F81232_REGISTER_REQUEST 0xa0 71 36 #define F81232_GET_REGISTER 0xc0 72 37 #define F81232_SET_REGISTER 0x40 38 + #define F81534A_ACCESS_REG_RETRY 2 73 39 74 40 #define SERIAL_BASE_ADDRESS 0x0120 75 41 #define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS) ··· 96 60 #define F81232_CLK_24_MHZ BIT(1) 97 61 #define F81232_CLK_14_77_MHZ (BIT(1) | BIT(0)) 98 62 #define F81232_CLK_MASK GENMASK(1, 0) 63 + 64 + #define F81534A_MODE_REG 0x107 65 + #define F81534A_TRIGGER_MASK GENMASK(3, 2) 66 + #define F81534A_TRIGGER_MULTIPLE_4X BIT(3) 67 + #define F81534A_FIFO_128BYTE (BIT(1) | BIT(0)) 68 + 69 + /* Serial port self GPIO control, 2bytes [control&output data][input data] */ 70 + #define F81534A_GPIO_REG 0x10e 71 + #define F81534A_GPIO_MODE2_DIR BIT(6) /* 1: input, 0: output */ 72 + #define F81534A_GPIO_MODE1_DIR BIT(5) 73 + #define F81534A_GPIO_MODE0_DIR BIT(4) 74 + #define F81534A_GPIO_MODE2_OUTPUT BIT(2) 75 + #define F81534A_GPIO_MODE1_OUTPUT BIT(1) 76 + #define F81534A_GPIO_MODE0_OUTPUT BIT(0) 77 + 78 + #define F81534A_CTRL_CMD_ENABLE_PORT 0x116 99 79 100 80 struct f81232_private { 101 81 struct mutex lock; ··· 374 322 __func__, retval); 375 323 } 376 324 325 + static char f81232_handle_lsr(struct usb_serial_port *port, u8 lsr) 326 + { 327 + struct f81232_private *priv = usb_get_serial_port_data(port); 328 + char tty_flag = TTY_NORMAL; 329 + 330 + if (!(lsr & UART_LSR_BRK_ERROR_BITS)) 331 + return tty_flag; 332 + 333 + if (lsr & UART_LSR_BI) { 334 + tty_flag = TTY_BREAK; 335 + port->icount.brk++; 336 + usb_serial_handle_break(port); 337 + } else if (lsr & UART_LSR_PE) { 338 + tty_flag = TTY_PARITY; 339 + port->icount.parity++; 340 + } else if (lsr & UART_LSR_FE) { 341 + tty_flag = TTY_FRAME; 342 + port->icount.frame++; 343 + } 344 + 345 + if (lsr & UART_LSR_OE) { 346 + port->icount.overrun++; 347 + schedule_work(&priv->lsr_work); 348 + tty_insert_flip_char(&port->port, 0, TTY_OVERRUN); 349 + } 350 + 351 + return tty_flag; 352 + } 353 + 377 354 static void f81232_process_read_urb(struct urb *urb) 378 355 { 379 356 struct usb_serial_port *port = urb->context; 380 - struct f81232_private *priv = usb_get_serial_port_data(port); 381 357 unsigned char *data = urb->transfer_buffer; 382 358 char tty_flag; 383 359 unsigned int i; ··· 421 341 /* bulk-in data: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... */ 422 342 423 343 for (i = 0; i < urb->actual_length; i += 2) { 424 - tty_flag = TTY_NORMAL; 425 344 lsr = data[i]; 426 - 427 - if (lsr & UART_LSR_BRK_ERROR_BITS) { 428 - if (lsr & UART_LSR_BI) { 429 - tty_flag = TTY_BREAK; 430 - port->icount.brk++; 431 - usb_serial_handle_break(port); 432 - } else if (lsr & UART_LSR_PE) { 433 - tty_flag = TTY_PARITY; 434 - port->icount.parity++; 435 - } else if (lsr & UART_LSR_FE) { 436 - tty_flag = TTY_FRAME; 437 - port->icount.frame++; 438 - } 439 - 440 - if (lsr & UART_LSR_OE) { 441 - port->icount.overrun++; 442 - schedule_work(&priv->lsr_work); 443 - tty_insert_flip_char(&port->port, 0, 444 - TTY_OVERRUN); 445 - } 446 - } 345 + tty_flag = f81232_handle_lsr(port, lsr); 447 346 448 347 if (port->port.console && port->sysrq) { 449 348 if (usb_serial_handle_sysrq_char(port, data[i + 1])) ··· 430 371 } 431 372 432 373 tty_insert_flip_char(&port->port, data[i + 1], tty_flag); 374 + } 375 + 376 + tty_flip_buffer_push(&port->port); 377 + } 378 + 379 + static void f81534a_process_read_urb(struct urb *urb) 380 + { 381 + struct usb_serial_port *port = urb->context; 382 + unsigned char *data = urb->transfer_buffer; 383 + char tty_flag; 384 + unsigned int i; 385 + u8 lsr; 386 + u8 len; 387 + 388 + if (urb->actual_length < 3) { 389 + dev_err(&port->dev, "short message received: %d\n", 390 + urb->actual_length); 391 + return; 392 + } 393 + 394 + len = data[0]; 395 + if (len != urb->actual_length) { 396 + dev_err(&port->dev, "malformed message received: %d (%d)\n", 397 + urb->actual_length, len); 398 + return; 399 + } 400 + 401 + /* bulk-in data: [LEN][Data.....][LSR] */ 402 + lsr = data[len - 1]; 403 + tty_flag = f81232_handle_lsr(port, lsr); 404 + 405 + if (port->port.console && port->sysrq) { 406 + for (i = 1; i < len - 1; ++i) { 407 + if (!usb_serial_handle_sysrq_char(port, data[i])) { 408 + tty_insert_flip_char(&port->port, data[i], 409 + tty_flag); 410 + } 411 + } 412 + } else { 413 + tty_insert_flip_string_fixed_flag(&port->port, &data[1], 414 + tty_flag, len - 2); 433 415 } 434 416 435 417 tty_flip_buffer_push(&port->port); ··· 759 659 return 0; 760 660 } 761 661 662 + static int f81534a_open(struct tty_struct *tty, struct usb_serial_port *port) 663 + { 664 + int status; 665 + u8 mask; 666 + u8 val; 667 + 668 + val = F81534A_TRIGGER_MULTIPLE_4X | F81534A_FIFO_128BYTE; 669 + mask = F81534A_TRIGGER_MASK | F81534A_FIFO_128BYTE; 670 + 671 + status = f81232_set_mask_register(port, F81534A_MODE_REG, mask, val); 672 + if (status) { 673 + dev_err(&port->dev, "failed to set MODE_REG: %d\n", status); 674 + return status; 675 + } 676 + 677 + return f81232_open(tty, port); 678 + } 679 + 762 680 static void f81232_close(struct usb_serial_port *port) 763 681 { 764 682 struct f81232_private *port_priv = usb_get_serial_port_data(port); ··· 794 676 f81232_set_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0); 795 677 else 796 678 f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS); 679 + } 680 + 681 + static bool f81232_tx_empty(struct usb_serial_port *port) 682 + { 683 + int status; 684 + u8 tmp; 685 + 686 + status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp); 687 + if (!status) { 688 + if ((tmp & UART_LSR_TEMT) != UART_LSR_TEMT) 689 + return false; 690 + } 691 + 692 + return true; 797 693 } 798 694 799 695 static int f81232_carrier_raised(struct usb_serial_port *port) ··· 860 728 dev_warn(&port->dev, "read LSR failed: %d\n", status); 861 729 } 862 730 731 + static int f81534a_ctrl_set_register(struct usb_interface *intf, u16 reg, 732 + u16 size, void *val) 733 + { 734 + struct usb_device *dev = interface_to_usbdev(intf); 735 + int retry = F81534A_ACCESS_REG_RETRY; 736 + int status; 737 + u8 *tmp; 738 + 739 + tmp = kmemdup(val, size, GFP_KERNEL); 740 + if (!tmp) 741 + return -ENOMEM; 742 + 743 + while (retry--) { 744 + status = usb_control_msg(dev, 745 + usb_sndctrlpipe(dev, 0), 746 + F81232_REGISTER_REQUEST, 747 + F81232_SET_REGISTER, 748 + reg, 749 + 0, 750 + tmp, 751 + size, 752 + USB_CTRL_SET_TIMEOUT); 753 + if (status < 0) { 754 + status = usb_translate_errors(status); 755 + if (status == -EIO) 756 + continue; 757 + } else if (status != size) { 758 + /* Retry on short transfers */ 759 + status = -EIO; 760 + continue; 761 + } else { 762 + status = 0; 763 + } 764 + 765 + break; 766 + } 767 + 768 + if (status) { 769 + dev_err(&intf->dev, "failed to set register 0x%x: %d\n", 770 + reg, status); 771 + } 772 + 773 + kfree(tmp); 774 + return status; 775 + } 776 + 777 + static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf, bool en) 778 + { 779 + unsigned char enable[2] = {0}; 780 + int status; 781 + 782 + /* 783 + * Enable all available serial ports, define as following: 784 + * bit 15 : Reset behavior (when HUB got soft reset) 785 + * 0: maintain all serial port enabled state. 786 + * 1: disable all serial port. 787 + * bit 0~11 : Serial port enable bit. 788 + */ 789 + if (en) { 790 + enable[0] = 0xff; 791 + enable[1] = 0x8f; 792 + } 793 + 794 + status = f81534a_ctrl_set_register(intf, F81534A_CTRL_CMD_ENABLE_PORT, 795 + sizeof(enable), enable); 796 + if (status) 797 + dev_err(&intf->dev, "failed to enable ports: %d\n", status); 798 + 799 + return status; 800 + } 801 + 802 + static int f81534a_ctrl_probe(struct usb_interface *intf, 803 + const struct usb_device_id *id) 804 + { 805 + return f81534a_ctrl_enable_all_ports(intf, true); 806 + } 807 + 808 + static void f81534a_ctrl_disconnect(struct usb_interface *intf) 809 + { 810 + f81534a_ctrl_enable_all_ports(intf, false); 811 + } 812 + 813 + static int f81534a_ctrl_resume(struct usb_interface *intf) 814 + { 815 + return f81534a_ctrl_enable_all_ports(intf, true); 816 + } 817 + 863 818 static int f81232_port_probe(struct usb_serial_port *port) 864 819 { 865 820 struct f81232_private *priv; 866 821 867 - priv = kzalloc(sizeof(*priv), GFP_KERNEL); 822 + priv = devm_kzalloc(&port->dev, sizeof(*priv), GFP_KERNEL); 868 823 if (!priv) 869 824 return -ENOMEM; 870 825 ··· 967 748 return 0; 968 749 } 969 750 970 - static int f81232_port_remove(struct usb_serial_port *port) 751 + static int f81534a_port_probe(struct usb_serial_port *port) 971 752 { 972 - struct f81232_private *priv; 753 + int status; 973 754 974 - priv = usb_get_serial_port_data(port); 975 - kfree(priv); 755 + /* tri-state with pull-high, default RS232 Mode */ 756 + status = f81232_set_register(port, F81534A_GPIO_REG, 757 + F81534A_GPIO_MODE2_DIR); 758 + if (status) 759 + return status; 976 760 977 - return 0; 761 + return f81232_port_probe(port); 978 762 } 979 763 980 764 static int f81232_suspend(struct usb_serial *serial, pm_message_t message) ··· 1021 799 .owner = THIS_MODULE, 1022 800 .name = "f81232", 1023 801 }, 1024 - .id_table = id_table, 802 + .id_table = f81232_id_table, 1025 803 .num_ports = 1, 1026 804 .bulk_in_size = 256, 1027 805 .bulk_out_size = 256, ··· 1035 813 .tiocmget = f81232_tiocmget, 1036 814 .tiocmset = f81232_tiocmset, 1037 815 .tiocmiwait = usb_serial_generic_tiocmiwait, 816 + .tx_empty = f81232_tx_empty, 1038 817 .process_read_urb = f81232_process_read_urb, 1039 818 .read_int_callback = f81232_read_int_callback, 1040 819 .port_probe = f81232_port_probe, 1041 - .port_remove = f81232_port_remove, 820 + .suspend = f81232_suspend, 821 + .resume = f81232_resume, 822 + }; 823 + 824 + static struct usb_serial_driver f81534a_device = { 825 + .driver = { 826 + .owner = THIS_MODULE, 827 + .name = "f81534a", 828 + }, 829 + .id_table = f81534a_id_table, 830 + .num_ports = 1, 831 + .open = f81534a_open, 832 + .close = f81232_close, 833 + .dtr_rts = f81232_dtr_rts, 834 + .carrier_raised = f81232_carrier_raised, 835 + .get_serial = f81232_get_serial_info, 836 + .break_ctl = f81232_break_ctl, 837 + .set_termios = f81232_set_termios, 838 + .tiocmget = f81232_tiocmget, 839 + .tiocmset = f81232_tiocmset, 840 + .tiocmiwait = usb_serial_generic_tiocmiwait, 841 + .tx_empty = f81232_tx_empty, 842 + .process_read_urb = f81534a_process_read_urb, 843 + .read_int_callback = f81232_read_int_callback, 844 + .port_probe = f81534a_port_probe, 1042 845 .suspend = f81232_suspend, 1043 846 .resume = f81232_resume, 1044 847 }; 1045 848 1046 849 static struct usb_serial_driver * const serial_drivers[] = { 1047 850 &f81232_device, 851 + &f81534a_device, 1048 852 NULL, 1049 853 }; 1050 854 1051 - module_usb_serial_driver(serial_drivers, id_table); 855 + static struct usb_driver f81534a_ctrl_driver = { 856 + .name = "f81534a_ctrl", 857 + .id_table = f81534a_ctrl_id_table, 858 + .probe = f81534a_ctrl_probe, 859 + .disconnect = f81534a_ctrl_disconnect, 860 + .resume = f81534a_ctrl_resume, 861 + }; 1052 862 1053 - MODULE_DESCRIPTION("Fintek F81232 USB to serial adaptor driver"); 863 + static int __init f81232_init(void) 864 + { 865 + int status; 866 + 867 + status = usb_register_driver(&f81534a_ctrl_driver, THIS_MODULE, 868 + KBUILD_MODNAME); 869 + if (status) 870 + return status; 871 + 872 + status = usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME, 873 + combined_id_table); 874 + if (status) { 875 + usb_deregister(&f81534a_ctrl_driver); 876 + return status; 877 + } 878 + 879 + return 0; 880 + } 881 + 882 + static void __exit f81232_exit(void) 883 + { 884 + usb_serial_deregister_drivers(serial_drivers); 885 + usb_deregister(&f81534a_ctrl_driver); 886 + } 887 + 888 + module_init(f81232_init); 889 + module_exit(f81232_exit); 890 + 891 + MODULE_DESCRIPTION("Fintek F81232/532A/534A/535/536 USB to serial driver"); 1054 892 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>"); 1055 893 MODULE_AUTHOR("Peter Hong <peter_hong@fintek.com.tw>"); 1056 894 MODULE_LICENSE("GPL v2");
+5 -7
drivers/usb/serial/generic.c
··· 417 417 /* 418 418 * Make sure URB is marked as free before checking the throttled flag 419 419 * to avoid racing with unthrottle() on another CPU. Matches the 420 - * smp_mb() in unthrottle(). 420 + * smp_mb__after_atomic() in unthrottle(). 421 421 */ 422 422 smp_mb__after_atomic(); 423 423 ··· 489 489 * Matches the smp_mb__after_atomic() in 490 490 * usb_serial_generic_read_bulk_callback(). 491 491 */ 492 - smp_mb(); 492 + smp_mb__after_atomic(); 493 493 494 494 usb_serial_generic_submit_read_urbs(port, GFP_KERNEL); 495 495 } ··· 609 609 * @tty: tty for the port 610 610 * @status: new carrier detect status, nonzero if active 611 611 */ 612 - void usb_serial_handle_dcd_change(struct usb_serial_port *usb_port, 612 + void usb_serial_handle_dcd_change(struct usb_serial_port *port, 613 613 struct tty_struct *tty, unsigned int status) 614 614 { 615 - struct tty_port *port = &usb_port->port; 616 - 617 - dev_dbg(&usb_port->dev, "%s - status %d\n", __func__, status); 615 + dev_dbg(&port->dev, "%s - status %d\n", __func__, status); 618 616 619 617 if (tty) { 620 618 struct tty_ldisc *ld = tty_ldisc_ref(tty); ··· 625 627 } 626 628 627 629 if (status) 628 - wake_up_interruptible(&port->open_wait); 630 + wake_up_interruptible(&port->port.open_wait); 629 631 else if (tty && !C_CLOCAL(tty)) 630 632 tty_hangup(tty); 631 633 }
+1 -1
drivers/usb/serial/io_edgeport.c
··· 710 710 /* grab the txcredits for the ports if available */ 711 711 position = 2; 712 712 portNumber = 0; 713 - while ((position < length) && 713 + while ((position < length - 1) && 714 714 (portNumber < edge_serial->serial->num_ports)) { 715 715 txCredits = data[position] | (data[position+1] << 8); 716 716 if (txCredits) {
+6
drivers/usb/serial/option.c
··· 1992 1992 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e01, 0xff, 0xff, 0xff) }, /* D-Link DWM-152/C1 */ 1993 1993 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x3e02, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/C1 */ 1994 1994 { USB_DEVICE_AND_INTERFACE_INFO(0x07d1, 0x7e11, 0xff, 0xff, 0xff) }, /* D-Link DWM-156/A3 */ 1995 + { USB_DEVICE_INTERFACE_CLASS(0x1435, 0xd191, 0xff), /* Wistron Neweb D19Q1 */ 1996 + .driver_info = RSVD(1) | RSVD(4) }, 1997 + { USB_DEVICE_INTERFACE_CLASS(0x1690, 0x7588, 0xff), /* ASKEY WWHC050 */ 1998 + .driver_info = RSVD(1) | RSVD(4) }, 1995 1999 { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x2031, 0xff), /* Olicard 600 */ 2000 + .driver_info = RSVD(4) }, 2001 + { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x2033, 0xff), /* BroadMobi BM806U */ 1996 2002 .driver_info = RSVD(4) }, 1997 2003 { USB_DEVICE_INTERFACE_CLASS(0x2020, 0x2060, 0xff), /* BroadMobi BM818 */ 1998 2004 .driver_info = RSVD(4) },
+1 -1
drivers/usb/serial/usb-serial.c
··· 288 288 289 289 /** 290 290 * serial_cleanup - free resources post close/hangup 291 - * @port: port to free up 291 + * @tty: tty to clean up 292 292 * 293 293 * Do the resource freeing and refcount dropping for the port. 294 294 * Avoid freeing the console.