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

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

For this to work, UART_CAP_RPM has to be set to up->capabilities a bit
earlier.

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

authored by

Jiri Slaby (SUSE) and committed by
Greg Kroah-Hartman
7345b07f 302c8145

+38 -72
+38 -72
drivers/tty/serial/8250/8250_omap.c
··· 393 393 * Ok, we're now changing the port state. Do it with 394 394 * interrupts disabled. 395 395 */ 396 - pm_runtime_get_sync(port->dev); 397 - uart_port_lock_irq(port); 396 + guard(serial8250_rpm)(up); 397 + guard(uart_port_lock_irq)(port); 398 398 399 399 /* 400 400 * Update the per-port timeout. ··· 502 502 } 503 503 } 504 504 omap8250_restore_regs(up); 505 - 506 - uart_port_unlock_irq(&up->port); 507 - pm_runtime_mark_last_busy(port->dev); 508 - pm_runtime_put_autosuspend(port->dev); 509 505 } 510 506 511 507 /* ··· 542 546 struct uart_8250_port *up = up_to_u8250p(port); 543 547 u8 efr; 544 548 545 - pm_runtime_get_sync(port->dev); 546 - 549 + guard(serial8250_rpm)(up); 547 550 /* Synchronize UART_IER access against the console. */ 548 - uart_port_lock_irq(port); 551 + guard(uart_port_lock_irq)(port); 549 552 550 553 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 551 554 efr = serial_in(up, UART_EFR); ··· 555 560 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); 556 561 serial_out(up, UART_EFR, efr); 557 562 serial_out(up, UART_LCR, 0); 558 - 559 - uart_port_unlock_irq(port); 560 - 561 - pm_runtime_mark_last_busy(port->dev); 562 - pm_runtime_put_autosuspend(port->dev); 563 563 } 564 564 565 565 static void omap_serial_fill_features_erratas(struct uart_8250_port *up, ··· 726 736 return ret; 727 737 } 728 738 729 - pm_runtime_get_sync(port->dev); 739 + #ifdef CONFIG_PM 740 + up->capabilities |= UART_CAP_RPM; 741 + #endif 742 + 743 + guard(serial8250_rpm)(up); 730 744 731 745 serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 732 746 ··· 753 759 } 754 760 755 761 /* Synchronize UART_IER access against the console. */ 756 - uart_port_lock_irq(port); 757 - up->ier = UART_IER_RLSI | UART_IER_RDI; 758 - serial_out(up, UART_IER, up->ier); 759 - uart_port_unlock_irq(port); 760 - 761 - #ifdef CONFIG_PM 762 - up->capabilities |= UART_CAP_RPM; 763 - #endif 762 + scoped_guard(uart_port_lock_irq, port) { 763 + up->ier = UART_IER_RLSI | UART_IER_RDI; 764 + serial_out(up, UART_IER, up->ier); 765 + } 764 766 765 767 /* Enable module level wake up */ 766 768 priv->wer = OMAP_UART_WER_MOD_WKUP; ··· 765 775 serial_out(up, UART_OMAP_WER, priv->wer); 766 776 767 777 if (up->dma && !(priv->habit & UART_HAS_EFR2)) { 768 - uart_port_lock_irq(port); 778 + guard(uart_port_lock_irq)(port); 769 779 up->dma->rx_dma(up); 770 - uart_port_unlock_irq(port); 771 780 } 772 781 773 782 enable_irq(port->irq); 774 783 775 - pm_runtime_mark_last_busy(port->dev); 776 - pm_runtime_put_autosuspend(port->dev); 777 784 return 0; 778 785 } 779 786 ··· 779 792 struct uart_8250_port *up = up_to_u8250p(port); 780 793 struct omap8250_priv *priv = port->private_data; 781 794 782 - pm_runtime_get_sync(port->dev); 795 + guard(serial8250_rpm)(up); 783 796 784 797 flush_work(&priv->qos_work); 785 798 if (up->dma) ··· 790 803 serial_out(up, UART_OMAP_EFR2, 0x0); 791 804 792 805 /* Synchronize UART_IER access against the console. */ 793 - uart_port_lock_irq(port); 794 - up->ier = 0; 795 - serial_out(up, UART_IER, 0); 796 - uart_port_unlock_irq(port); 806 + scoped_guard(uart_port_lock_irq, port) { 807 + up->ier = 0; 808 + serial_out(up, UART_IER, 0); 809 + } 810 + 797 811 disable_irq_nosync(port->irq); 798 812 dev_pm_clear_wake_irq(port->dev); 799 813 ··· 807 819 if (up->lcr & UART_LCR_SBC) 808 820 serial_out(up, UART_LCR, up->lcr & ~UART_LCR_SBC); 809 821 serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 810 - 811 - pm_runtime_mark_last_busy(port->dev); 812 - pm_runtime_put_autosuspend(port->dev); 813 822 } 814 823 815 824 static void omap_8250_throttle(struct uart_port *port) 816 825 { 817 826 struct omap8250_priv *priv = port->private_data; 818 - unsigned long flags; 819 827 820 - pm_runtime_get_sync(port->dev); 828 + guard(serial8250_rpm)(up_to_u8250p(port)); 829 + guard(uart_port_lock_irqsave)(port); 821 830 822 - uart_port_lock_irqsave(port, &flags); 823 831 port->ops->stop_rx(port); 824 832 priv->throttled = true; 825 - uart_port_unlock_irqrestore(port, flags); 826 - 827 - pm_runtime_mark_last_busy(port->dev); 828 - pm_runtime_put_autosuspend(port->dev); 829 833 } 830 834 831 835 static void omap_8250_unthrottle(struct uart_port *port) 832 836 { 833 837 struct omap8250_priv *priv = port->private_data; 834 838 struct uart_8250_port *up = up_to_u8250p(port); 835 - unsigned long flags; 836 839 837 - pm_runtime_get_sync(port->dev); 838 - 840 + guard(serial8250_rpm)(up); 839 841 /* Synchronize UART_IER access against the console. */ 840 - uart_port_lock_irqsave(port, &flags); 842 + guard(uart_port_lock_irqsave)(port); 843 + 841 844 priv->throttled = false; 842 845 if (up->dma) 843 846 up->dma->rx_dma(up); 844 847 up->ier |= UART_IER_RLSI | UART_IER_RDI; 845 848 serial_out(up, UART_IER, up->ier); 846 - uart_port_unlock_irqrestore(port, flags); 847 - 848 - pm_runtime_mark_last_busy(port->dev); 849 - pm_runtime_put_autosuspend(port->dev); 850 849 } 851 850 852 851 static int omap8250_rs485_config(struct uart_port *port, ··· 971 996 struct omap8250_priv *priv = p->port.private_data; 972 997 struct uart_8250_dma *dma = p->dma; 973 998 struct dma_tx_state state; 974 - unsigned long flags; 975 999 976 1000 /* Synchronize UART_IER access against the console. */ 977 - uart_port_lock_irqsave(&p->port, &flags); 1001 + guard(uart_port_lock_irqsave)(&p->port); 978 1002 979 1003 /* 980 1004 * If the tx status is not DMA_COMPLETE, then this is a delayed 981 1005 * completion callback. A previous RX timeout flush would have 982 1006 * already pushed the data, so exit. 983 1007 */ 984 - if (dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state) != 985 - DMA_COMPLETE) { 986 - uart_port_unlock_irqrestore(&p->port, flags); 1008 + if (dmaengine_tx_status(dma->rxchan, dma->rx_cookie, &state) != DMA_COMPLETE) 987 1009 return; 988 - } 989 - __dma_rx_do_complete(p); 990 - if (!priv->throttled) { 991 - p->ier |= UART_IER_RLSI | UART_IER_RDI; 992 - serial_out(p, UART_IER, p->ier); 993 - if (!(priv->habit & UART_HAS_EFR2)) 994 - omap_8250_rx_dma(p); 995 - } 996 1010 997 - uart_port_unlock_irqrestore(&p->port, flags); 1011 + __dma_rx_do_complete(p); 1012 + if (priv->throttled) 1013 + return; 1014 + 1015 + p->ier |= UART_IER_RLSI | UART_IER_RDI; 1016 + serial_out(p, UART_IER, p->ier); 1017 + if (!(priv->habit & UART_HAS_EFR2)) 1018 + omap_8250_rx_dma(p); 998 1019 } 999 1020 1000 1021 static void omap_8250_rx_dma_flush(struct uart_8250_port *p) ··· 1088 1117 struct uart_8250_port *p = param; 1089 1118 struct uart_8250_dma *dma = p->dma; 1090 1119 struct tty_port *tport = &p->port.state->port; 1091 - unsigned long flags; 1092 1120 bool en_thri = false; 1093 1121 struct omap8250_priv *priv = p->port.private_data; 1094 1122 1095 1123 dma_sync_single_for_cpu(dma->txchan->device->dev, dma->tx_addr, 1096 1124 UART_XMIT_SIZE, DMA_TO_DEVICE); 1097 1125 1098 - uart_port_lock_irqsave(&p->port, &flags); 1126 + guard(uart_port_lock_irqsave)(&p->port); 1099 1127 1100 1128 dma->tx_running = 0; 1101 1129 ··· 1122 1152 dma->tx_err = 1; 1123 1153 serial8250_set_THRI(p); 1124 1154 } 1125 - 1126 - uart_port_unlock_irqrestore(&p->port, flags); 1127 1155 } 1128 1156 1129 1157 static int omap_8250_tx_dma(struct uart_8250_port *p) ··· 1772 1804 up = serial8250_get_port(priv->line); 1773 1805 1774 1806 if (up && omap8250_lost_context(up)) { 1775 - uart_port_lock_irq(&up->port); 1807 + guard(uart_port_lock_irq)(&up->port); 1776 1808 omap8250_restore_regs(up); 1777 - uart_port_unlock_irq(&up->port); 1778 1809 } 1779 1810 1780 1811 if (up && up->dma && up->dma->rxchan && !(priv->habit & UART_HAS_EFR2)) { 1781 - uart_port_lock_irq(&up->port); 1812 + guard(uart_port_lock_irq)(&up->port); 1782 1813 omap_8250_rx_dma(up); 1783 - uart_port_unlock_irq(&up->port); 1784 1814 } 1785 1815 1786 1816 atomic_set(&priv->active, 1);