Skip to content

Commit 3093f18

Browse files
Villemoesgregkh
authored andcommitted
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 <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Reviewed-by: Fabio Estevam <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 80c4d3d commit 3093f18

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

drivers/tty/serial/imx.c

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ static const struct of_device_id imx_uart_dt_ids[] = {
264264
};
265265
MODULE_DEVICE_TABLE(of, imx_uart_dt_ids);
266266

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+
267272
static inline void imx_uart_writel(struct imx_port *sport, u32 val, u32 offset)
268273
{
269274
writel(val, sport->port.membase + offset);
@@ -377,7 +382,7 @@ static void imx_uart_disable_loopback_rs485(struct imx_port *sport)
377382
/* called with port.lock taken and irqs off */
378383
static void imx_uart_start_rx(struct uart_port *port)
379384
{
380-
struct imx_port *sport = (struct imx_port *)port;
385+
struct imx_port *sport = to_imx_port(port);
381386
unsigned int ucr1, ucr2;
382387

383388
ucr1 = imx_uart_readl(sport, UCR1);
@@ -401,7 +406,7 @@ static void imx_uart_start_rx(struct uart_port *port)
401406
/* called with port.lock taken and irqs off */
402407
static void imx_uart_stop_tx(struct uart_port *port)
403408
{
404-
struct imx_port *sport = (struct imx_port *)port;
409+
struct imx_port *sport = to_imx_port(port);
405410
u32 ucr1, ucr4, usr2;
406411

407412
if (sport->tx_state == OFF)
@@ -466,7 +471,7 @@ static void imx_uart_stop_tx(struct uart_port *port)
466471

467472
static void imx_uart_stop_rx_with_loopback_ctrl(struct uart_port *port, bool loopback)
468473
{
469-
struct imx_port *sport = (struct imx_port *)port;
474+
struct imx_port *sport = to_imx_port(port);
470475
u32 ucr1, ucr2, ucr4, uts;
471476

472477
ucr1 = imx_uart_readl(sport, UCR1);
@@ -511,7 +516,7 @@ static void imx_uart_stop_rx(struct uart_port *port)
511516
/* called with port.lock taken and irqs off */
512517
static void imx_uart_enable_ms(struct uart_port *port)
513518
{
514-
struct imx_port *sport = (struct imx_port *)port;
519+
struct imx_port *sport = to_imx_port(port);
515520

516521
mod_timer(&sport->timer, jiffies);
517522

@@ -662,7 +667,7 @@ static void imx_uart_dma_tx(struct imx_port *sport)
662667
/* called with port.lock taken and irqs off */
663668
static void imx_uart_start_tx(struct uart_port *port)
664669
{
665-
struct imx_port *sport = (struct imx_port *)port;
670+
struct imx_port *sport = to_imx_port(port);
666671
struct tty_port *tport = &sport->port.state->port;
667672
u32 ucr1;
668673

@@ -1043,7 +1048,7 @@ static irqreturn_t imx_uart_int(int irq, void *dev_id)
10431048
*/
10441049
static unsigned int imx_uart_tx_empty(struct uart_port *port)
10451050
{
1046-
struct imx_port *sport = (struct imx_port *)port;
1051+
struct imx_port *sport = to_imx_port(port);
10471052
unsigned int ret;
10481053

10491054
ret = (imx_uart_readl(sport, USR2) & USR2_TXDC) ? TIOCSER_TEMT : 0;
@@ -1058,7 +1063,7 @@ static unsigned int imx_uart_tx_empty(struct uart_port *port)
10581063
/* called with port.lock taken and irqs off */
10591064
static unsigned int imx_uart_get_mctrl(struct uart_port *port)
10601065
{
1061-
struct imx_port *sport = (struct imx_port *)port;
1066+
struct imx_port *sport = to_imx_port(port);
10621067
unsigned int ret = imx_uart_get_hwmctrl(sport);
10631068

10641069
mctrl_gpio_get(sport->gpios, &ret);
@@ -1069,7 +1074,7 @@ static unsigned int imx_uart_get_mctrl(struct uart_port *port)
10691074
/* called with port.lock taken and irqs off */
10701075
static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
10711076
{
1072-
struct imx_port *sport = (struct imx_port *)port;
1077+
struct imx_port *sport = to_imx_port(port);
10731078
u32 ucr3, uts;
10741079

10751080
if (!(port->rs485.flags & SER_RS485_ENABLED)) {
@@ -1112,7 +1117,7 @@ static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
11121117
*/
11131118
static void imx_uart_break_ctl(struct uart_port *port, int break_state)
11141119
{
1115-
struct imx_port *sport = (struct imx_port *)port;
1120+
struct imx_port *sport = to_imx_port(port);
11161121
unsigned long flags;
11171122
u32 ucr1;
11181123

@@ -1434,7 +1439,7 @@ static void imx_uart_disable_dma(struct imx_port *sport)
14341439

14351440
static int imx_uart_startup(struct uart_port *port)
14361441
{
1437-
struct imx_port *sport = (struct imx_port *)port;
1442+
struct imx_port *sport = to_imx_port(port);
14381443
int retval;
14391444
unsigned long flags;
14401445
int dma_is_inited = 0;
@@ -1548,7 +1553,7 @@ static int imx_uart_startup(struct uart_port *port)
15481553

15491554
static void imx_uart_shutdown(struct uart_port *port)
15501555
{
1551-
struct imx_port *sport = (struct imx_port *)port;
1556+
struct imx_port *sport = to_imx_port(port);
15521557
unsigned long flags;
15531558
u32 ucr1, ucr2, ucr4, uts;
15541559

@@ -1622,7 +1627,7 @@ static void imx_uart_shutdown(struct uart_port *port)
16221627
/* called with port.lock taken and irqs off */
16231628
static void imx_uart_flush_buffer(struct uart_port *port)
16241629
{
1625-
struct imx_port *sport = (struct imx_port *)port;
1630+
struct imx_port *sport = to_imx_port(port);
16261631
struct scatterlist *sgl = &sport->tx_sgl[0];
16271632

16281633
if (!sport->dma_chan_tx)
@@ -1649,7 +1654,7 @@ static void
16491654
imx_uart_set_termios(struct uart_port *port, struct ktermios *termios,
16501655
const struct ktermios *old)
16511656
{
1652-
struct imx_port *sport = (struct imx_port *)port;
1657+
struct imx_port *sport = to_imx_port(port);
16531658
unsigned long flags;
16541659
u32 ucr2, old_ucr2, ufcr;
16551660
unsigned int baud, quot;
@@ -1852,7 +1857,7 @@ imx_uart_verify_port(struct uart_port *port, struct serial_struct *ser)
18521857

18531858
static int imx_uart_poll_init(struct uart_port *port)
18541859
{
1855-
struct imx_port *sport = (struct imx_port *)port;
1860+
struct imx_port *sport = to_imx_port(port);
18561861
unsigned long flags;
18571862
u32 ucr1, ucr2;
18581863
int retval;
@@ -1901,7 +1906,7 @@ static int imx_uart_poll_init(struct uart_port *port)
19011906

19021907
static int imx_uart_poll_get_char(struct uart_port *port)
19031908
{
1904-
struct imx_port *sport = (struct imx_port *)port;
1909+
struct imx_port *sport = to_imx_port(port);
19051910
if (!(imx_uart_readl(sport, USR2) & USR2_RDR))
19061911
return NO_POLL_CHAR;
19071912

@@ -1910,7 +1915,7 @@ static int imx_uart_poll_get_char(struct uart_port *port)
19101915

19111916
static void imx_uart_poll_put_char(struct uart_port *port, unsigned char c)
19121917
{
1913-
struct imx_port *sport = (struct imx_port *)port;
1918+
struct imx_port *sport = to_imx_port(port);
19141919
unsigned int status;
19151920

19161921
/* drain */
@@ -1932,7 +1937,7 @@ static void imx_uart_poll_put_char(struct uart_port *port, unsigned char c)
19321937
static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termios,
19331938
struct serial_rs485 *rs485conf)
19341939
{
1935-
struct imx_port *sport = (struct imx_port *)port;
1940+
struct imx_port *sport = to_imx_port(port);
19361941
u32 ucr2;
19371942

19381943
if (rs485conf->flags & SER_RS485_ENABLED) {
@@ -1986,7 +1991,7 @@ static struct imx_port *imx_uart_ports[UART_NR];
19861991
#if IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE)
19871992
static void imx_uart_console_putchar(struct uart_port *port, unsigned char ch)
19881993
{
1989-
struct imx_port *sport = (struct imx_port *)port;
1994+
struct imx_port *sport = to_imx_port(port);
19901995

19911996
while (imx_uart_readl(sport, imx_uart_uts_reg(sport)) & UTS_TXFULL)
19921997
barrier();

0 commit comments

Comments
 (0)