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

tty: make use of tty_get_{char,frame}_size

In the previous patch, we introduced tty_get_char_size() and
tty_get_frame_size() for computing character and frame sizes,
respectively. Here, we make use of them in various tty drivers where
applicable.

The stats look nice: 12 insertions, 169 deletions.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David Lin <dtwlin@gmail.com>
Cc: Johan Hovold <johan@kernel.org>
Cc: Alex Elder <elder@kernel.org>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Andy Gross <agross@kernel.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Oliver Neukum <oneukum@suse.com>
Acked-by: Alex Elder <elder@kernel.org>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
Link: https://lore.kernel.org/r/20210610090247.2593-4-jslaby@suse.cz
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby and committed by
Greg Kroah-Hartman
3ec2ff37 d8f0209b

+16 -206
+1 -15
drivers/staging/greybus/uart.c
··· 494 494 (termios->c_cflag & PARODD ? 1 : 2) + 495 495 (termios->c_cflag & CMSPAR ? 2 : 0) : 0; 496 496 497 - switch (termios->c_cflag & CSIZE) { 498 - case CS5: 499 - newline.data_bits = 5; 500 - break; 501 - case CS6: 502 - newline.data_bits = 6; 503 - break; 504 - case CS7: 505 - newline.data_bits = 7; 506 - break; 507 - case CS8: 508 - default: 509 - newline.data_bits = 8; 510 - break; 511 - } 497 + newline.data_bits = tty_get_char_size(termios->c_cflag); 512 498 513 499 /* FIXME: needs to clear unsupported bits in the termios */ 514 500 gb_tty->clocal = ((termios->c_cflag & CLOCAL) != 0);
+1 -18
drivers/tty/serial/cpm_uart/cpm_uart_core.c
··· 524 524 scval = 0; 525 525 526 526 /* byte size */ 527 - switch (termios->c_cflag & CSIZE) { 528 - case CS5: 529 - bits = 5; 530 - break; 531 - case CS6: 532 - bits = 6; 533 - break; 534 - case CS7: 535 - bits = 7; 536 - break; 537 - case CS8: 538 - bits = 8; 539 - break; 540 - /* Never happens, but GCC is too dumb to figure it out */ 541 - default: 542 - bits = 8; 543 - break; 544 - } 527 + bits = tty_get_char_size(termios->c_cflag); 545 528 sbits = bits - 5; 546 529 547 530 if (termios->c_cflag & CSTOPB) {
+2 -20
drivers/tty/serial/mxs-auart.c
··· 962 962 struct ktermios *old) 963 963 { 964 964 struct mxs_auart_port *s = to_auart_port(u); 965 - u32 bm, ctrl, ctrl2, div; 965 + u32 ctrl, ctrl2, div; 966 966 unsigned int cflag, baud, baud_min, baud_max; 967 967 968 968 cflag = termios->c_cflag; ··· 970 970 ctrl = AUART_LINECTRL_FEN; 971 971 ctrl2 = mxs_read(s, REG_CTRL2); 972 972 973 - /* byte size */ 974 - switch (cflag & CSIZE) { 975 - case CS5: 976 - bm = 5; 977 - break; 978 - case CS6: 979 - bm = 6; 980 - break; 981 - case CS7: 982 - bm = 7; 983 - break; 984 - case CS8: 985 - bm = 8; 986 - break; 987 - default: 988 - return; 989 - } 990 - 991 - ctrl |= AUART_LINECTRL_WLEN(bm); 973 + ctrl |= AUART_LINECTRL_WLEN(tty_get_char_size(cflag)); 992 974 993 975 /* parity */ 994 976 if (cflag & PARENB) {
+1 -15
drivers/tty/serial/qcom_geni_serial.c
··· 1050 1050 } 1051 1051 1052 1052 /* bits per char */ 1053 - switch (termios->c_cflag & CSIZE) { 1054 - case CS5: 1055 - bits_per_char = 5; 1056 - break; 1057 - case CS6: 1058 - bits_per_char = 6; 1059 - break; 1060 - case CS7: 1061 - bits_per_char = 7; 1062 - break; 1063 - case CS8: 1064 - default: 1065 - bits_per_char = 8; 1066 - break; 1067 - } 1053 + bits_per_char = tty_get_char_size(termios->c_cflag); 1068 1054 1069 1055 /* stop bits */ 1070 1056 if (termios->c_cflag & CSTOPB)
+1 -19
drivers/tty/serial/sh-sci.c
··· 2500 2500 uart_update_timeout(port, termios->c_cflag, baud); 2501 2501 2502 2502 /* byte size and parity */ 2503 - switch (termios->c_cflag & CSIZE) { 2504 - case CS5: 2505 - bits = 7; 2506 - break; 2507 - case CS6: 2508 - bits = 8; 2509 - break; 2510 - case CS7: 2511 - bits = 9; 2512 - break; 2513 - default: 2514 - bits = 10; 2515 - break; 2516 - } 2517 - 2518 - if (termios->c_cflag & CSTOPB) 2519 - bits++; 2520 - if (termios->c_cflag & PARENB) 2521 - bits++; 2503 + bits = tty_get_frame_size(termios->c_cflag); 2522 2504 2523 2505 if (sci_getreg(port, SEMR)->size) 2524 2506 serial_port_out(port, SEMR, 0);
+1 -31
drivers/tty/serial/stm32-usart.c
··· 718 718 free_irq(port->irq, port); 719 719 } 720 720 721 - static unsigned int stm32_usart_get_databits(struct ktermios *termios) 722 - { 723 - unsigned int bits; 724 - 725 - tcflag_t cflag = termios->c_cflag; 726 - 727 - switch (cflag & CSIZE) { 728 - /* 729 - * CSIZE settings are not necessarily supported in hardware. 730 - * CSIZE unsupported configurations are handled here to set word length 731 - * to 8 bits word as default configuration and to print debug message. 732 - */ 733 - case CS5: 734 - bits = 5; 735 - break; 736 - case CS6: 737 - bits = 6; 738 - break; 739 - case CS7: 740 - bits = 7; 741 - break; 742 - /* default including CS8 */ 743 - default: 744 - bits = 8; 745 - break; 746 - } 747 - 748 - return bits; 749 - } 750 - 751 721 static void stm32_usart_set_termios(struct uart_port *port, 752 722 struct ktermios *termios, 753 723 struct ktermios *old) ··· 775 805 if (cflag & CSTOPB) 776 806 cr2 |= USART_CR2_STOP_2B; 777 807 778 - bits = stm32_usart_get_databits(termios); 808 + bits = tty_get_char_size(cflag); 779 809 stm32_port->rdr_mask = (BIT(bits) - 1); 780 810 781 811 if (cflag & PARENB) {
+2 -15
drivers/usb/class/cdc-acm.c
··· 1056 1056 newline.bParityType = termios->c_cflag & PARENB ? 1057 1057 (termios->c_cflag & PARODD ? 1 : 2) + 1058 1058 (termios->c_cflag & CMSPAR ? 2 : 0) : 0; 1059 - switch (termios->c_cflag & CSIZE) { 1060 - case CS5: 1061 - newline.bDataBits = 5; 1062 - break; 1063 - case CS6: 1064 - newline.bDataBits = 6; 1065 - break; 1066 - case CS7: 1067 - newline.bDataBits = 7; 1068 - break; 1069 - case CS8: 1070 - default: 1071 - newline.bDataBits = 8; 1072 - break; 1073 - } 1059 + newline.bDataBits = tty_get_char_size(termios->c_cflag); 1060 + 1074 1061 /* FIXME: Needs to clear unsupported bits in the termios */ 1075 1062 acm->clocal = ((termios->c_cflag & CLOCAL) != 0); 1076 1063
+1 -19
drivers/usb/serial/belkin_sa.c
··· 356 356 357 357 /* set the number of data bits */ 358 358 if ((cflag & CSIZE) != (old_cflag & CSIZE)) { 359 - switch (cflag & CSIZE) { 360 - case CS5: 361 - urb_value = BELKIN_SA_DATA_BITS(5); 362 - break; 363 - case CS6: 364 - urb_value = BELKIN_SA_DATA_BITS(6); 365 - break; 366 - case CS7: 367 - urb_value = BELKIN_SA_DATA_BITS(7); 368 - break; 369 - case CS8: 370 - urb_value = BELKIN_SA_DATA_BITS(8); 371 - break; 372 - default: 373 - dev_dbg(&port->dev, 374 - "CSIZE was not CS5-CS8, using default of 8\n"); 375 - urb_value = BELKIN_SA_DATA_BITS(8); 376 - break; 377 - } 359 + urb_value = BELKIN_SA_DATA_BITS(tty_get_char_size(cflag)); 378 360 if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0) 379 361 dev_err(&port->dev, "Set data bits error\n"); 380 362 }
+2 -17
drivers/usb/serial/cypress_m8.c
··· 887 887 } else 888 888 parity_enable = parity_type = 0; 889 889 890 - switch (cflag & CSIZE) { 891 - case CS5: 892 - data_bits = 5; 893 - break; 894 - case CS6: 895 - data_bits = 6; 896 - break; 897 - case CS7: 898 - data_bits = 7; 899 - break; 900 - case CS8: 901 - data_bits = 8; 902 - break; 903 - default: 904 - dev_err(dev, "%s - CSIZE was set, but not CS5-CS8\n", __func__); 905 - data_bits = 8; 906 - } 890 + data_bits = tty_get_char_size(cflag); 891 + 907 892 spin_lock_irqsave(&priv->lock, flags); 908 893 oldlines = priv->line_control; 909 894 if ((cflag & CBAUD) == B0) {
+1 -14
drivers/usb/serial/pl2303.c
··· 789 789 790 790 pl2303_get_line_request(port, buf); 791 791 792 - switch (C_CSIZE(tty)) { 793 - case CS5: 794 - buf[6] = 5; 795 - break; 796 - case CS6: 797 - buf[6] = 6; 798 - break; 799 - case CS7: 800 - buf[6] = 7; 801 - break; 802 - default: 803 - case CS8: 804 - buf[6] = 8; 805 - } 792 + buf[6] = tty_get_char_size(tty->termios.c_cflag); 806 793 dev_dbg(&port->dev, "data bits = %d\n", buf[6]); 807 794 808 795 /* For reference buf[0]:buf[3] baud rate value */
+1 -8
drivers/usb/serial/whiteheat.c
··· 625 625 626 626 port_settings.port = port->port_number + 1; 627 627 628 - /* get the byte size */ 629 - switch (cflag & CSIZE) { 630 - case CS5: port_settings.bits = 5; break; 631 - case CS6: port_settings.bits = 6; break; 632 - case CS7: port_settings.bits = 7; break; 633 - default: 634 - case CS8: port_settings.bits = 8; break; 635 - } 628 + port_settings.bits = tty_get_char_size(cflag); 636 629 dev_dbg(dev, "%s - data bits = %d\n", __func__, port_settings.bits); 637 630 638 631 /* determine the parity */