Commit 49d5741b authored by Jamie Iles's avatar Jamie Iles Committed by Greg Kroah-Hartman

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: default avatarJamie Iles <jamie@jamieiles.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1b41dbc1
...@@ -461,7 +461,8 @@ static void dwapb_serial_out(struct uart_port *p, int offset, int value) ...@@ -461,7 +461,8 @@ static void dwapb_serial_out(struct uart_port *p, int offset, int value)
/* Save the LCR value so it can be re-written when a /* Save the LCR value so it can be re-written when a
* Busy Detect interrupt occurs. */ * Busy Detect interrupt occurs. */
if (save_offset == UART_LCR) { if (save_offset == UART_LCR) {
struct uart_8250_port *up = (struct uart_8250_port *)p; struct uart_8250_port *up =
container_of(p, struct uart_8250_port, port);
up->lcr = value; up->lcr = value;
} }
writeb(value, p->membase + offset); writeb(value, p->membase + offset);
...@@ -485,7 +486,8 @@ static void io_serial_out(struct uart_port *p, int offset, int value) ...@@ -485,7 +486,8 @@ static void io_serial_out(struct uart_port *p, int offset, int value)
static void set_io_from_upio(struct uart_port *p) static void set_io_from_upio(struct uart_port *p)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)p; struct uart_8250_port *up =
container_of(p, struct uart_8250_port, port);
switch (p->iotype) { switch (p->iotype) {
case UPIO_HUB6: case UPIO_HUB6:
p->serial_in = hub6_serial_in; p->serial_in = hub6_serial_in;
...@@ -1319,7 +1321,8 @@ static inline void __stop_tx(struct uart_8250_port *p) ...@@ -1319,7 +1321,8 @@ static inline void __stop_tx(struct uart_8250_port *p)
static void serial8250_stop_tx(struct uart_port *port) static void serial8250_stop_tx(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
__stop_tx(up); __stop_tx(up);
...@@ -1336,7 +1339,8 @@ static void transmit_chars(struct uart_8250_port *up); ...@@ -1336,7 +1339,8 @@ static void transmit_chars(struct uart_8250_port *up);
static void serial8250_start_tx(struct uart_port *port) static void serial8250_start_tx(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
if (!(up->ier & UART_IER_THRI)) { if (!(up->ier & UART_IER_THRI)) {
up->ier |= UART_IER_THRI; up->ier |= UART_IER_THRI;
...@@ -1364,7 +1368,8 @@ static void serial8250_start_tx(struct uart_port *port) ...@@ -1364,7 +1368,8 @@ static void serial8250_start_tx(struct uart_port *port)
static void serial8250_stop_rx(struct uart_port *port) static void serial8250_stop_rx(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
up->ier &= ~UART_IER_RLSI; up->ier &= ~UART_IER_RLSI;
up->port.read_status_mask &= ~UART_LSR_DR; up->port.read_status_mask &= ~UART_LSR_DR;
...@@ -1373,7 +1378,8 @@ static void serial8250_stop_rx(struct uart_port *port) ...@@ -1373,7 +1378,8 @@ static void serial8250_stop_rx(struct uart_port *port)
static void serial8250_enable_ms(struct uart_port *port) static void serial8250_enable_ms(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
/* no MSR capabilities */ /* no MSR capabilities */
if (up->bugs & UART_BUG_NOMSR) if (up->bugs & UART_BUG_NOMSR)
...@@ -1781,7 +1787,8 @@ static void serial8250_backup_timeout(unsigned long data) ...@@ -1781,7 +1787,8 @@ static void serial8250_backup_timeout(unsigned long data)
static unsigned int serial8250_tx_empty(struct uart_port *port) static unsigned int serial8250_tx_empty(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned long flags; unsigned long flags;
unsigned int lsr; unsigned int lsr;
...@@ -1795,7 +1802,8 @@ static unsigned int serial8250_tx_empty(struct uart_port *port) ...@@ -1795,7 +1802,8 @@ static unsigned int serial8250_tx_empty(struct uart_port *port)
static unsigned int serial8250_get_mctrl(struct uart_port *port) static unsigned int serial8250_get_mctrl(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned int status; unsigned int status;
unsigned int ret; unsigned int ret;
...@@ -1815,7 +1823,8 @@ static unsigned int serial8250_get_mctrl(struct uart_port *port) ...@@ -1815,7 +1823,8 @@ static unsigned int serial8250_get_mctrl(struct uart_port *port)
static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned char mcr = 0; unsigned char mcr = 0;
if (mctrl & TIOCM_RTS) if (mctrl & TIOCM_RTS)
...@@ -1836,7 +1845,8 @@ static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl) ...@@ -1836,7 +1845,8 @@ static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
static void serial8250_break_ctl(struct uart_port *port, int break_state) static void serial8250_break_ctl(struct uart_port *port, int break_state)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&up->port.lock, flags); spin_lock_irqsave(&up->port.lock, flags);
...@@ -1890,7 +1900,8 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits) ...@@ -1890,7 +1900,8 @@ static void wait_for_xmitr(struct uart_8250_port *up, int bits)
static int serial8250_get_poll_char(struct uart_port *port) static int serial8250_get_poll_char(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned char lsr = serial_inp(up, UART_LSR); unsigned char lsr = serial_inp(up, UART_LSR);
if (!(lsr & UART_LSR_DR)) if (!(lsr & UART_LSR_DR))
...@@ -1904,7 +1915,8 @@ static void serial8250_put_poll_char(struct uart_port *port, ...@@ -1904,7 +1915,8 @@ static void serial8250_put_poll_char(struct uart_port *port,
unsigned char c) unsigned char c)
{ {
unsigned int ier; unsigned int ier;
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
/* /*
* First save the IER then disable the interrupts * First save the IER then disable the interrupts
...@@ -1938,7 +1950,8 @@ static void serial8250_put_poll_char(struct uart_port *port, ...@@ -1938,7 +1950,8 @@ static void serial8250_put_poll_char(struct uart_port *port,
static int serial8250_startup(struct uart_port *port) static int serial8250_startup(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned long flags; unsigned long flags;
unsigned char lsr, iir; unsigned char lsr, iir;
int retval; int retval;
...@@ -2166,7 +2179,8 @@ static int serial8250_startup(struct uart_port *port) ...@@ -2166,7 +2179,8 @@ static int serial8250_startup(struct uart_port *port)
static void serial8250_shutdown(struct uart_port *port) static void serial8250_shutdown(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned long flags; unsigned long flags;
/* /*
...@@ -2235,7 +2249,8 @@ void ...@@ -2235,7 +2249,8 @@ void
serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios, serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
struct ktermios *old) struct ktermios *old)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
unsigned char cval, fcr = 0; unsigned char cval, fcr = 0;
unsigned long flags; unsigned long flags;
unsigned int baud, quot; unsigned int baud, quot;
...@@ -2435,7 +2450,8 @@ serial8250_set_ldisc(struct uart_port *port, int new) ...@@ -2435,7 +2450,8 @@ serial8250_set_ldisc(struct uart_port *port, int new)
void serial8250_do_pm(struct uart_port *port, unsigned int state, void serial8250_do_pm(struct uart_port *port, unsigned int state,
unsigned int oldstate) unsigned int oldstate)
{ {
struct uart_8250_port *p = (struct uart_8250_port *)port; struct uart_8250_port *p =
container_of(port, struct uart_8250_port, port);
serial8250_set_sleep(p, state != 0); serial8250_set_sleep(p, state != 0);
} }
...@@ -2566,7 +2582,8 @@ static void serial8250_release_rsa_resource(struct uart_8250_port *up) ...@@ -2566,7 +2582,8 @@ static void serial8250_release_rsa_resource(struct uart_8250_port *up)
static void serial8250_release_port(struct uart_port *port) static void serial8250_release_port(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
serial8250_release_std_resource(up); serial8250_release_std_resource(up);
if (up->port.type == PORT_RSA) if (up->port.type == PORT_RSA)
...@@ -2575,7 +2592,8 @@ static void serial8250_release_port(struct uart_port *port) ...@@ -2575,7 +2592,8 @@ static void serial8250_release_port(struct uart_port *port)
static int serial8250_request_port(struct uart_port *port) static int serial8250_request_port(struct uart_port *port)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
int ret = 0; int ret = 0;
ret = serial8250_request_std_resource(up); ret = serial8250_request_std_resource(up);
...@@ -2590,7 +2608,8 @@ static int serial8250_request_port(struct uart_port *port) ...@@ -2590,7 +2608,8 @@ static int serial8250_request_port(struct uart_port *port)
static void serial8250_config_port(struct uart_port *port, int flags) static void serial8250_config_port(struct uart_port *port, int flags)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
int probeflags = PROBE_ANY; int probeflags = PROBE_ANY;
int ret; int ret;
...@@ -2771,7 +2790,8 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev) ...@@ -2771,7 +2790,8 @@ serial8250_register_ports(struct uart_driver *drv, struct device *dev)
static void serial8250_console_putchar(struct uart_port *port, int ch) static void serial8250_console_putchar(struct uart_port *port, int ch)
{ {
struct uart_8250_port *up = (struct uart_8250_port *)port; struct uart_8250_port *up =
container_of(port, struct uart_8250_port, port);
wait_for_xmitr(up, UART_LSR_THRE); wait_for_xmitr(up, UART_LSR_THRE);
serial_out(up, UART_TX, ch); serial_out(up, UART_TX, ch);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment