From patchwork Mon Jun 20 14:29:04 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 9187669 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 E22BE607D1 for ; Mon, 20 Jun 2016 14:46:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF9EB27BEE for ; Mon, 20 Jun 2016 14:46:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD12127B2F; Mon, 20 Jun 2016 14:46:49 +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 2EC6F2793D for ; Mon, 20 Jun 2016 14:46:49 +0000 (UTC) Received: from localhost ([::1]:44082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0TP-0002F1-PT for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jun 2016 10:46:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CT-00086E-MH for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bF0CQ-0003C1-Mf for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:16 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:32772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bF0CQ-0003Bv-Fc for qemu-devel@nongnu.org; Mon, 20 Jun 2016 10:29:14 -0400 Received: by mail-wm0-x242.google.com with SMTP id r201so14552284wme.0 for ; Mon, 20 Jun 2016 07:29:14 -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=Jo8evYPkOgI6sunY1tBkkfHpGGlNAdB64ReItYMa6gs=; b=sQUsqtcGUt+na1skn/fzBI3key1sxjOfCn7M/+wJ8sHCaAQG7O4axKWpRuI2do2YP7 f4cku1Ya++rr+T7rGc0UMvbTdgUU2eMTBq5y7HPmhK4iPXqf9gjQ8/ODBsHQBGSaBWeA OAkiqNOGm8EXoINZ6aAlN0eO08AuktD7sggyQuZsTv+L8JaoBLSndBqfaUFv++IhlKOT w/q5MZ6RHQuTn5G0aaUAy6B7VNf5sT1lkZVz34AEw9DrJNxfscPwgu5WyhhAnJPdX/kF UZLzHtuc+RFwsJ4Nk90fKjRE7xUeQMaRpw9r4DKCWBd0kf81PRqhCYz/t9Rvwx+OtUwZ E41Q== 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=Jo8evYPkOgI6sunY1tBkkfHpGGlNAdB64ReItYMa6gs=; b=lUmJDWC6KJvQAtTPT/6OjLRJsO1AVJM9VpFr2DAJdiwswUlSkogfUzm+DBbU130J4s 9/uVF8XruxDo0ROyQh8EOGLfML2aMaJnIVTPwlJXEv01gB/X3m8QCyfH2hOctGdI05fx +fuLt/hayELJkZKc6BSrRAezj7xJmosoPTZ83ibcFAGxF4sqXLiq8ssvpDPplfU228Sl zPLzYFAE8wOgEIjhVDpT18GXsfzwByXT6RmDiTNGEvnEtX8CJgIwx0kXBmTaMzpDbMCY BCThKEyB7EZ0J9UFolJr217v3tsme/BmOQ0lc90sV1PMOtYX6rFV1gF+5kvp/oXazNoq FNzQ== X-Gm-Message-State: ALyK8tI7S9AVe7FtZd7/CB5z8xw6HQzTnsjHjZaE4P4ui245IVAwXxplkHl0m+wzgxv8CA== X-Received: by 10.28.129.208 with SMTP id c199mr10960797wmd.79.1466432953593; Mon, 20 Jun 2016 07:29:13 -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.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Jun 2016 07:29:12 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 20 Jun 2016 16:29:04 +0200 Message-Id: <1466432945-28682-6-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 5/6] char: change qemu_chr_fe_add_watch to return unsigned 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 g_source_attach can return any value between 1 and UINT_MAX if you let QEMU run long enough. However, qemu_chr_fe_add_watch can also return a negative errno value when the device is disconnected or does not support chr_add_watch. Change it to return zero to avoid overloading these values. Fix the cadence_uart which asserts in this case (easily obtained with "-serial pty"). Signed-off-by: Paolo Bonzini Reviewed-by: Dr. David Alan Gilbert --- hw/char/cadence_uart.c | 5 ++++- include/sysemu/char.h | 16 ++++++++++++++-- qemu-char.c | 8 ++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c index c856fc3..488a570 100644 --- a/hw/char/cadence_uart.c +++ b/hw/char/cadence_uart.c @@ -294,7 +294,10 @@ static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond, if (s->tx_count) { int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP, cadence_uart_xmit, s); - assert(r); + if (!r) { + s->tx_count = 0; + return FALSE; + } } uart_update_status(s); diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 1eb2d0f..07434a0 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -221,8 +221,20 @@ void qemu_chr_fe_event(CharDriverState *s, int event); void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...) GCC_FMT_ATTR(2, 3); -int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, - GIOFunc func, void *user_data); +/** + * @qemu_chr_fe_add_watch: + * + * If the backend is connected, create and add a #GSource that fires + * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP) + * is active; return the #GSource's tag. If it is disconnected, + * return 0. + * + * @cond the condition to poll for + * @func the function to call when the condition happens + * @user_data the opaque pointer to pass to @func + */ +unsigned qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data); /** * @qemu_chr_fe_write: diff --git a/qemu-char.c b/qemu-char.c index 84f49ac..39b2ccd 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3966,19 +3966,19 @@ void qemu_chr_fe_event(struct CharDriverState *chr, int event) } } -int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, - GIOFunc func, void *user_data) +unsigned qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data) { GSource *src; guint tag; if (s->chr_add_watch == NULL) { - return -ENOSYS; + return 0; } src = s->chr_add_watch(s, cond); if (!src) { - return -EINVAL; + return 0; } g_source_set_callback(src, (GSourceFunc)func, user_data, NULL);