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 63F6FC3F2D2 for ; Tue, 3 Mar 2020 02:50:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2ED9E246D9 for ; Tue, 3 Mar 2020 02:50:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583203822; bh=TmISeBl+z/riu5zI1Aow+4OtmrTWBLBSDho4zHJx+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=q3NbnE/RK8tmlZC105SQlvNTO5Qp+68BRTlcgcd0ttXiMJgY2NQ3vPS8kr1UE7C6E VKQQJwoY8oCwbj8zk3UUoxdgUHV9ka+zaTZTtb+WXwMLgUabdPJSNuvyDbcGvbOZpD DVUOyqOM40FW9SQAcY6YCBSWWjBUpjI2UjMPZ/DI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729145AbgCCCuU (ORCPT ); Mon, 2 Mar 2020 21:50:20 -0500 Received: from mail.kernel.org ([198.145.29.99]:46754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727837AbgCCCuI (ORCPT ); Mon, 2 Mar 2020 21:50:08 -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 3EE34246E1; Tue, 3 Mar 2020 02:50:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1583203808; bh=TmISeBl+z/riu5zI1Aow+4OtmrTWBLBSDho4zHJx+0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rnm/mA6RElk4Mr15qlAUKRkqBd1GrqmVn4R+gjzqRTtiChBdLuQxU/i09JAGq7Biv Dw5J67/IaFDo/+cuuai44qeEHWbuelpnjcysrEtUxcIpshoLh/Z3umebMvibrv3EIf DmkFiDQPIeFM1xNUR4q1GkuQL8uSwivVqtL3ikXk= 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.9 04/13] usb: gadget: serial: fix Tx stall after buffer overflow Date: Mon, 2 Mar 2020 21:49:53 -0500 Message-Id: <20200303025002.10600-4-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200303025002.10600-1-sashal@kernel.org> References: <20200303025002.10600-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 510a54f889635..5d7d0f2e80a5e 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