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

tty: Convert ->dtr_rts() to take bool argument

Convert the raise/on parameter in ->dtr_rts() to bool through the
callchain. The parameter is used like bool. In USB serial, there
remains a few implicit bool -> larger type conversions because some
devices use u8 in their control messages.

In moxa_tiocmget(), dtr variable was reused for line status which
requires int so use a separate variable for status.

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
Acked-by: Ulf Hansson <ulf.hansson@linaro.org> # For MMC
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20230117090358.4796-8-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ilpo Järvinen and committed by
Greg Kroah-Hartman
5d420399 b300fb26

+52 -50
+2 -2
drivers/mmc/core/sdio_uart.c
··· 548 548 * adjusted during an open, close and hangup. 549 549 */ 550 550 551 - static void uart_dtr_rts(struct tty_port *tport, int onoff) 551 + static void uart_dtr_rts(struct tty_port *tport, bool onoff) 552 552 { 553 553 struct sdio_uart_port *port = 554 554 container_of(tport, struct sdio_uart_port, port); 555 555 int ret = sdio_uart_claim_func(port); 556 556 if (ret) 557 557 return; 558 - if (onoff == 0) 558 + if (!onoff) 559 559 sdio_uart_clear_mctrl(port, TIOCM_DTR | TIOCM_RTS); 560 560 else 561 561 sdio_uart_set_mctrl(port, TIOCM_DTR | TIOCM_RTS);
+1 -1
drivers/staging/greybus/uart.c
··· 701 701 return -ENOIOCTLCMD; 702 702 } 703 703 704 - static void gb_tty_dtr_rts(struct tty_port *port, int on) 704 + static void gb_tty_dtr_rts(struct tty_port *port, bool on) 705 705 { 706 706 struct gb_tty *gb_tty; 707 707 u8 newctrl;
+1 -1
drivers/tty/amiserial.c
··· 1459 1459 return !(ciab.pra & SER_DCD); 1460 1460 } 1461 1461 1462 - static void amiga_dtr_rts(struct tty_port *port, int raise) 1462 + static void amiga_dtr_rts(struct tty_port *port, bool raise) 1463 1463 { 1464 1464 struct serial_state *info = container_of(port, struct serial_state, 1465 1465 tport);
+2 -2
drivers/tty/hvc/hvc_console.c
··· 376 376 /* We are ready... raise DTR/RTS */ 377 377 if (C_BAUD(tty)) 378 378 if (hp->ops->dtr_rts) 379 - hp->ops->dtr_rts(hp, 1); 379 + hp->ops->dtr_rts(hp, true); 380 380 tty_port_set_initialized(&hp->port, true); 381 381 } 382 382 ··· 406 406 407 407 if (C_HUPCL(tty)) 408 408 if (hp->ops->dtr_rts) 409 - hp->ops->dtr_rts(hp, 0); 409 + hp->ops->dtr_rts(hp, false); 410 410 411 411 if (hp->ops->notifier_del) 412 412 hp->ops->notifier_del(hp, hp->data);
+1 -1
drivers/tty/hvc/hvc_console.h
··· 66 66 int (*tiocmset)(struct hvc_struct *hp, unsigned int set, unsigned int clear); 67 67 68 68 /* Callbacks to handle tty ports */ 69 - void (*dtr_rts)(struct hvc_struct *hp, int raise); 69 + void (*dtr_rts)(struct hvc_struct *hp, bool raise); 70 70 }; 71 71 72 72 /* Register a vterm and a slot index for use as a console (console_init) */
+2 -2
drivers/tty/hvc/hvc_iucv.c
··· 658 658 /** 659 659 * hvc_iucv_dtr_rts() - HVC notifier for handling DTR/RTS 660 660 * @hp: Pointer the HVC device (struct hvc_struct) 661 - * @raise: Non-zero to raise or zero to lower DTR/RTS lines 661 + * @raise: True to raise or false to lower DTR/RTS lines 662 662 * 663 663 * This routine notifies the HVC back-end to raise or lower DTR/RTS 664 664 * lines. Raising DTR/RTS is ignored. Lowering DTR/RTS indicates to 665 665 * drop the IUCV connection (similar to hang up the modem). 666 666 */ 667 - static void hvc_iucv_dtr_rts(struct hvc_struct *hp, int raise) 667 + static void hvc_iucv_dtr_rts(struct hvc_struct *hp, bool raise) 668 668 { 669 669 struct hvc_iucv_private *priv; 670 670 struct iucv_path *path;
+28 -26
drivers/tty/moxa.c
··· 502 502 static void moxa_set_tty_param(struct tty_struct *, const struct ktermios *); 503 503 static void moxa_shutdown(struct tty_port *); 504 504 static bool moxa_carrier_raised(struct tty_port *); 505 - static void moxa_dtr_rts(struct tty_port *, int); 505 + static void moxa_dtr_rts(struct tty_port *, bool); 506 506 /* 507 507 * moxa board interface functions: 508 508 */ 509 509 static void MoxaPortEnable(struct moxa_port *); 510 510 static void MoxaPortDisable(struct moxa_port *); 511 511 static int MoxaPortSetTermio(struct moxa_port *, struct ktermios *, speed_t); 512 - static int MoxaPortGetLineOut(struct moxa_port *, int *, int *); 513 - static void MoxaPortLineCtrl(struct moxa_port *, int, int); 512 + static int MoxaPortGetLineOut(struct moxa_port *, bool *, bool *); 513 + static void MoxaPortLineCtrl(struct moxa_port *, bool, bool); 514 514 static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); 515 515 static int MoxaPortLineStatus(struct moxa_port *); 516 516 static void MoxaPortFlushData(struct moxa_port *, int); ··· 1443 1443 return dcd; 1444 1444 } 1445 1445 1446 - static void moxa_dtr_rts(struct tty_port *port, int onoff) 1446 + static void moxa_dtr_rts(struct tty_port *port, bool onoff) 1447 1447 { 1448 1448 struct moxa_port *ch = container_of(port, struct moxa_port, port); 1449 1449 MoxaPortLineCtrl(ch, onoff, onoff); ··· 1481 1481 if (!tty_port_initialized(&ch->port)) { 1482 1482 ch->statusflags = 0; 1483 1483 moxa_set_tty_param(tty, &tty->termios); 1484 - MoxaPortLineCtrl(ch, 1, 1); 1484 + MoxaPortLineCtrl(ch, true, true); 1485 1485 MoxaPortEnable(ch); 1486 1486 MoxaSetFifo(ch, ch->type == PORT_16550A); 1487 1487 tty_port_set_initialized(&ch->port, true); ··· 1557 1557 static int moxa_tiocmget(struct tty_struct *tty) 1558 1558 { 1559 1559 struct moxa_port *ch = tty->driver_data; 1560 - int flag = 0, dtr, rts; 1560 + bool dtr, rts; 1561 + int flag = 0; 1562 + int status; 1561 1563 1562 1564 MoxaPortGetLineOut(ch, &dtr, &rts); 1563 1565 if (dtr) 1564 1566 flag |= TIOCM_DTR; 1565 1567 if (rts) 1566 1568 flag |= TIOCM_RTS; 1567 - dtr = MoxaPortLineStatus(ch); 1568 - if (dtr & 1) 1569 + status = MoxaPortLineStatus(ch); 1570 + if (status & 1) 1569 1571 flag |= TIOCM_CTS; 1570 - if (dtr & 2) 1572 + if (status & 2) 1571 1573 flag |= TIOCM_DSR; 1572 - if (dtr & 4) 1574 + if (status & 4) 1573 1575 flag |= TIOCM_CD; 1574 1576 return flag; 1575 1577 } ··· 1580 1578 unsigned int set, unsigned int clear) 1581 1579 { 1582 1580 struct moxa_port *ch; 1583 - int dtr, rts; 1581 + bool dtr, rts; 1584 1582 1585 1583 mutex_lock(&moxa_openlock); 1586 1584 ch = tty->driver_data; ··· 1591 1589 1592 1590 MoxaPortGetLineOut(ch, &dtr, &rts); 1593 1591 if (set & TIOCM_RTS) 1594 - rts = 1; 1592 + rts = true; 1595 1593 if (set & TIOCM_DTR) 1596 - dtr = 1; 1594 + dtr = true; 1597 1595 if (clear & TIOCM_RTS) 1598 - rts = 0; 1596 + rts = false; 1599 1597 if (clear & TIOCM_DTR) 1600 - dtr = 0; 1598 + dtr = false; 1601 1599 MoxaPortLineCtrl(ch, dtr, rts); 1602 1600 mutex_unlock(&moxa_openlock); 1603 1601 return 0; ··· 1879 1877 * 1880 1878 * Function 13: Get the DTR/RTS state of this port. 1881 1879 * Syntax: 1882 - * int MoxaPortGetLineOut(int port, int *dtrState, int *rtsState); 1880 + * int MoxaPortGetLineOut(int port, bool *dtrState, bool *rtsState); 1883 1881 * int port : port number (0 - 127) 1884 - * int * dtrState : pointer to INT to receive the current DTR 1882 + * bool * dtrState : pointer to bool to receive the current DTR 1885 1883 * state. (if NULL, this function will not 1886 1884 * write to this address) 1887 - * int * rtsState : pointer to INT to receive the current RTS 1885 + * bool * rtsState : pointer to bool to receive the current RTS 1888 1886 * state. (if NULL, this function will not 1889 1887 * write to this address) 1890 1888 * ··· 1894 1892 * 1895 1893 * Function 14: Setting the DTR/RTS output state of this port. 1896 1894 * Syntax: 1897 - * void MoxaPortLineCtrl(int port, int dtrState, int rtsState); 1895 + * void MoxaPortLineCtrl(int port, bool dtrState, bool rtsState); 1898 1896 * int port : port number (0 - 127) 1899 - * int dtrState : DTR output state (0: off, 1: on) 1900 - * int rtsState : RTS output state (0: off, 1: on) 1897 + * bool dtrState : DTR output state 1898 + * bool rtsState : RTS output state 1901 1899 * 1902 1900 * 1903 1901 * Function 15: Setting the flow control of this port. ··· 2105 2103 return baud; 2106 2104 } 2107 2105 2108 - static int MoxaPortGetLineOut(struct moxa_port *port, int *dtrState, 2109 - int *rtsState) 2106 + static int MoxaPortGetLineOut(struct moxa_port *port, bool *dtrState, 2107 + bool *rtsState) 2110 2108 { 2111 2109 if (dtrState) 2112 - *dtrState = !!(port->lineCtrl & DTR_ON); 2110 + *dtrState = port->lineCtrl & DTR_ON; 2113 2111 if (rtsState) 2114 - *rtsState = !!(port->lineCtrl & RTS_ON); 2112 + *rtsState = port->lineCtrl & RTS_ON; 2115 2113 2116 2114 return 0; 2117 2115 } 2118 2116 2119 - static void MoxaPortLineCtrl(struct moxa_port *port, int dtr, int rts) 2117 + static void MoxaPortLineCtrl(struct moxa_port *port, bool dtr, bool rts) 2120 2118 { 2121 2119 u8 mode = 0; 2122 2120
+1 -1
drivers/tty/mxser.c
··· 465 465 return inb(mp->ioaddr + UART_MSR) & UART_MSR_DCD; 466 466 } 467 467 468 - static void mxser_dtr_rts(struct tty_port *port, int on) 468 + static void mxser_dtr_rts(struct tty_port *port, bool on) 469 469 { 470 470 struct mxser_port *mp = container_of(port, struct mxser_port, port); 471 471 unsigned long flags;
+1 -1
drivers/tty/n_gsm.c
··· 3792 3792 return dlci->modem_rx & TIOCM_CD; 3793 3793 } 3794 3794 3795 - static void gsm_dtr_rts(struct tty_port *port, int onoff) 3795 + static void gsm_dtr_rts(struct tty_port *port, bool onoff) 3796 3796 { 3797 3797 struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port); 3798 3798 unsigned int modem_tx = dlci->modem_tx;
+4 -4
drivers/tty/serial/serial_core.c
··· 169 169 #define uart_set_mctrl(port, set) uart_update_mctrl(port, set, 0) 170 170 #define uart_clear_mctrl(port, clear) uart_update_mctrl(port, 0, clear) 171 171 172 - static void uart_port_dtr_rts(struct uart_port *uport, int raise) 172 + static void uart_port_dtr_rts(struct uart_port *uport, bool raise) 173 173 { 174 174 if (raise) 175 175 uart_set_mctrl(uport, TIOCM_DTR | TIOCM_RTS); ··· 239 239 * port is open and ready to respond. 240 240 */ 241 241 if (init_hw && C_BAUD(tty)) 242 - uart_port_dtr_rts(uport, 1); 242 + uart_port_dtr_rts(uport, true); 243 243 } 244 244 245 245 /* ··· 302 302 } 303 303 304 304 if (!tty || C_HUPCL(tty)) 305 - uart_port_dtr_rts(uport, 0); 305 + uart_port_dtr_rts(uport, false); 306 306 307 307 uart_port_shutdown(port); 308 308 } ··· 1885 1885 return mctrl & TIOCM_CAR; 1886 1886 } 1887 1887 1888 - static void uart_dtr_rts(struct tty_port *port, int raise) 1888 + static void uart_dtr_rts(struct tty_port *port, bool raise) 1889 1889 { 1890 1890 struct uart_state *state = container_of(port, struct uart_state, port); 1891 1891 struct uart_port *uport;
+2 -2
drivers/tty/tty_port.c
··· 463 463 void tty_port_raise_dtr_rts(struct tty_port *port) 464 464 { 465 465 if (port->ops->dtr_rts) 466 - port->ops->dtr_rts(port, 1); 466 + port->ops->dtr_rts(port, true); 467 467 } 468 468 EXPORT_SYMBOL(tty_port_raise_dtr_rts); 469 469 ··· 478 478 void tty_port_lower_dtr_rts(struct tty_port *port) 479 479 { 480 480 if (port->ops->dtr_rts) 481 - port->ops->dtr_rts(port, 0); 481 + port->ops->dtr_rts(port, false); 482 482 } 483 483 EXPORT_SYMBOL(tty_port_lower_dtr_rts); 484 484
+1 -1
drivers/usb/class/cdc-acm.c
··· 651 651 return tty_port_open(&acm->port, tty, filp); 652 652 } 653 653 654 - static void acm_port_dtr_rts(struct tty_port *port, int raise) 654 + static void acm_port_dtr_rts(struct tty_port *port, bool raise) 655 655 { 656 656 struct acm *acm = container_of(port, struct acm, port); 657 657 int val;
+1 -1
drivers/usb/serial/usb-serial.c
··· 765 765 return true; 766 766 } 767 767 768 - static void serial_port_dtr_rts(struct tty_port *port, int on) 768 + static void serial_port_dtr_rts(struct tty_port *port, bool on) 769 769 { 770 770 struct usb_serial_port *p = container_of(port, struct usb_serial_port, port); 771 771 struct usb_serial_driver *drv = p->serial->type;
+2 -2
include/linux/tty_port.h
··· 16 16 /** 17 17 * struct tty_port_operations -- operations on tty_port 18 18 * @carrier_raised: return true if the carrier is raised on @port 19 - * @dtr_rts: raise the DTR line if @raise is nonzero, otherwise lower DTR 19 + * @dtr_rts: raise the DTR line if @raise is true, otherwise lower DTR 20 20 * @shutdown: called when the last close completes or a hangup finishes IFF the 21 21 * port was initialized. Do not use to free resources. Turn off the device 22 22 * only. Called under the port mutex to serialize against @activate and ··· 32 32 */ 33 33 struct tty_port_operations { 34 34 bool (*carrier_raised)(struct tty_port *port); 35 - void (*dtr_rts)(struct tty_port *port, int raise); 35 + void (*dtr_rts)(struct tty_port *port, bool raise); 36 36 void (*shutdown)(struct tty_port *port); 37 37 int (*activate)(struct tty_port *port, struct tty_struct *tty); 38 38 void (*destruct)(struct tty_port *port);