diff mbox series

usb: cdc-acm: move ldisc dcd notification outside of acm's read lock

Message ID ZN1zV/zjPgpGlHXo@vps3.drown.org (mailing list archive)
State Accepted
Commit f72ae60881ff685004d7de7152517607fcd9968f
Headers show
Series usb: cdc-acm: move ldisc dcd notification outside of acm's read lock | expand

Commit Message

Dan Drown Aug. 17, 2023, 1:09 a.m. UTC
dcd_change notification call moved outside of the acm->read_lock
to protect any future tty ldisc that calls wait_serial_change()

Signed-off-by: Dan Drown <dan-netdev@drown.org>
---
 drivers/usb/class/cdc-acm.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

Comments

Oliver Neukum Aug. 17, 2023, 8:19 a.m. UTC | #1
On 17.08.23 03:09, Dan Drown wrote:
> dcd_change notification call moved outside of the acm->read_lock
> to protect any future tty ldisc that calls wait_serial_change()
> 
> Signed-off-by: Dan Drown <dan-netdev@drown.org>
Acked-by: Oliver Neukum <oneukum@suse.com>
diff mbox series

Patch

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 9b34199474c4..dfb28c7c3069 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -319,23 +319,24 @@  static void acm_process_notification(struct acm *acm, unsigned char *buf)
 		}
 
 		difference = acm->ctrlin ^ newctrl;
+
+		if ((difference & USB_CDC_SERIAL_STATE_DCD) && acm->port.tty) {
+			struct tty_ldisc *ld = tty_ldisc_ref(acm->port.tty);
+			if (ld) {
+				if (ld->ops->dcd_change)
+					ld->ops->dcd_change(acm->port.tty, newctrl & USB_CDC_SERIAL_STATE_DCD);
+				tty_ldisc_deref(ld);
+			}
+		}
+
 		spin_lock_irqsave(&acm->read_lock, flags);
 		acm->ctrlin = newctrl;
 		acm->oldcount = acm->iocount;
 
 		if (difference & USB_CDC_SERIAL_STATE_DSR)
 			acm->iocount.dsr++;
-		if (difference & USB_CDC_SERIAL_STATE_DCD) {
-			if (acm->port.tty) {
-				struct tty_ldisc *ld = tty_ldisc_ref(acm->port.tty);
-				if (ld) {
-					if (ld->ops->dcd_change)
-						ld->ops->dcd_change(acm->port.tty, newctrl & USB_CDC_SERIAL_STATE_DCD);
-					tty_ldisc_deref(ld);
-				}
-			}
+		if (difference & USB_CDC_SERIAL_STATE_DCD)
 			acm->iocount.dcd++;
-		}
 		if (newctrl & USB_CDC_SERIAL_STATE_BREAK) {
 			acm->iocount.brk++;
 			tty_insert_flip_char(&acm->port, 0, TTY_BREAK);