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

Configure Feed

Select the types of activity you want to include in your feed.

serial: imx: stop casting struct uart_port to struct imx_port

struct imx_port does have a struct uart_port as its first member, so
the current code works, but it is not how kernel code is usually
written.

Similar to many other serial drivers, introduce and use a
to_imx_port() helper based on container_of(). No functional change.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Fabio Estevam <festevam@gmail.com>
Link: https://lore.kernel.org/r/20240528094022.2161066-1-linux@rasmusvillemoes.dk
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Rasmus Villemoes and committed by
Greg Kroah-Hartman
3093f180 80c4d3d4

+23 -18
+23 -18
drivers/tty/serial/imx.c
··· 264 264 }; 265 265 MODULE_DEVICE_TABLE(of, imx_uart_dt_ids); 266 266 267 + static inline struct imx_port *to_imx_port(struct uart_port *port) 268 + { 269 + return container_of(port, struct imx_port, port); 270 + } 271 + 267 272 static inline void imx_uart_writel(struct imx_port *sport, u32 val, u32 offset) 268 273 { 269 274 writel(val, sport->port.membase + offset); ··· 382 377 /* called with port.lock taken and irqs off */ 383 378 static void imx_uart_start_rx(struct uart_port *port) 384 379 { 385 - struct imx_port *sport = (struct imx_port *)port; 380 + struct imx_port *sport = to_imx_port(port); 386 381 unsigned int ucr1, ucr2; 387 382 388 383 ucr1 = imx_uart_readl(sport, UCR1); ··· 406 401 /* called with port.lock taken and irqs off */ 407 402 static void imx_uart_stop_tx(struct uart_port *port) 408 403 { 409 - struct imx_port *sport = (struct imx_port *)port; 404 + struct imx_port *sport = to_imx_port(port); 410 405 u32 ucr1, ucr4, usr2; 411 406 412 407 if (sport->tx_state == OFF) ··· 471 466 472 467 static void imx_uart_stop_rx_with_loopback_ctrl(struct uart_port *port, bool loopback) 473 468 { 474 - struct imx_port *sport = (struct imx_port *)port; 469 + struct imx_port *sport = to_imx_port(port); 475 470 u32 ucr1, ucr2, ucr4, uts; 476 471 477 472 ucr1 = imx_uart_readl(sport, UCR1); ··· 516 511 /* called with port.lock taken and irqs off */ 517 512 static void imx_uart_enable_ms(struct uart_port *port) 518 513 { 519 - struct imx_port *sport = (struct imx_port *)port; 514 + struct imx_port *sport = to_imx_port(port); 520 515 521 516 mod_timer(&sport->timer, jiffies); 522 517 ··· 667 662 /* called with port.lock taken and irqs off */ 668 663 static void imx_uart_start_tx(struct uart_port *port) 669 664 { 670 - struct imx_port *sport = (struct imx_port *)port; 665 + struct imx_port *sport = to_imx_port(port); 671 666 struct tty_port *tport = &sport->port.state->port; 672 667 u32 ucr1; 673 668 ··· 1048 1043 */ 1049 1044 static unsigned int imx_uart_tx_empty(struct uart_port *port) 1050 1045 { 1051 - struct imx_port *sport = (struct imx_port *)port; 1046 + struct imx_port *sport = to_imx_port(port); 1052 1047 unsigned int ret; 1053 1048 1054 1049 ret = (imx_uart_readl(sport, USR2) & USR2_TXDC) ? TIOCSER_TEMT : 0; ··· 1063 1058 /* called with port.lock taken and irqs off */ 1064 1059 static unsigned int imx_uart_get_mctrl(struct uart_port *port) 1065 1060 { 1066 - struct imx_port *sport = (struct imx_port *)port; 1061 + struct imx_port *sport = to_imx_port(port); 1067 1062 unsigned int ret = imx_uart_get_hwmctrl(sport); 1068 1063 1069 1064 mctrl_gpio_get(sport->gpios, &ret); ··· 1074 1069 /* called with port.lock taken and irqs off */ 1075 1070 static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) 1076 1071 { 1077 - struct imx_port *sport = (struct imx_port *)port; 1072 + struct imx_port *sport = to_imx_port(port); 1078 1073 u32 ucr3, uts; 1079 1074 1080 1075 if (!(port->rs485.flags & SER_RS485_ENABLED)) { ··· 1117 1112 */ 1118 1113 static void imx_uart_break_ctl(struct uart_port *port, int break_state) 1119 1114 { 1120 - struct imx_port *sport = (struct imx_port *)port; 1115 + struct imx_port *sport = to_imx_port(port); 1121 1116 unsigned long flags; 1122 1117 u32 ucr1; 1123 1118 ··· 1439 1434 1440 1435 static int imx_uart_startup(struct uart_port *port) 1441 1436 { 1442 - struct imx_port *sport = (struct imx_port *)port; 1437 + struct imx_port *sport = to_imx_port(port); 1443 1438 int retval; 1444 1439 unsigned long flags; 1445 1440 int dma_is_inited = 0; ··· 1553 1548 1554 1549 static void imx_uart_shutdown(struct uart_port *port) 1555 1550 { 1556 - struct imx_port *sport = (struct imx_port *)port; 1551 + struct imx_port *sport = to_imx_port(port); 1557 1552 unsigned long flags; 1558 1553 u32 ucr1, ucr2, ucr4, uts; 1559 1554 ··· 1627 1622 /* called with port.lock taken and irqs off */ 1628 1623 static void imx_uart_flush_buffer(struct uart_port *port) 1629 1624 { 1630 - struct imx_port *sport = (struct imx_port *)port; 1625 + struct imx_port *sport = to_imx_port(port); 1631 1626 struct scatterlist *sgl = &sport->tx_sgl[0]; 1632 1627 1633 1628 if (!sport->dma_chan_tx) ··· 1654 1649 imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, 1655 1650 const struct ktermios *old) 1656 1651 { 1657 - struct imx_port *sport = (struct imx_port *)port; 1652 + struct imx_port *sport = to_imx_port(port); 1658 1653 unsigned long flags; 1659 1654 u32 ucr2, old_ucr2, ufcr; 1660 1655 unsigned int baud, quot; ··· 1857 1852 1858 1853 static int imx_uart_poll_init(struct uart_port *port) 1859 1854 { 1860 - struct imx_port *sport = (struct imx_port *)port; 1855 + struct imx_port *sport = to_imx_port(port); 1861 1856 unsigned long flags; 1862 1857 u32 ucr1, ucr2; 1863 1858 int retval; ··· 1906 1901 1907 1902 static int imx_uart_poll_get_char(struct uart_port *port) 1908 1903 { 1909 - struct imx_port *sport = (struct imx_port *)port; 1904 + struct imx_port *sport = to_imx_port(port); 1910 1905 if (!(imx_uart_readl(sport, USR2) & USR2_RDR)) 1911 1906 return NO_POLL_CHAR; 1912 1907 ··· 1915 1910 1916 1911 static void imx_uart_poll_put_char(struct uart_port *port, unsigned char c) 1917 1912 { 1918 - struct imx_port *sport = (struct imx_port *)port; 1913 + struct imx_port *sport = to_imx_port(port); 1919 1914 unsigned int status; 1920 1915 1921 1916 /* drain */ ··· 1937 1932 static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termios, 1938 1933 struct serial_rs485 *rs485conf) 1939 1934 { 1940 - struct imx_port *sport = (struct imx_port *)port; 1935 + struct imx_port *sport = to_imx_port(port); 1941 1936 u32 ucr2; 1942 1937 1943 1938 if (rs485conf->flags & SER_RS485_ENABLED) { ··· 1991 1986 #if IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE) 1992 1987 static void imx_uart_console_putchar(struct uart_port *port, unsigned char ch) 1993 1988 { 1994 - struct imx_port *sport = (struct imx_port *)port; 1989 + struct imx_port *sport = to_imx_port(port); 1995 1990 1996 1991 while (imx_uart_readl(sport, imx_uart_uts_reg(sport)) & UTS_TXFULL) 1997 1992 barrier();