From patchwork Thu Aug 17 01:09:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Drown X-Patchwork-Id: 13355856 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C491C05052 for ; Thu, 17 Aug 2023 01:10:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347447AbjHQBKJ (ORCPT ); Wed, 16 Aug 2023 21:10:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347485AbjHQBJr (ORCPT ); Wed, 16 Aug 2023 21:09:47 -0400 Received: from vps3.drown.org (vps3.drown.org [96.126.122.39]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C521E19E for ; Wed, 16 Aug 2023 18:09:45 -0700 (PDT) X-Envelope-From: dan-netdev@drown.org Received: from vps3.drown.org (vps3.drown.org [IPv6:2600:3c00::f03c:91ff:fedf:5654]) by vps3.drown.org (Postfix) with ESMTPSA id A0E583A0591; Wed, 16 Aug 2023 20:09:44 -0500 (CDT) Date: Wed, 16 Aug 2023 20:09:43 -0500 From: Dan Drown To: Oliver Neukum , linux-usb@vger.kernel.org Subject: [PATCH] usb: cdc-acm: move ldisc dcd notification outside of acm's read lock Message-ID: References: <2e5758f57081786db37482a50bc0e58b@f9ae53fa8754> <1eb2b49d-52c9-c113-7c60-81634edfd646@suse.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1eb2b49d-52c9-c113-7c60-81634edfd646@suse.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 Acked-by: Oliver Neukum --- drivers/usb/class/cdc-acm.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) 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);