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: sc16is7xx: use guards for simple mutex locks

Guards can help to make the code more readable, so use them wherever they
do so.

In sc16is7xx_port_irq(), labels and 'rc' locals are eliminated completely.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://patch.msgid.link/20251027142957.1032073-6-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hugo Villeneuve and committed by
Greg Kroah-Hartman
0f4f88bf aed482b5

+8 -15
+8 -15
drivers/tty/serial/sc16is7xx.c
··· 11 11 #define DEFAULT_SYMBOL_NAMESPACE "SERIAL_NXP_SC16IS7XX" 12 12 13 13 #include <linux/bits.h> 14 + #include <linux/cleanup.h> 14 15 #include <linux/clk.h> 15 16 #include <linux/delay.h> 16 17 #include <linux/device.h> ··· 779 778 780 779 static bool sc16is7xx_port_irq(struct sc16is7xx_port *s, int portno) 781 780 { 782 - bool rc = true; 783 781 unsigned int iir, rxlen; 784 782 struct uart_port *port = &s->p[portno].port; 785 783 struct sc16is7xx_one *one = to_sc16is7xx_one(port, port); 786 784 787 - mutex_lock(&one->lock); 785 + guard(mutex)(&one->lock); 788 786 789 787 iir = sc16is7xx_port_read(port, SC16IS7XX_IIR_REG); 790 - if (iir & SC16IS7XX_IIR_NO_INT_BIT) { 791 - rc = false; 792 - goto out_port_irq; 793 - } 788 + if (iir & SC16IS7XX_IIR_NO_INT_BIT) 789 + return false; 794 790 795 791 iir &= SC16IS7XX_IIR_ID_MASK; 796 792 ··· 827 829 break; 828 830 } 829 831 830 - out_port_irq: 831 - mutex_unlock(&one->lock); 832 - 833 - return rc; 832 + return true; 834 833 } 835 834 836 835 static irqreturn_t sc16is7xx_irq(int irq, void *dev_id) ··· 868 873 (port->rs485.delay_rts_before_send > 0)) 869 874 msleep(port->rs485.delay_rts_before_send); 870 875 871 - mutex_lock(&one->lock); 876 + guard(mutex)(&one->lock); 872 877 sc16is7xx_handle_tx(port); 873 - mutex_unlock(&one->lock); 874 878 } 875 879 876 880 static void sc16is7xx_reconf_rs485(struct uart_port *port) ··· 936 942 struct sc16is7xx_port *s = dev_get_drvdata(one->port.dev); 937 943 938 944 if (one->port.state) { 939 - mutex_lock(&one->lock); 940 - sc16is7xx_update_mlines(one); 941 - mutex_unlock(&one->lock); 945 + scoped_guard(mutex, &one->lock) 946 + sc16is7xx_update_mlines(one); 942 947 943 948 kthread_queue_delayed_work(&s->kworker, &one->ms_work, HZ); 944 949 }