From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 26011C3F2D2 for ; Tue, 3 Mar 2020 02:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E758E2166E for ; Tue, 3 Mar 2020 02:59:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583204357; bh=MA8zhD69ihie6dC77BwgHBWhp7WRCSyibezRwwFndzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=SWifdGni5lRxM3v1b8oXTeFYtA/tE9LLow4zKk427AV1rHjjx2VupL64mbDXxFte5 fo2vu79ez1hekZjtJCHMqRmD2wiymFYSPdFOs9C/HxQs5vOylIiVq2cMemPNyxOZFI iABVBCko4HOGjhebVv3mkY9mIJ7mzLemWNVQpjgk= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729007AbgCCC7P (ORCPT ); Mon, 2 Mar 2020 21:59:15 -0500 Received: from mail.kernel.org ([198.145.29.99]:42980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728186AbgCCCrt (ORCPT ); Mon, 2 Mar 2020 21:47:49 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6EDEC24684; Tue, 3 Mar 2020 02:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583203669; bh=MA8zhD69ihie6dC77BwgHBWhp7WRCSyibezRwwFndzk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sl82fSqL/U9jBNcqF7+k8brCjHxHx11LiqXZmE7cyW7o8n2hM9+99otdLifzzIvv2 rjySFKCebvhsuDGi8wth6riNfsncdveqDUxV7sOz29Se2OrceS4CHwiHAgNDG/QpEl Xbv7omOHfeATanmA5thCTjQQR8AB8V3UrebN7Wfw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sergey Organov , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Felipe Balbi , Sasha Levin , linux-usb@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 07/58] usb: gadget: serial: fix Tx stall after buffer overflow Date: Mon, 2 Mar 2020 21:46:49 -0500 Message-Id: <20200303024740.9511-7-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200303024740.9511-1-sashal@kernel.org> References: <20200303024740.9511-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sergey Organov [ Upstream commit e4bfded56cf39b8d02733c1e6ef546b97961e18a ] Symptom: application opens /dev/ttyGS0 and starts sending (writing) to it while either USB cable is not connected, or nobody listens on the other side of the cable. If driver circular buffer overflows before connection is established, no data will be written to the USB layer until/unless /dev/ttyGS0 is closed and re-opened again by the application (the latter besides having no means of being notified about the event of establishing of the connection.) Fix: on open and/or connect, kick Tx to flush circular buffer data to USB layer. Signed-off-by: Sergey Organov Reviewed-by: Michał Mirosław Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/u_serial.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c index bb1e2e1d00769..038c445a4e9b5 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -560,8 +560,10 @@ static int gs_start_io(struct gs_port *port) port->n_read = 0; started = gs_start_rx(port); - /* unblock any pending writes into our circular buffer */ if (started) { + gs_start_tx(port); + /* Unblock any pending writes into our circular buffer, in case + * we didn't in gs_start_tx() */ tty_wakeup(port->port.tty); } else { gs_free_requests(ep, head, &port->read_allocated); -- 2.20.1