Linux USB
 help / color / mirror / Atom feed
* [PATCH] usb: serial: replacing mutex_lock to guard(mutex)
@ 2026-06-14 19:23 Leonid Konontsov
  2026-06-15  2:28 ` Greg Kroah-Hartman
  2026-06-15  2:29 ` Greg Kroah-Hartman
  0 siblings, 2 replies; 3+ messages in thread
From: Leonid Konontsov @ 2026-06-14 19:23 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, Leonid Konontsov

Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in
ark3116.c file.

Signed-off-by: Leonid Konontsov <lkonontsov@gmail.com>
---
 drivers/usb/serial/ark3116.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
index d974da43fba3..9cd8179de583 100644
--- a/drivers/usb/serial/ark3116.c
+++ b/drivers/usb/serial/ark3116.c
@@ -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;
 }
 
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: serial: replacing mutex_lock to guard(mutex)
  2026-06-14 19:23 [PATCH] usb: serial: replacing mutex_lock to guard(mutex) Leonid Konontsov
@ 2026-06-15  2:28 ` Greg Kroah-Hartman
  2026-06-15  2:29 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-06-15  2:28 UTC (permalink / raw)
  To: Leonid Konontsov; +Cc: Johan Hovold, linux-usb, linux-kernel

On Sun, Jun 14, 2026 at 10:23:37PM +0300, Leonid Konontsov wrote:
> Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in
> ark3116.c file.

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] usb: serial: replacing mutex_lock to guard(mutex)
  2026-06-14 19:23 [PATCH] usb: serial: replacing mutex_lock to guard(mutex) Leonid Konontsov
  2026-06-15  2:28 ` Greg Kroah-Hartman
@ 2026-06-15  2:29 ` Greg Kroah-Hartman
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-06-15  2:29 UTC (permalink / raw)
  To: Leonid Konontsov; +Cc: Johan Hovold, linux-usb, linux-kernel

On Sun, Jun 14, 2026 at 10:23:37PM +0300, Leonid Konontsov wrote:
> Moving from manual mutex_lock's and mutex_unlock's to guard(mutex) in
> ark3116.c file.
> 
> Signed-off-by: Leonid Konontsov <lkonontsov@gmail.com>
> ---
>  drivers/usb/serial/ark3116.c | 15 ++++-----------
>  1 file changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/usb/serial/ark3116.c b/drivers/usb/serial/ark3116.c
> index d974da43fba3..9cd8179de583 100644
> --- a/drivers/usb/serial/ark3116.c
> +++ b/drivers/usb/serial/ark3116.c
> @@ -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);

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-06-15  2:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-14 19:23 [PATCH] usb: serial: replacing mutex_lock to guard(mutex) Leonid Konontsov
2026-06-15  2:28 ` Greg Kroah-Hartman
2026-06-15  2:29 ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox