All of
 help / color / mirror / Atom feed
From: Johan Hovold <>
To: Oliver Neukum <>,
	Greg Kroah-Hartman <>
	Johan Hovold <>,
Subject: [PATCH 1/2] USB: cdc-acm: fix racy tty buffer accesses
Date: Wed, 29 Sep 2021 11:09:36 +0200	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

A recent change that started reporting break events to the line
discipline caused the tty-buffer insertions to no longer be serialised
by inserting events also from the completion handler for the interrupt

Completion calls for distinct endpoints are not guaranteed to be
serialised. For example, in case a host-controller driver uses
bottom-half completion, the interrupt and bulk-in completion handlers
can end up running in parallel on two CPUs (high-and low-prio tasklets,
respectively) thereby breaking the tty layer's single producer

Fix this by holding the read lock also when inserting characters from
the bulk endpoint.

Fixes: 08dff274edda ("cdc-acm: fix BREAK rx code path adding necessary calls")
Signed-off-by: Johan Hovold <>
 drivers/usb/class/cdc-acm.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 4e2f1552f4b7..c7a1736720e7 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -475,11 +475,16 @@ static int acm_submit_read_urbs(struct acm *acm, gfp_t mem_flags)
 static void acm_process_read_urb(struct acm *acm, struct urb *urb)
+	unsigned long flags;
 	if (!urb->actual_length)
+	spin_lock_irqsave(&acm->read_lock, flags);
 	tty_insert_flip_string(&acm->port, urb->transfer_buffer,
+	spin_unlock_irqrestore(&acm->read_lock, flags);

  reply	other threads:[~2021-09-29  9:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29  9:09 [PATCH 0/2] USB: cdc-acm: fix break reporting Johan Hovold
2021-09-29  9:09 ` Johan Hovold [this message]
2021-09-30  9:04   ` [PATCH 1/2] USB: cdc-acm: fix racy tty buffer accesses Oliver Neukum
2021-09-29  9:09 ` [PATCH 2/2] USB: cdc-acm: fix break reporting Johan Hovold
2021-09-30  9:05   ` Oliver Neukum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \ \ \ \ \ \ \ \
    --subject='Re: [PATCH 1/2] USB: cdc-acm: fix racy tty buffer accesses' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.