usb: serial: replacing mutex_lock to guard(mutex)
Subsystems (2)
PATCH 1/1 usb: serial: replacing mutex_lock to guard(mutex)
Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in ark3116.c file.
--- drivers/usb/serial/ark3116.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/usb/serial/ark3116.c +4 -11
@@ -237,7 +237,7 @@ static void ark3116_set_termios(struct tty_struct *tty, }/* Update state: synchronize */ -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock);/* keep old LCR_SBC bit */ lcr |= (priv->lcr &UART_LCR_SBC );
@@ -280,8 +280,6 @@ static void ark3116_set_termios(struct tty_struct *tty,ark3116_write_reg (serial,UART_LCR , lcr); } -mutex_unlock (&priv->hw_lock); -/* check for software flow control */ if (I_IXOFF (tty) ||I_IXON (tty)) { dev_warn(&port->dev,
@@ -379,9 +377,8 @@ static int ark3116_tiocmget(struct tty_struct *tty)__u32 ctrl;unsigned long flags; -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock); ctrl = priv->mcr; -mutex_unlock (&priv->hw_lock);spin_lock_irqsave (&priv->status_lock, flags); status = priv->msr;
@@ -407,7 +404,7 @@ static int ark3116_tiocmset(struct tty_struct *tty,* in priv->mcr is actually the one that is in the hardware */ -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock);if (set &TIOCM_RTS ) priv->mcr |=UART_MCR_RTS ;
@@ -428,8 +425,6 @@ static int ark3116_tiocmset(struct tty_struct *tty,ark3116_write_reg (port->serial,UART_MCR , priv->mcr); -mutex_unlock (&priv->hw_lock); -return 0 ; }
@@ -440,7 +435,7 @@ static int ark3116_break_ctl(struct tty_struct *tty, int break_state)int ret;/* LCR is also used for other things: protect access */ -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock);if (break_state) priv->lcr |=UART_LCR_SBC ;
@@ -449,8 +444,6 @@ static int ark3116_break_ctl(struct tty_struct *tty, int break_state) ret =ark3116_write_reg (port->serial,UART_LCR , priv->lcr); -mutex_unlock (&priv->hw_lock); -return ret; }
Signature · 1 line
2.54.0
Greg Kroah-Hartman
maintainerQuoted 2 lines · Leonid Konontsov
Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in
ark3116.cfile.
That says what you are doing, but not why.
Please don't change code to use guard() unless you are fixing a bug. Otherwise the churn in the kernel would not be worth it. Just use it in new code please.
thanks,
greg k-h
Greg Kroah-Hartman
maintainerQuoted 31 lines · Leonid Konontsov
Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in
ark3116.cfile.Signed-off-by Leonid Konontsov <[email protected]>--- drivers/usb/serial/ark3116.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)drivers/usb/serial/ark3116.c +1
-3@@ -237,7 +237,7 @@ static void ark3116_set_termios(struct tty_struct *tty, }/* Update state: synchronize */ -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock);/* keep old LCR_SBC bit */ lcr |= (priv->lcr &UART_LCR_SBC );@@ -280,8 +280,6 @@ static void ark3116_set_termios(struct tty_struct *tty,ark3116_write_reg (serial,UART_LCR , lcr); } -mutex_unlock (&priv->hw_lock); -/* check for software flow control */ if (I_IXOFF (tty) ||I_IXON (tty)) { dev_warn(&port->dev,
drivers/usb/serial/ark3116.c static int ark3116_tiocmget(struct tty_struct *tty) · line 384
Quoted 7 lines
drivers/usb/serial/ark3116.c +1
-2@@ -379,9 +377,8 @@ static int ark3116_tiocmget(struct tty_struct *tty)__u32 ctrl;unsigned long flags; -mutex_lock (&priv->hw_lock); +guard (mutex)(&priv->hw_lock); ctrl = priv->mcr; -mutex_unlock (&priv->hw_lock);
As "proof" you shouldn't be doing this, you just changed the logic here and might have broken the driver :(
Did you test this change?
thanks,
greg k-h