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

uart: tidy the uart_get_info API

We pass both port and state because the original caller had both to hand.
With all the attribute callers this won't be true so do the conversion in
the function itself.

The current callers all do lock/query/unlock. This won't be true for future
set based cases but there are plenty of get ones that will exist so split
the code with a helper for the future cases.

Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Alan Cox and committed by
Greg Kroah-Hartman
9f109694 bebe73e3

+15 -14
+15 -14
drivers/tty/serial/serial_core.c
··· 634 634 uart_set_mctrl(port, TIOCM_RTS); 635 635 } 636 636 637 - static void uart_get_info(struct tty_port *port, 638 - struct uart_state *state, 637 + static void do_uart_get_info(struct tty_port *port, 639 638 struct serial_struct *retinfo) 640 639 { 640 + struct uart_state *state = container_of(port, struct uart_state, port); 641 641 struct uart_port *uport = state->uart_port; 642 642 643 643 memset(retinfo, 0, sizeof(*retinfo)); ··· 662 662 retinfo->iomem_base = (void *)(unsigned long)uport->mapbase; 663 663 } 664 664 665 - static int uart_get_info_user(struct uart_state *state, 666 - struct serial_struct __user *retinfo) 665 + static void uart_get_info(struct tty_port *port, 666 + struct serial_struct *retinfo) 667 667 { 668 - struct tty_port *port = &state->port; 669 - struct serial_struct tmp; 670 - 671 668 /* Ensure the state we copy is consistent and no hardware changes 672 669 occur as we go */ 673 670 mutex_lock(&port->mutex); 674 - uart_get_info(port, state, &tmp); 671 + do_uart_get_info(port, retinfo); 675 672 mutex_unlock(&port->mutex); 673 + } 674 + 675 + static int uart_get_info_user(struct tty_port *port, 676 + struct serial_struct __user *retinfo) 677 + { 678 + struct serial_struct tmp; 679 + uart_get_info(port, &tmp); 676 680 677 681 if (copy_to_user(retinfo, &tmp, sizeof(*retinfo))) 678 682 return -EFAULT; ··· 1135 1131 */ 1136 1132 switch (cmd) { 1137 1133 case TIOCGSERIAL: 1138 - ret = uart_get_info_user(state, uarg); 1134 + ret = uart_get_info_user(port, uarg); 1139 1135 break; 1140 1136 1141 1137 case TIOCSSERIAL: ··· 2335 2331 { 2336 2332 struct serial_struct tmp; 2337 2333 struct tty_port *port = dev_get_drvdata(dev); 2338 - struct uart_state *state = container_of(port, struct uart_state, port); 2339 2334 2340 - mutex_lock(&port->mutex); 2341 - uart_get_info(port, state, &tmp); 2342 - mutex_unlock(&port->mutex); 2343 - 2335 + uart_get_info(port, &tmp); 2344 2336 return snprintf(buf, PAGE_SIZE, "%d\n", tmp.baud_base * 16); 2345 2337 } 2346 2338 ··· 2355 2355 &tty_dev_attr_group, 2356 2356 NULL 2357 2357 }; 2358 + 2358 2359 2359 2360 /** 2360 2361 * uart_add_one_port - attach a driver-defined port structure