diff options
author | Jamie Iles <jamie@jamieiles.com> | 2010-12-01 18:39:35 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-12-10 18:19:37 -0500 |
commit | 49d5741be27aa90301b89bf254972b355ed9c8ee (patch) | |
tree | 10da68046d0ba7e92cd156d413d8b03f72dec0fb /drivers/serial | |
parent | 1b41dbc1296269797efbb2b0837732b74de4731d (diff) |
8250: use container_of() instead of casting
The 8250 driver structure uart_8250_port took advantage of the fact
that the struct uart_port was the first member of its structure and
used an explicit cast to convert to the derived class. Replace the
explicit casts with container_of() for safety and clarity.
Signed-off-by: Jamie Iles <jamie@jamieiles.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/serial')
-rw-r--r-- | drivers/serial/8250.c | 60 |
1 files changed, 40 insertions, 20 deletions
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c index 4d8e14b7aa93..0b4ce47d9871 100644 --- a/drivers/serial/8250.c +++ b/drivers/serial/8250.c | |||
@@ -461,7 +461,8 @@ static void dwapb_serial_out(struct uart_port *p, int offset, int value) | |||
461 | /* Save the LCR value so it can be re-written when a | 461 | /* Save the LCR value so it can be re-written when a |
462 | * Busy Detect interrupt occurs. */ | 462 | * Busy Detect interrupt occurs. */ |
463 | if (save_offset == UART_LCR) { | 463 | if (save_offset == UART_LCR) { |
464 | struct uart_8250_port *up = (struct uart_8250_port *)p; | 464 | struct uart_8250_port *up = |
465 | container_of(p, struct uart_8250_port, port); | ||
465 | up->lcr = value; | 466 | up->lcr = value; |
466 | } | 467 | } |
467 | writeb(value, p->membase + offset); | 468 | writeb(value, p->membase + offset); |
@@ -485,7 +486,8 @@ static void io_serial_out(struct uart_port *p, int offset, int value) | |||
485 | 486 | ||
486 | static void set_io_from_upio(struct uart_port *p) | 487 | static void set_io_from_upio(struct uart_port *p) |
487 | { | 488 | { |
488 | struct uart_8250_port *up = (struct uart_8250_port *)p; | 489 | struct uart_8250_port *up = |
490 | container_of(p, struct uart_8250_port, port); | ||
489 | switch (p->iotype) { | 491 | switch (p->iotype) { |
490 | case UPIO_HUB6: | 492 | case UPIO_HUB6: |
491 | p->serial_in = hub6_serial_in; | 493 | p->serial_in = hub6_serial_in; |
@@ -1319,7 +1321,8 @@ static inline void __stop_tx(struct uart_8250_port *p) | |||
1319 | 1321 | ||
1320 | static void serial8250_stop_tx(struct uart_port *port) | 1322 | static void serial8250_stop_tx(struct uart_port *port) |
1321 | { | 1323 | { |
1322 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1324 | struct uart_8250_port *up = |
1325 | container_of(port, struct uart_8250_port, port); | ||
1323 | 1326 | ||
1324 | __stop_tx(up); | 1327 | __stop_tx(up); |
1325 | 1328 | ||
@@ -1336,7 +1339,8 @@ static void transmit_chars(struct uart_8250_port *up); | |||
1336 | 1339 | ||
1337 | static void serial8250_start_tx(struct uart_port *port) | 1340 | static void serial8250_start_tx(struct uart_port *port) |
1338 | { | 1341 | { |
1339 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1342 | struct uart_8250_port *up = |
1343 | container_of(port, struct uart_8250_port, port); | ||
1340 | 1344 | ||
1341 | if (!(up->ier & UART_IER_THRI)) { | 1345 | if (!(up->ier & UART_IER_THRI)) { |
1342 | up->ier |= UART_IER_THRI; | 1346 | up->ier |= UART_IER_THRI; |
@@ -1364,7 +1368,8 @@ static void serial8250_start_tx(struct uart_port *port) | |||
1364 | 1368 | ||
1365 | static void serial8250_stop_rx(struct uart_port *port) | 1369 | static void serial8250_stop_rx(struct uart_port *port) |
1366 | { | 1370 | { |
1367 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1371 | struct uart_8250_port *up = |
1372 | container_of(port, struct uart_8250_port, port); | ||
1368 | 1373 | ||
1369 | up->ier &= ~UART_IER_RLSI; | 1374 | up->ier &= ~UART_IER_RLSI; |
1370 | up->port.read_status_mask &= ~UART_LSR_DR; | 1375 | up->port.read_status_mask &= ~UART_LSR_DR; |
@@ -1373,7 +1378,8 @@ static void serial8250_stop_rx(struct uart_port *port) | |||
1373 | 1378 | ||
1374 | static void serial8250_enable_ms(struct uart_port *port) | 1379 | static void serial8250_enable_ms(struct uart_port *port) |
1375 | { | 1380 | { |
1376 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1381 | struct uart_8250_port *up = |
1382 | container_of(port, struct uart_8250_port, port); | ||
1377 | 1383 | ||
1378 | /* no MSR capabilities */ | 1384 | /* no MSR capabilities */ |
1379 | if (up->bugs & UART_BUG_NOMSR) | 1385 | if (up->bugs & UART_BUG_NOMSR) |
@@ -1781,7 +1787,8 @@ static void serial8250_backup_timeout(unsigned long data) | |||
1781 | 1787 | ||
1782 | static unsigned int serial8250_tx_empty(struct uart_port *port) | 1788 | static unsigned int serial8250_tx_empty(struct uart_port *port) |
1783 | { | 1789 | { |
1784 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1790 | struct uart_8250_port *up = |
1791 | container_of(port, struct uart_8250_port, port); | ||
1785 | unsigned long flags; | 1792 | unsigned long flags; |
1786 | unsigned int lsr; | 1793 | unsigned int lsr; |
1787 | 1794 | ||
@@ -1795,7 +1802,8 @@ static unsigned int serial8250_tx_empty(struct uart_port *port) | |||
1795 | 1802 | ||
1796 | static unsigned int serial8250_get_mctrl(struct uart_port *port) | 1803 | static unsigned int serial8250_get_mctrl(struct uart_port *port) |
1797 | { | 1804 | { |
1798 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1805 | struct uart_8250_port *up = |
1806 | container_of(port, struct uart_8250_port, port); | ||
1799 | unsigned int status; | 1807 | unsigned int status; |
1800 | unsigned int ret; | 1808 | unsigned int ret; |
1801 | 1809 | ||
@@ -1815,7 +1823,8 @@ static unsigned int serial8250_get_mctrl(struct uart_port *port) | |||
1815 | 1823 | ||
1816 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) | 1824 | static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) |
1817 | { | 1825 | { |
1818 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1826 | struct uart_8250_port *up = |
1827 | container_of(port, struct uart_8250_port, port); | ||
1819 | unsigned char mcr = 0; | 1828 | unsigned char mcr = 0; |
1820 | 1829 | ||
1821 | if (mctrl & TIOCM_RTS) | 1830 | if (mctrl & TIOCM_RTS) |
@@ -1836,7 +1845,8 @@ static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) | |||
1836 | 1845 | ||
1837 | static void serial8250_break_ctl(struct uart_port *port, int break_state) | 1846 | static void serial8250_break_ctl(struct uart_port *port, int break_state) |
1838 | { | 1847 | { |
1839 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1848 | struct uart_8250_port *up = |
1849 | container_of(port, struct uart_8250_port, port); | ||
1840 | unsigned long flags; | 1850 | unsigned long flags; |
1841 | 1851 | ||
1842 | spin_lock_irqsave(&up->port.lock, flags); | 1852 | spin_lock_irqsave(&up->port.lock, flags); |
@@ -1890,7 +1900,8 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits) | |||
1890 | 1900 | ||
1891 | static int serial8250_get_poll_char(struct uart_port *port) | 1901 | static int serial8250_get_poll_char(struct uart_port *port) |
1892 | { | 1902 | { |
1893 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1903 | struct uart_8250_port *up = |
1904 | container_of(port, struct uart_8250_port, port); | ||
1894 | unsigned char lsr = serial_inp(up, UART_LSR); | 1905 | unsigned char lsr = serial_inp(up, UART_LSR); |
1895 | 1906 | ||
1896 | if (!(lsr & UART_LSR_DR)) | 1907 | if (!(lsr & UART_LSR_DR)) |
@@ -1904,7 +1915,8 @@ static void serial8250_put_poll_char(struct uart_port *port, | |||
1904 | unsigned char c) | 1915 | unsigned char c) |
1905 | { | 1916 | { |
1906 | unsigned int ier; | 1917 | unsigned int ier; |
1907 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1918 | struct uart_8250_port *up = |
1919 | container_of(port, struct uart_8250_port, port); | ||
1908 | 1920 | ||
1909 | /* | 1921 | /* |
1910 | * First save the IER then disable the interrupts | 1922 | * First save the IER then disable the interrupts |
@@ -1938,7 +1950,8 @@ static void serial8250_put_poll_char(struct uart_port *port, | |||
1938 | 1950 | ||
1939 | static int serial8250_startup(struct uart_port *port) | 1951 | static int serial8250_startup(struct uart_port *port) |
1940 | { | 1952 | { |
1941 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 1953 | struct uart_8250_port *up = |
1954 | container_of(port, struct uart_8250_port, port); | ||
1942 | unsigned long flags; | 1955 | unsigned long flags; |
1943 | unsigned char lsr, iir; | 1956 | unsigned char lsr, iir; |
1944 | int retval; | 1957 | int retval; |
@@ -2166,7 +2179,8 @@ dont_test_tx_en: | |||
2166 | 2179 | ||
2167 | static void serial8250_shutdown(struct uart_port *port) | 2180 | static void serial8250_shutdown(struct uart_port *port) |
2168 | { | 2181 | { |
2169 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2182 | struct uart_8250_port *up = |
2183 | container_of(port, struct uart_8250_port, port); | ||
2170 | unsigned long flags; | 2184 | unsigned long flags; |
2171 | 2185 | ||
2172 | /* | 2186 | /* |
@@ -2235,7 +2249,8 @@ void | |||
2235 | serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, | 2249 | serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, |
2236 | struct ktermios *old) | 2250 | struct ktermios *old) |
2237 | { | 2251 | { |
2238 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2252 | struct uart_8250_port *up = |
2253 | container_of(port, struct uart_8250_port, port); | ||
2239 | unsigned char cval, fcr = 0; | 2254 | unsigned char cval, fcr = 0; |
2240 | unsigned long flags; | 2255 | unsigned long flags; |
2241 | unsigned int baud, quot; | 2256 | unsigned int baud, quot; |
@@ -2435,7 +2450,8 @@ serial8250_set_ldisc(struct uart_port *port, int new) | |||
2435 | void serial8250_do_pm(struct uart_port *port, unsigned int state, | 2450 | void serial8250_do_pm(struct uart_port *port, unsigned int state, |
2436 | unsigned int oldstate) | 2451 | unsigned int oldstate) |
2437 | { | 2452 | { |
2438 | struct uart_8250_port *p = (struct uart_8250_port *)port; | 2453 | struct uart_8250_port *p = |
2454 | container_of(port, struct uart_8250_port, port); | ||
2439 | 2455 | ||
2440 | serial8250_set_sleep(p, state != 0); | 2456 | serial8250_set_sleep(p, state != 0); |
2441 | } | 2457 | } |
@@ -2566,7 +2582,8 @@ static void serial8250_release_rsa_resource(struct uart_8250_port *up) | |||
2566 | 2582 | ||
2567 | static void serial8250_release_port(struct uart_port *port) | 2583 | static void serial8250_release_port(struct uart_port *port) |
2568 | { | 2584 | { |
2569 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2585 | struct uart_8250_port *up = |
2586 | container_of(port, struct uart_8250_port, port); | ||
2570 | 2587 | ||
2571 | serial8250_release_std_resource(up); | 2588 | serial8250_release_std_resource(up); |
2572 | if (up->port.type == PORT_RSA) | 2589 | if (up->port.type == PORT_RSA) |
@@ -2575,7 +2592,8 @@ static void serial8250_release_port(struct uart_port *port) | |||
2575 | 2592 | ||
2576 | static int serial8250_request_port(struct uart_port *port) | 2593 | static int serial8250_request_port(struct uart_port *port) |
2577 | { | 2594 | { |
2578 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2595 | struct uart_8250_port *up = |
2596 | container_of(port, struct uart_8250_port, port); | ||
2579 | int ret = 0; | 2597 | int ret = 0; |
2580 | 2598 | ||
2581 | ret = serial8250_request_std_resource(up); | 2599 | ret = serial8250_request_std_resource(up); |
@@ -2590,7 +2608,8 @@ static int serial8250_request_port(struct uart_port *port) | |||
2590 | 2608 | ||
2591 | static void serial8250_config_port(struct uart_port *port, int flags) | 2609 | static void serial8250_config_port(struct uart_port *port, int flags) |
2592 | { | 2610 | { |
2593 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2611 | struct uart_8250_port *up = |
2612 | container_of(port, struct uart_8250_port, port); | ||
2594 | int probeflags = PROBE_ANY; | 2613 | int probeflags = PROBE_ANY; |
2595 | int ret; | 2614 | int ret; |
2596 | 2615 | ||
@@ -2771,7 +2790,8 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) | |||
2771 | 2790 | ||
2772 | static void serial8250_console_putchar(struct uart_port *port, int ch) | 2791 | static void serial8250_console_putchar(struct uart_port *port, int ch) |
2773 | { | 2792 | { |
2774 | struct uart_8250_port *up = (struct uart_8250_port *)port; | 2793 | struct uart_8250_port *up = |
2794 | container_of(port, struct uart_8250_port, port); | ||
2775 | 2795 | ||
2776 | wait_for_xmitr(up, UART_LSR_THRE); | 2796 | wait_for_xmitr(up, UART_LSR_THRE); |
2777 | serial_out(up, UART_TX, ch); | 2797 | serial_out(up, UART_TX, ch); |