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 71246C3F2D2 for ; Tue, 3 Mar 2020 02:53:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3ED512166E for ; Tue, 3 Mar 2020 02:53:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583203992; bh=f+smNxhL2OfdgV7oDdGzlTppEvpqzeaeqjamekC+ckE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=CdzTfN1fvJ+8+uDuWxKJvSpg+UMHgMuRkjdujlZvO4saRs7c6r4N8NJsaDypJHXoA 0N3jxyjNJXCPwhdTktoRDtKk2J8GV+dvzdtaKoaoYVeOLIySWB7cI75AcEkeZN5mr+ +pxxb6qFnuGzZtOTWsRxJGyXWB+Y3m/AIespOPXU= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728965AbgCCCts (ORCPT ); Mon, 2 Mar 2020 21:49:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:45990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728929AbgCCCtm (ORCPT ); Mon, 2 Mar 2020 21:49:42 -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 ABA1F2468D; Tue, 3 Mar 2020 02:49:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583203781; bh=f+smNxhL2OfdgV7oDdGzlTppEvpqzeaeqjamekC+ckE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=icIt4muG1fGkYyzzx22l9ZSWlfJKr7TldSX1wy/tZBM6UE1mu+oaQif45kMpx8U4k XL70twANYWbyYH7/ZuBeTI5IFgio+lNMAEJySuTcbVuIJJw2NneJYjt0ptOCppKxWl VDxmakOBSS6y1GY1LRZ6FFtahVHrEPIc4VvAeipY= 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 4.14 06/22] usb: gadget: serial: fix Tx stall after buffer overflow Date: Mon, 2 Mar 2020 21:49:17 -0500 Message-Id: <20200303024933.10371-6-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200303024933.10371-1-sashal@kernel.org> References: <20200303024933.10371-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 520ace49f91d9..942d2977797d7 100644 --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -715,8 +715,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