From patchwork Mon Jun 20 14:29:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1CEB601C0 for ; Mon, 20 Jun 2016 15:22:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0E451FFC9 for ; Mon, 20 Jun 2016 15:22:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5C452793A; Mon, 20 Jun 2016 15:22:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 52F8C1FFC9 for ; Mon, 20 Jun 2016 15:22:43 +0000 (UTC) Received: from localhost ([::1]:44313 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF129-0007w6-UT for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 11:22:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54007) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CU-00087A-LW for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0CR-0003CJ-Mh for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:17 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:36317) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CR-0003CA-Fa for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:15 -0400 Received: by mail-wm0-x242.google.com with SMTP id c82so11609099wme.3 for ; Mon, 20 Jun 2016 07:29:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=S/iHnUdEwSINpr0DvZY3EdVYra12v2y75gi3NTJjyCo=; b=ck8R1QBSeeAcit4xRnxspC1ywqpl98L5HRYuiBWDnmx3FIz+mPhvS21ylkjGb10AQE mbeCHej0vQ9ZSEdoctJFfinynkmeHQqqEv9X8FJ909J8HeXup888RJKawRx+zaacCASA oGgQy746mKsH4A0IcqcO/TBnny8HnvItVc3ItHmcxP23r9S4v/JrP+JeoDWvNXBn921n 9mGZQ4armP1SF9MdBm3+dzzwVT966zTIplNsI+CNP44J7UQagiE10J3lHCvGAEIVYl71 lkt09xBHFYmyvRsQNG7s22d/lABb72KvetFJiwAxVibYcy4rJddu99wYVpX4nP7Wotlg IPSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=S/iHnUdEwSINpr0DvZY3EdVYra12v2y75gi3NTJjyCo=; b=Mxi6yRY+Cvwy0NvnFVEL8T7cmexT7/ikdZUQtGZ/WnDIVLyztCV6rzENRx0KB09O4D FDsKMqmBW5AYeDq9ePwWCHhhioc7DNH79wj71t4OvaeRafsoqZZaicih2Yrgac+eIJ5q 1/jXGw2HTAPaHMSlkK9CExrKj4T3VwD+KYFYxwkwrvvb+WUy0oJ0vST+NPQjfA5P3DK1 DSmFcqGztXtFRRHaWCLlYouy3SKG3bVSOAXzDXvJB/XzFZK9N8yaxagenIxMSj+KrIQ6 vv6k827fOzFhGVeS10mF7pR0UJmZDWQ9dWzKFMl1D3vkoOzhIVV/WHQ86xChhWQajg8I x8EQ== X-Gm-Message-State: ALyK8tJ/7cpndeIYk4jwpczZ9zpAP8+XQ1Wu+eRQqlzEPky0SJFEF4mB78amGzcnrtAX1g== X-Received: by 10.194.158.138 with SMTP id wu10mr14046905wjb.84.1466432954854; Mon, 20 Jun 2016 07:29:14 -0700 (PDT) Received: from donizetti.lan (94-39-188-118.adsl-ull.clienti.tiscali.it. [94.39.188.118]) by smtp.gmail.com with ESMTPSA id bb4sm24359892wjb.32.2016.06.20.07.29.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:29:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 16:29:05 +0200 Message-Id: <1466432945-28682-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> References: <1466432945-28682-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH 6/6] serial: remove watch on reset X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcketchum@gmail.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Otherwise, this can cause serial_xmit to be entered with LSR.TEMT=0, which is invalid and causes an assertion failure. Reported-by: Bret Ketchum Signed-off-by: Paolo Bonzini Tested-by: Bret Ketchum Reviewed-by: Dr. David Alan Gilbert --- hw/char/serial.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/hw/char/serial.c b/hw/char/serial.c index d232473..7c196e2 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -228,6 +228,7 @@ static gboolean serial_watch_cb(GIOChannel *chan, GIOCondition cond, void *opaque) { SerialState *s = opaque; + s->watch_tag = 0; serial_xmit(s); return FALSE; } @@ -258,10 +259,12 @@ static void serial_xmit(SerialState *s) if (s->mcr & UART_MCR_LOOP) { /* in loopback mode, say that we just received a char */ serial_receive1(s, &s->tsr, 1); - } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1) { - if (s->tsr_retry < MAX_XMIT_RETRY && - qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, - serial_watch_cb, s) > 0) { + } else if (qemu_chr_fe_write(s->chr, &s->tsr, 1) != 1 && + s->tsr_retry < MAX_XMIT_RETRY) { + assert(s->watch_tag == 0); + s->watch_tag = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, + serial_watch_cb, s); + if (s->watch_tag > 0) { s->tsr_retry++; return; } @@ -834,6 +837,11 @@ static void serial_reset(void *opaque) { SerialState *s = opaque; + if (s->watch_tag > 0) { + g_source_remove(s->watch_tag); + s->watch_tag = 0; + } + s->rbr = 0; s->ier = 0; s->iir = UART_IIR_NO_INT;