From patchwork Tue Nov 3 20:36:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 320483 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp4926521ilc; Tue, 3 Nov 2020 13:30:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwTdmc4qY6ChovWPkUE2kD4EMSZRP+IMWuxrkdiNI5UQFnoUyKzSC6Pu+EzrY6YiuOK8D49 X-Received: by 2002:a17:906:c298:: with SMTP id r24mr4141576ejz.38.1604439022678; Tue, 03 Nov 2020 13:30:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604439022; cv=none; d=google.com; s=arc-20160816; b=XJlD1lw6eSy12UdKbB5XhQ7wVJVmwMVedfFMbqrb7DokNyZJexaCodQLdMjGWxQvG2 xxusYdUy8k67bWFj7kbrHzsgu0s0ZM7Thq+TeTUSIPF+Qrd+YkxDWFvh7V3lAtRDmUv7 8ELImD3hbO8IYyc0TVbhBugc/W5mY1+TzoMqKWekVFbqG20vbC7hfu/4FKh+cYTIlYhm zpoqyOQlMWgUENtzSiPIC8P7jf8SCHITZYFbTl26ZY0tKJGvlr/D+HAC+WxuyJkNDgjV 0aSGLzh1jZeb08iFZEFi168I0eeCGUyp5c7uj1dd8obq5J4DTaNDGOuyeyer3NrCa7Kp i8eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cwwJosRvlx/tR9UeNxwVR+uGv76Teqc9D24ACth/v4k=; b=fvjjrhcX0UN0w0TRcdyqbzTl6Z2heIZk/cqJAbEFknPgpwj0MmgVDq3CuFspuA7WpO v2nUhaC25qtT40IqCvnuFQpxvyoC5iAONAHro9xgUbEk3lZtE/4lgSCLYpfKiHoITZpz ROpSJYVl6zzyBLZpUBHQx2lqJVR6XeHAqUG/rnmz+ZgMm7qkUrCXQNveW02LIHVzP3VA r2+pBFSY+C6X9eeSpuj2NUPlMWdmGGXpftiUY0ZHP2OvD7ZaqO7DmJ7t/cIjrOXJCXA1 7DlynObd00MVCKi2Wc9G096wO6YnLXqwotF1XYiO435tMm4XzFD+sP6/3Fada4e7BL3s RL9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uDeZKCp1; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si14935822edx.366.2020.11.03.13.30.22; Tue, 03 Nov 2020 13:30:22 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uDeZKCp1; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732938AbgKCU6S (ORCPT + 15 others); Tue, 3 Nov 2020 15:58:18 -0500 Received: from mail.kernel.org ([198.145.29.99]:60736 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731620AbgKCU6J (ORCPT ); Tue, 3 Nov 2020 15:58:09 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 10D7A22226; Tue, 3 Nov 2020 20:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437088; bh=6gqfKi7nRYV04QdamIXbFjjF4hzO7LFY2ItuIf0RGDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uDeZKCp1wJdj6qMpiP/Zs7Kcm6uci7BAkUG+rpZsgnWzoquKQTXABP6DmUhxLQhBL 9c0mFwYmQKM4oOtm77D5BNYrlolmODIETlFSg7zsYRK7YO8PUwQS5sW+btgRRUl3Ey PtT9OvCMj2yfLEeZCrgF4HC5SEYqDSsywxVpfNCM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oliver Neukum , Pascal Vizeli , Jerome Brunet Subject: [PATCH 5.4 141/214] usb: cdc-acm: fix cooldown mechanism Date: Tue, 3 Nov 2020 21:36:29 +0100 Message-Id: <20201103203304.045751616@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jerome Brunet commit 38203b8385bf6283537162bde7d499f830964711 upstream. Commit a4e7279cd1d1 ("cdc-acm: introduce a cool down") is causing regression if there is some USB error, such as -EPROTO. This has been reported on some samples of the Odroid-N2 using the Combee II Zibgee USB dongle. > struct acm *acm = container_of(work, struct acm, work) is incorrect in case of a delayed work and causes warnings, usually from the workqueue: > WARNING: CPU: 0 PID: 0 at kernel/workqueue.c:1474 __queue_work+0x480/0x528. When this happens, USB eventually stops working completely after a while. Also the ACM_ERROR_DELAY bit is never set, so the cooldown mechanism previously introduced cannot be triggered and acm_submit_read_urb() is never called. This changes makes the cdc-acm driver use a single delayed work, fixing the pointer arithmetic in acm_softint() and set the ACM_ERROR_DELAY when the cooldown mechanism appear to be needed. Fixes: a4e7279cd1d1 ("cdc-acm: introduce a cool down") Cc: Oliver Neukum Reported-by: Pascal Vizeli Acked-by: Oliver Neukum Signed-off-by: Jerome Brunet Link: https://lore.kernel.org/r/20201019170702.150534-1-jbrunet@baylibre.com Cc: stable Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/class/cdc-acm.c | 12 +++++------- drivers/usb/class/cdc-acm.h | 3 +-- 2 files changed, 6 insertions(+), 9 deletions(-) --- a/drivers/usb/class/cdc-acm.c +++ b/drivers/usb/class/cdc-acm.c @@ -507,6 +507,7 @@ static void acm_read_bulk_callback(struc "%s - cooling babbling device\n", __func__); usb_mark_last_busy(acm->dev); set_bit(rb->index, &acm->urbs_in_error_delay); + set_bit(ACM_ERROR_DELAY, &acm->flags); cooldown = true; break; default: @@ -532,7 +533,7 @@ static void acm_read_bulk_callback(struc if (stopped || stalled || cooldown) { if (stalled) - schedule_work(&acm->work); + schedule_delayed_work(&acm->dwork, 0); else if (cooldown) schedule_delayed_work(&acm->dwork, HZ / 2); return; @@ -562,13 +563,13 @@ static void acm_write_bulk(struct urb *u acm_write_done(acm, wb); spin_unlock_irqrestore(&acm->write_lock, flags); set_bit(EVENT_TTY_WAKEUP, &acm->flags); - schedule_work(&acm->work); + schedule_delayed_work(&acm->dwork, 0); } static void acm_softint(struct work_struct *work) { int i; - struct acm *acm = container_of(work, struct acm, work); + struct acm *acm = container_of(work, struct acm, dwork.work); if (test_bit(EVENT_RX_STALL, &acm->flags)) { smp_mb(); /* against acm_suspend() */ @@ -584,7 +585,7 @@ static void acm_softint(struct work_stru if (test_and_clear_bit(ACM_ERROR_DELAY, &acm->flags)) { for (i = 0; i < acm->rx_buflimit; i++) if (test_and_clear_bit(i, &acm->urbs_in_error_delay)) - acm_submit_read_urb(acm, i, GFP_NOIO); + acm_submit_read_urb(acm, i, GFP_KERNEL); } if (test_and_clear_bit(EVENT_TTY_WAKEUP, &acm->flags)) @@ -1364,7 +1365,6 @@ made_compressed_probe: acm->ctrlsize = ctrlsize; acm->readsize = readsize; acm->rx_buflimit = num_rx_buf; - INIT_WORK(&acm->work, acm_softint); INIT_DELAYED_WORK(&acm->dwork, acm_softint); init_waitqueue_head(&acm->wioctl); spin_lock_init(&acm->write_lock); @@ -1574,7 +1574,6 @@ static void acm_disconnect(struct usb_in } acm_kill_urbs(acm); - cancel_work_sync(&acm->work); cancel_delayed_work_sync(&acm->dwork); tty_unregister_device(acm_tty_driver, acm->minor); @@ -1617,7 +1616,6 @@ static int acm_suspend(struct usb_interf return 0; acm_kill_urbs(acm); - cancel_work_sync(&acm->work); cancel_delayed_work_sync(&acm->dwork); acm->urbs_in_error_delay = 0; --- a/drivers/usb/class/cdc-acm.h +++ b/drivers/usb/class/cdc-acm.h @@ -112,8 +112,7 @@ struct acm { # define ACM_ERROR_DELAY 3 unsigned long urbs_in_error_delay; /* these need to be restarted after a delay */ struct usb_cdc_line_coding line; /* bits, stop, parity */ - struct work_struct work; /* work queue entry for various purposes*/ - struct delayed_work dwork; /* for cool downs needed in error recovery */ + struct delayed_work dwork; /* work queue entry for various purposes */ unsigned int ctrlin; /* input control lines (DCD, DSR, RI, break, overruns) */ unsigned int ctrlout; /* output control lines (DTR, RTS) */ struct async_icount iocount; /* counters for control line changes */