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: 8250: use guard()s

Having all the new guards, use them in the 8250 code. This improves
readability, makes error handling easier, and marks locked portions of
code explicit.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20250814072456.182853-10-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
b339809e 56609c05

+144 -221
+25 -46
drivers/tty/serial/8250/8250_core.c
··· 72 72 struct list_head *l, *end = NULL; 73 73 int pass_counter = 0, handled = 0; 74 74 75 - spin_lock(&i->lock); 75 + guard(spinlock)(&i->lock); 76 76 77 77 l = i->head; 78 78 do { ··· 90 90 if (l == i->head && pass_counter++ > PASS_LIMIT) 91 91 break; 92 92 } while (l != end); 93 - 94 - spin_unlock(&i->lock); 95 93 96 94 return IRQ_RETVAL(handled); 97 95 } ··· 130 132 { 131 133 struct irq_info *i; 132 134 133 - mutex_lock(&hash_mutex); 135 + guard(mutex)(&hash_mutex); 134 136 135 137 hash_for_each_possible(irq_lists, i, node, up->port.irq) 136 138 if (i->irq == up->port.irq) 137 - goto unlock; 139 + return i; 138 140 139 141 i = kzalloc(sizeof(*i), GFP_KERNEL); 140 - if (i == NULL) { 141 - i = ERR_PTR(-ENOMEM); 142 - goto unlock; 143 - } 142 + if (i == NULL) 143 + return ERR_PTR(-ENOMEM); 144 + 144 145 spin_lock_init(&i->lock); 145 146 i->irq = up->port.irq; 146 147 hash_add(irq_lists, &i->node, i->irq); 147 - unlock: 148 - mutex_unlock(&hash_mutex); 149 148 150 149 return i; 151 150 } ··· 156 161 if (IS_ERR(i)) 157 162 return PTR_ERR(i); 158 163 159 - spin_lock_irq(&i->lock); 164 + scoped_guard(spinlock_irq, &i->lock) { 165 + if (i->head) { 166 + list_add(&up->list, i->head); 160 167 161 - if (i->head) { 162 - list_add(&up->list, i->head); 163 - spin_unlock_irq(&i->lock); 168 + return 0; 169 + } 164 170 165 - ret = 0; 166 - } else { 167 171 INIT_LIST_HEAD(&up->list); 168 172 i->head = &up->list; 169 - spin_unlock_irq(&i->lock); 170 - ret = request_irq(up->port.irq, serial8250_interrupt, 171 - up->port.irqflags, up->port.name, i); 172 - if (ret < 0) 173 - serial_do_unlink(i, up); 174 173 } 174 + 175 + ret = request_irq(up->port.irq, serial8250_interrupt, up->port.irqflags, up->port.name, i); 176 + if (ret < 0) 177 + serial_do_unlink(i, up); 175 178 176 179 return ret; 177 180 } ··· 663 670 664 671 static void serial_8250_overrun_backoff_work(struct work_struct *work) 665 672 { 666 - struct uart_8250_port *up = 667 - container_of(to_delayed_work(work), struct uart_8250_port, 668 - overrun_backoff); 669 - struct uart_port *port = &up->port; 670 - unsigned long flags; 673 + struct uart_8250_port *up = container_of(to_delayed_work(work), struct uart_8250_port, 674 + overrun_backoff); 671 675 672 - uart_port_lock_irqsave(port, &flags); 676 + guard(uart_port_lock_irqsave)(&up->port); 673 677 up->ier |= UART_IER_RLSI | UART_IER_RDI; 674 678 serial_out(up, UART_IER, up->ier); 675 - uart_port_unlock_irqrestore(port, flags); 676 679 } 677 680 678 681 /** ··· 687 698 int serial8250_register_8250_port(const struct uart_8250_port *up) 688 699 { 689 700 struct uart_8250_port *uart; 690 - int ret = -ENOSPC; 701 + int ret; 691 702 692 703 if (up->port.uartclk == 0) 693 704 return -EINVAL; 694 705 695 - mutex_lock(&serial_mutex); 706 + guard(mutex)(&serial_mutex); 696 707 697 708 uart = serial8250_find_match_or_unused(&up->port); 698 709 if (!uart) { ··· 702 713 */ 703 714 uart = serial8250_setup_port(nr_uarts); 704 715 if (!uart) 705 - goto unlock; 716 + return -ENOSPC; 706 717 nr_uarts++; 707 718 } 708 719 709 720 /* Check if it is CIR already. We check this below again, see there why. */ 710 - if (uart->port.type == PORT_8250_CIR) { 711 - ret = -ENODEV; 712 - goto unlock; 713 - } 721 + if (uart->port.type == PORT_8250_CIR) 722 + return -ENODEV; 714 723 715 724 if (uart->port.dev) 716 725 uart_remove_one_port(&serial8250_reg, &uart->port); ··· 842 855 uart->overrun_backoff_time_ms = 0; 843 856 } 844 857 845 - unlock: 846 - mutex_unlock(&serial_mutex); 847 - 848 858 return ret; 849 859 850 860 err: 851 861 uart->port.dev = NULL; 852 - mutex_unlock(&serial_mutex); 853 862 return ret; 854 863 } 855 864 EXPORT_SYMBOL(serial8250_register_8250_port); ··· 861 878 { 862 879 struct uart_8250_port *uart = &serial8250_ports[line]; 863 880 864 - mutex_lock(&serial_mutex); 881 + guard(mutex)(&serial_mutex); 865 882 866 883 if (uart->em485) { 867 - unsigned long flags; 868 - 869 - uart_port_lock_irqsave(&uart->port, &flags); 884 + guard(uart_port_lock_irqsave)(&uart->port); 870 885 serial8250_em485_destroy(uart); 871 - uart_port_unlock_irqrestore(&uart->port, flags); 872 886 } 873 887 874 888 uart_remove_one_port(&serial8250_reg, &uart->port); ··· 881 901 } else { 882 902 uart->port.dev = NULL; 883 903 } 884 - mutex_unlock(&serial_mutex); 885 904 } 886 905 EXPORT_SYMBOL(serial8250_unregister_port); 887 906
+119 -175
drivers/tty/serial/8250/8250_port.c
··· 674 674 { 675 675 unsigned char lcr = 0, efr = 0; 676 676 677 - serial8250_rpm_get(p); 677 + guard(serial8250_rpm)(p); 678 678 679 - if (p->capabilities & UART_CAP_SLEEP) { 680 - /* Synchronize UART_IER access against the console. */ 681 - uart_port_lock_irq(&p->port); 682 - if (p->capabilities & UART_CAP_EFR) { 683 - lcr = serial_in(p, UART_LCR); 684 - efr = serial_in(p, UART_EFR); 685 - serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 686 - serial_out(p, UART_EFR, UART_EFR_ECB); 687 - serial_out(p, UART_LCR, 0); 688 - } 689 - serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 690 - if (p->capabilities & UART_CAP_EFR) { 691 - serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 692 - serial_out(p, UART_EFR, efr); 693 - serial_out(p, UART_LCR, lcr); 694 - } 695 - uart_port_unlock_irq(&p->port); 679 + if (!(p->capabilities & UART_CAP_SLEEP)) 680 + return; 681 + 682 + /* Synchronize UART_IER access against the console. */ 683 + guard(uart_port_lock_irq)(&p->port); 684 + 685 + if (p->capabilities & UART_CAP_EFR) { 686 + lcr = serial_in(p, UART_LCR); 687 + efr = serial_in(p, UART_EFR); 688 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 689 + serial_out(p, UART_EFR, UART_EFR_ECB); 690 + serial_out(p, UART_LCR, 0); 696 691 } 697 - 698 - serial8250_rpm_put(p); 692 + serial_out(p, UART_IER, sleep ? UART_IERX_SLEEP : 0); 693 + if (p->capabilities & UART_CAP_EFR) { 694 + serial_out(p, UART_LCR, UART_LCR_CONF_MODE_B); 695 + serial_out(p, UART_EFR, efr); 696 + serial_out(p, UART_LCR, lcr); 697 + } 699 698 } 700 699 701 700 /* Clear the interrupt registers. */ ··· 1230 1231 probe_irq_off(probe_irq_on()); 1231 1232 save_mcr = serial8250_in_MCR(up); 1232 1233 /* Synchronize UART_IER access against the console. */ 1233 - uart_port_lock_irq(port); 1234 - save_ier = serial_in(up, UART_IER); 1235 - uart_port_unlock_irq(port); 1234 + scoped_guard(uart_port_lock_irq, port) 1235 + save_ier = serial_in(up, UART_IER); 1236 1236 serial8250_out_MCR(up, UART_MCR_OUT1 | UART_MCR_OUT2); 1237 1237 1238 1238 irqs = probe_irq_on(); ··· 1244 1246 UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2); 1245 1247 } 1246 1248 /* Synchronize UART_IER access against the console. */ 1247 - uart_port_lock_irq(port); 1248 - serial_out(up, UART_IER, UART_IER_ALL_INTR); 1249 - uart_port_unlock_irq(port); 1249 + scoped_guard(uart_port_lock_irq, port) 1250 + serial_out(up, UART_IER, UART_IER_ALL_INTR); 1250 1251 serial8250_clear_interrupts(port); 1251 1252 serial_out(up, UART_TX, 0xFF); 1252 1253 udelay(20); ··· 1253 1256 1254 1257 serial8250_out_MCR(up, save_mcr); 1255 1258 /* Synchronize UART_IER access against the console. */ 1256 - uart_port_lock_irq(port); 1257 - serial_out(up, UART_IER, save_ier); 1258 - uart_port_unlock_irq(port); 1259 + scoped_guard(uart_port_lock_irq, port) 1260 + serial_out(up, UART_IER, save_ier); 1259 1261 1260 1262 if (port->flags & UPF_FOURPORT) 1261 1263 outb_p(save_ICP, ICP); ··· 1269 1273 /* Port locked to synchronize UART_IER access against the console. */ 1270 1274 lockdep_assert_held_once(&port->lock); 1271 1275 1272 - serial8250_rpm_get(up); 1276 + guard(serial8250_rpm)(up); 1273 1277 1274 1278 up->ier &= ~(UART_IER_RLSI | UART_IER_RDI); 1275 1279 serial_port_out(port, UART_IER, up->ier); 1276 - 1277 - serial8250_rpm_put(up); 1278 1280 } 1279 1281 1280 1282 /** ··· 1316 1322 struct uart_8250_em485 *em485 = container_of(t, struct uart_8250_em485, 1317 1323 stop_tx_timer); 1318 1324 struct uart_8250_port *p = em485->port; 1319 - unsigned long flags; 1320 1325 1321 - serial8250_rpm_get(p); 1322 - uart_port_lock_irqsave(&p->port, &flags); 1326 + guard(serial8250_rpm)(p); 1327 + guard(uart_port_lock_irqsave)(&p->port); 1328 + 1323 1329 if (em485->active_timer == &em485->stop_tx_timer) { 1324 1330 p->rs485_stop_tx(p, true); 1325 1331 em485->active_timer = NULL; 1326 1332 em485->tx_stopped = true; 1327 1333 } 1328 - uart_port_unlock_irqrestore(&p->port, flags); 1329 - serial8250_rpm_put(p); 1330 1334 1331 1335 return HRTIMER_NORESTART; 1332 1336 } ··· 1399 1407 { 1400 1408 struct uart_8250_port *up = up_to_u8250p(port); 1401 1409 1402 - serial8250_rpm_get(up); 1410 + guard(serial8250_rpm)(up); 1403 1411 __stop_tx(up); 1404 1412 1405 1413 /* ··· 1409 1417 up->acr |= UART_ACR_TXDIS; 1410 1418 serial_icr_write(up, UART_ACR, up->acr); 1411 1419 } 1412 - serial8250_rpm_put(up); 1413 1420 } 1414 1421 1415 1422 static inline void __start_tx(struct uart_port *port) ··· 1503 1512 struct uart_8250_em485 *em485 = container_of(t, struct uart_8250_em485, 1504 1513 start_tx_timer); 1505 1514 struct uart_8250_port *p = em485->port; 1506 - unsigned long flags; 1507 1515 1508 - uart_port_lock_irqsave(&p->port, &flags); 1516 + guard(uart_port_lock_irqsave)(&p->port); 1517 + 1509 1518 if (em485->active_timer == &em485->start_tx_timer) { 1510 1519 __start_tx(&p->port); 1511 1520 em485->active_timer = NULL; 1512 1521 } 1513 - uart_port_unlock_irqrestore(&p->port, flags); 1514 1522 1515 1523 return HRTIMER_NORESTART; 1516 1524 } ··· 1577 1587 1578 1588 up->ier |= UART_IER_MSI; 1579 1589 1580 - serial8250_rpm_get(up); 1590 + guard(serial8250_rpm)(up); 1581 1591 serial_port_out(port, UART_IER, up->ier); 1582 - serial8250_rpm_put(up); 1583 1592 } 1584 1593 1585 1594 void serial8250_read_char(struct uart_8250_port *up, u16 lsr) ··· 1839 1850 { 1840 1851 struct uart_8250_port *up = up_to_u8250p(port); 1841 1852 unsigned int iir; 1842 - int ret; 1843 1853 1844 - serial8250_rpm_get(up); 1854 + guard(serial8250_rpm)(up); 1845 1855 1846 1856 iir = serial_port_in(port, UART_IIR); 1847 - ret = serial8250_handle_irq(port, iir); 1848 - 1849 - serial8250_rpm_put(up); 1850 - return ret; 1857 + return serial8250_handle_irq(port, iir); 1851 1858 } 1852 1859 1853 1860 /* ··· 1854 1869 */ 1855 1870 static int serial8250_tx_threshold_handle_irq(struct uart_port *port) 1856 1871 { 1857 - unsigned long flags; 1858 1872 unsigned int iir = serial_port_in(port, UART_IIR); 1859 1873 1860 1874 /* TX Threshold IRQ triggered so load up FIFO */ 1861 1875 if ((iir & UART_IIR_ID) == UART_IIR_THRI) { 1862 1876 struct uart_8250_port *up = up_to_u8250p(port); 1863 1877 1864 - uart_port_lock_irqsave(port, &flags); 1878 + guard(uart_port_lock_irqsave)(port); 1865 1879 serial8250_tx_chars(up); 1866 - uart_port_unlock_irqrestore(port, flags); 1867 1880 } 1868 1881 1869 1882 iir = serial_port_in(port, UART_IIR); ··· 1871 1888 static unsigned int serial8250_tx_empty(struct uart_port *port) 1872 1889 { 1873 1890 struct uart_8250_port *up = up_to_u8250p(port); 1874 - unsigned int result = 0; 1875 - unsigned long flags; 1876 1891 1877 - serial8250_rpm_get(up); 1892 + guard(serial8250_rpm)(up); 1893 + guard(uart_port_lock_irqsave)(port); 1878 1894 1879 - uart_port_lock_irqsave(port, &flags); 1880 1895 if (!serial8250_tx_dma_running(up) && uart_lsr_tx_empty(serial_lsr_in(up))) 1881 - result = TIOCSER_TEMT; 1882 - uart_port_unlock_irqrestore(port, flags); 1896 + return TIOCSER_TEMT; 1883 1897 1884 - serial8250_rpm_put(up); 1885 - 1886 - return result; 1898 + return 0; 1887 1899 } 1888 1900 1889 1901 unsigned int serial8250_do_get_mctrl(struct uart_port *port) ··· 1887 1909 unsigned int status; 1888 1910 unsigned int val; 1889 1911 1890 - serial8250_rpm_get(up); 1891 - status = serial8250_modem_status(up); 1892 - serial8250_rpm_put(up); 1912 + scoped_guard(serial8250_rpm, up) 1913 + status = serial8250_modem_status(up); 1893 1914 1894 1915 val = serial8250_MSR_to_TIOCM(status); 1895 1916 if (up->gpios) ··· 1932 1955 static void serial8250_break_ctl(struct uart_port *port, int break_state) 1933 1956 { 1934 1957 struct uart_8250_port *up = up_to_u8250p(port); 1935 - unsigned long flags; 1936 1958 1937 - serial8250_rpm_get(up); 1938 - uart_port_lock_irqsave(port, &flags); 1959 + guard(serial8250_rpm)(up); 1960 + guard(uart_port_lock_irqsave)(port); 1961 + 1939 1962 if (break_state == -1) 1940 1963 up->lcr |= UART_LCR_SBC; 1941 1964 else 1942 1965 up->lcr &= ~UART_LCR_SBC; 1943 1966 serial_port_out(port, UART_LCR, up->lcr); 1944 - uart_port_unlock_irqrestore(port, flags); 1945 - serial8250_rpm_put(up); 1946 1967 } 1947 1968 1948 1969 /* Returns true if @bits were set, false on timeout */ ··· 2000 2025 static int serial8250_get_poll_char(struct uart_port *port) 2001 2026 { 2002 2027 struct uart_8250_port *up = up_to_u8250p(port); 2003 - int status; 2004 2028 u16 lsr; 2005 2029 2006 - serial8250_rpm_get(up); 2030 + guard(serial8250_rpm)(up); 2007 2031 2008 2032 lsr = serial_port_in(port, UART_LSR); 2033 + if (!(lsr & UART_LSR_DR)) 2034 + return NO_POLL_CHAR; 2009 2035 2010 - if (!(lsr & UART_LSR_DR)) { 2011 - status = NO_POLL_CHAR; 2012 - goto out; 2013 - } 2014 - 2015 - status = serial_port_in(port, UART_RX); 2016 - out: 2017 - serial8250_rpm_put(up); 2018 - return status; 2036 + return serial_port_in(port, UART_RX); 2019 2037 } 2020 2038 2021 2039 ··· 2026 2058 * should allow safe lockless usage here. 2027 2059 */ 2028 2060 2029 - serial8250_rpm_get(up); 2061 + guard(serial8250_rpm)(up); 2030 2062 /* 2031 2063 * First save the IER then disable the interrupts 2032 2064 */ ··· 2045 2077 */ 2046 2078 wait_for_xmitr(up, UART_LSR_BOTH_EMPTY); 2047 2079 serial_port_out(port, UART_IER, ier); 2048 - serial8250_rpm_put(up); 2049 2080 } 2050 2081 2051 2082 #endif /* CONFIG_CONSOLE_POLL */ ··· 2052 2085 static void serial8250_startup_special(struct uart_port *port) 2053 2086 { 2054 2087 struct uart_8250_port *up = up_to_u8250p(port); 2055 - unsigned long flags; 2056 2088 2057 2089 switch (port->type) { 2058 - case PORT_16C950: 2090 + case PORT_16C950: { 2059 2091 /* 2060 2092 * Wake up and initialize UART 2061 2093 * 2062 2094 * Synchronize UART_IER access against the console. 2063 2095 */ 2064 - uart_port_lock_irqsave(port, &flags); 2096 + guard(uart_port_lock_irqsave)(port); 2065 2097 up->acr = 0; 2066 2098 serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 2067 2099 serial_port_out(port, UART_EFR, UART_EFR_ECB); ··· 2070 2104 serial_port_out(port, UART_LCR, UART_LCR_CONF_MODE_B); 2071 2105 serial_port_out(port, UART_EFR, UART_EFR_ECB); 2072 2106 serial_port_out(port, UART_LCR, 0); 2073 - uart_port_unlock_irqrestore(port, flags); 2074 2107 break; 2108 + } 2075 2109 case PORT_DA830: 2076 2110 /* 2077 2111 * Reset the port 2078 2112 * 2079 2113 * Synchronize UART_IER access against the console. 2080 2114 */ 2081 - uart_port_lock_irqsave(port, &flags); 2082 - serial_port_out(port, UART_IER, 0); 2083 - serial_port_out(port, UART_DA830_PWREMU_MGMT, 0); 2084 - uart_port_unlock_irqrestore(port, flags); 2115 + scoped_guard(uart_port_lock_irqsave, port) { 2116 + serial_port_out(port, UART_IER, 0); 2117 + serial_port_out(port, UART_DA830_PWREMU_MGMT, 0); 2118 + } 2085 2119 mdelay(10); 2086 2120 2087 2121 /* Enable Tx, Rx and free run mode */ ··· 2139 2173 static void serial8250_THRE_test(struct uart_port *port) 2140 2174 { 2141 2175 struct uart_8250_port *up = up_to_u8250p(port); 2142 - unsigned long flags; 2143 2176 bool iir_noint1, iir_noint2; 2144 2177 2145 2178 if (!port->irq) ··· 2158 2193 * 2159 2194 * Synchronize UART_IER access against the console. 2160 2195 */ 2161 - uart_port_lock_irqsave(port, &flags); 2162 - 2163 - wait_for_xmitr(up, UART_LSR_THRE); 2164 - serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2165 - udelay(1); /* allow THRE to set */ 2166 - iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT; 2167 - serial_port_out(port, UART_IER, 0); 2168 - serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2169 - udelay(1); /* allow a working UART time to re-assert THRE */ 2170 - iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT; 2171 - serial_port_out(port, UART_IER, 0); 2172 - 2173 - uart_port_unlock_irqrestore(port, flags); 2196 + scoped_guard(uart_port_lock_irqsave, port) { 2197 + wait_for_xmitr(up, UART_LSR_THRE); 2198 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2199 + udelay(1); /* allow THRE to set */ 2200 + iir_noint1 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT; 2201 + serial_port_out(port, UART_IER, 0); 2202 + serial_port_out_sync(port, UART_IER, UART_IER_THRI); 2203 + udelay(1); /* allow a working UART time to re-assert THRE */ 2204 + iir_noint2 = serial_port_in(port, UART_IIR) & UART_IIR_NO_INT; 2205 + serial_port_out(port, UART_IER, 0); 2206 + } 2174 2207 2175 2208 if (port->irqflags & IRQF_SHARED) 2176 2209 enable_irq(port->irq); ··· 2232 2269 2233 2270 static void serial8250_initialize(struct uart_port *port) 2234 2271 { 2235 - unsigned long flags; 2236 - 2237 - uart_port_lock_irqsave(port, &flags); 2272 + guard(uart_port_lock_irqsave)(port); 2238 2273 serial_port_out(port, UART_LCR, UART_LCR_WLEN8); 2239 2274 2240 2275 serial8250_init_mctrl(port); 2241 2276 serial8250_iir_txen_test(port); 2242 - uart_port_unlock_irqrestore(port, flags); 2243 2277 } 2244 2278 2245 2279 int serial8250_do_startup(struct uart_port *port) ··· 2255 2295 if (port->iotype != up->cur_iotype) 2256 2296 set_io_from_upio(port); 2257 2297 2258 - serial8250_rpm_get(up); 2298 + guard(serial8250_rpm)(up); 2259 2299 2260 2300 serial8250_startup_special(port); 2261 2301 ··· 2275 2315 if (!(port->flags & UPF_BUGGY_UART) && 2276 2316 (serial_port_in(port, UART_LSR) == 0xff)) { 2277 2317 dev_info_ratelimited(port->dev, "LSR safety check engaged!\n"); 2278 - retval = -ENODEV; 2279 - goto out; 2318 + return -ENODEV; 2280 2319 } 2281 2320 2282 2321 serial8250_set_TRG_levels(port); ··· 2286 2327 2287 2328 retval = up->ops->setup_irq(up); 2288 2329 if (retval) 2289 - goto out; 2330 + return retval; 2290 2331 2291 2332 serial8250_THRE_test(port); 2292 2333 ··· 2335 2376 outb_p(0x80, icp); 2336 2377 inb_p(icp); 2337 2378 } 2338 - retval = 0; 2339 - out: 2340 - serial8250_rpm_put(up); 2341 - return retval; 2379 + 2380 + return 0; 2342 2381 } 2343 2382 EXPORT_SYMBOL_GPL(serial8250_do_startup); 2344 2383 ··· 2350 2393 void serial8250_do_shutdown(struct uart_port *port) 2351 2394 { 2352 2395 struct uart_8250_port *up = up_to_u8250p(port); 2353 - unsigned long flags; 2354 2396 2355 2397 serial8250_rpm_get(up); 2356 2398 /* ··· 2357 2401 * 2358 2402 * Synchronize UART_IER access against the console. 2359 2403 */ 2360 - uart_port_lock_irqsave(port, &flags); 2361 - up->ier = 0; 2362 - serial_port_out(port, UART_IER, 0); 2363 - uart_port_unlock_irqrestore(port, flags); 2404 + scoped_guard(uart_port_lock_irqsave, port) { 2405 + up->ier = 0; 2406 + serial_port_out(port, UART_IER, 0); 2407 + } 2364 2408 2365 2409 synchronize_irq(port->irq); 2366 2410 2367 2411 if (up->dma) 2368 2412 serial8250_release_dma(up); 2369 2413 2370 - uart_port_lock_irqsave(port, &flags); 2371 - if (port->flags & UPF_FOURPORT) { 2372 - /* reset interrupts on the AST Fourport board */ 2373 - inb((port->iobase & 0xfe0) | 0x1f); 2374 - port->mctrl |= TIOCM_OUT1; 2375 - } else 2376 - port->mctrl &= ~TIOCM_OUT2; 2414 + scoped_guard(uart_port_lock_irqsave, port) { 2415 + if (port->flags & UPF_FOURPORT) { 2416 + /* reset interrupts on the AST Fourport board */ 2417 + inb((port->iobase & 0xfe0) | 0x1f); 2418 + port->mctrl |= TIOCM_OUT1; 2419 + } else 2420 + port->mctrl &= ~TIOCM_OUT2; 2377 2421 2378 - serial8250_set_mctrl(port, port->mctrl); 2379 - uart_port_unlock_irqrestore(port, flags); 2422 + serial8250_set_mctrl(port, port->mctrl); 2423 + } 2380 2424 2381 2425 /* 2382 2426 * Disable break condition and FIFOs ··· 2568 2612 void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk) 2569 2613 { 2570 2614 struct tty_port *tport = &port->state->port; 2571 - struct tty_struct *tty; 2572 2615 2573 - tty = tty_port_tty_get(tport); 2574 - if (!tty) { 2575 - mutex_lock(&tport->mutex); 2616 + scoped_guard(tty_port_tty, tport) { 2617 + struct tty_struct *tty = scoped_tty(); 2618 + 2619 + guard(rwsem_write)(&tty->termios_rwsem); 2620 + guard(mutex)(&tport->mutex); 2621 + 2622 + if (port->uartclk == uartclk) 2623 + return; 2624 + 2576 2625 port->uartclk = uartclk; 2577 - mutex_unlock(&tport->mutex); 2626 + 2627 + if (!tty_port_initialized(tport)) 2628 + return; 2629 + 2630 + serial8250_do_set_termios(port, &tty->termios, NULL); 2631 + 2578 2632 return; 2579 2633 } 2580 - 2581 - down_write(&tty->termios_rwsem); 2582 - mutex_lock(&tport->mutex); 2583 - 2584 - if (port->uartclk == uartclk) 2585 - goto out_unlock; 2586 - 2634 + guard(mutex)(&tport->mutex); 2587 2635 port->uartclk = uartclk; 2588 - 2589 - if (!tty_port_initialized(tport)) 2590 - goto out_unlock; 2591 - 2592 - serial8250_do_set_termios(port, &tty->termios, NULL); 2593 - 2594 - out_unlock: 2595 - mutex_unlock(&tport->mutex); 2596 - up_write(&tty->termios_rwsem); 2597 - tty_kref_put(tty); 2598 2636 } 2599 2637 EXPORT_SYMBOL_GPL(serial8250_update_uartclk); 2600 2638 ··· 2743 2793 const struct ktermios *old) 2744 2794 { 2745 2795 struct uart_8250_port *up = up_to_u8250p(port); 2746 - unsigned long flags; 2747 2796 unsigned int baud, quot, frac = 0; 2748 2797 u8 lcr; 2749 2798 ··· 2752 2803 quot = serial8250_get_divisor(port, baud, &frac); 2753 2804 2754 2805 /* 2755 - * Ok, we're now changing the port state. Do it with 2756 - * interrupts disabled. 2806 + * Ok, we're now changing the port state. Do it with interrupts disabled. 2757 2807 * 2758 2808 * Synchronize UART_IER access against the console. 2759 2809 */ 2760 - serial8250_rpm_get(up); 2761 - uart_port_lock_irqsave(port, &flags); 2810 + scoped_guard(serial8250_rpm, up) { 2811 + guard(uart_port_lock_irqsave)(port); 2762 2812 2763 - up->lcr = lcr; 2764 - serial8250_set_trigger_for_slow_speed(port, termios, baud); 2765 - serial8250_set_afe(port, termios); 2766 - uart_update_timeout(port, termios->c_cflag, baud); 2767 - serial8250_set_errors_and_ignores(port, termios); 2768 - serial8250_set_ier(port, termios); 2769 - serial8250_set_efr(port, termios); 2770 - serial8250_set_divisor(port, baud, quot, frac); 2771 - serial8250_set_fcr(port, termios); 2772 - serial8250_set_mctrl(port, port->mctrl); 2773 - 2774 - uart_port_unlock_irqrestore(port, flags); 2775 - serial8250_rpm_put(up); 2813 + up->lcr = lcr; 2814 + serial8250_set_trigger_for_slow_speed(port, termios, baud); 2815 + serial8250_set_afe(port, termios); 2816 + uart_update_timeout(port, termios->c_cflag, baud); 2817 + serial8250_set_errors_and_ignores(port, termios); 2818 + serial8250_set_ier(port, termios); 2819 + serial8250_set_efr(port, termios); 2820 + serial8250_set_divisor(port, baud, quot, frac); 2821 + serial8250_set_fcr(port, termios); 2822 + serial8250_set_mctrl(port, port->mctrl); 2823 + } 2776 2824 2777 2825 /* Don't rewrite B0 */ 2778 2826 if (tty_termios_baud_rate(termios)) ··· 2791 2845 { 2792 2846 if (termios->c_line == N_PPS) { 2793 2847 port->flags |= UPF_HARDPPS_CD; 2794 - uart_port_lock_irq(port); 2848 + guard(uart_port_lock_irq)(port); 2795 2849 serial8250_enable_ms(port); 2796 - uart_port_unlock_irq(port); 2797 2850 } else { 2798 2851 port->flags &= ~UPF_HARDPPS_CD; 2799 2852 if (!UART_ENABLE_MS(port, termios->c_cflag)) { 2800 - uart_port_lock_irq(port); 2853 + guard(uart_port_lock_irq)(port); 2801 2854 serial8250_disable_ms(port); 2802 - uart_port_unlock_irq(port); 2803 2855 } 2804 2856 } 2805 2857 }