From patchwork Fri Jan 6 08:55:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9500229 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 7262F606DE for ; Fri, 6 Jan 2017 09:00:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 570262841E for ; Fri, 6 Jan 2017 09:00:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A48228427; Fri, 6 Jan 2017 09:00:00 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 EC1A62841E for ; Fri, 6 Jan 2017 08:59:59 +0000 (UTC) Received: from localhost ([::1]:51228 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPQNS-00019n-S1 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Jan 2017 03:59:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cPQJf-0006QU-Pk for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cPQJd-0008Lf-5D for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cPQJc-0008Kw-Tu for qemu-devel@nongnu.org; Fri, 06 Jan 2017 03:56:01 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1D55CC01B138; Fri, 6 Jan 2017 08:56:01 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v068u08A023922; Fri, 6 Jan 2017 03:56:00 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id EE40580C1F; Fri, 6 Jan 2017 09:55:58 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 6 Jan 2017 09:55:30 +0100 Message-Id: <1483692945-9866-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1483692945-9866-1-git-send-email-kraxel@redhat.com> References: <1483692945-9866-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 06 Jan 2017 08:56:01 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/17] wctablet: add wctablet_queue_output helper 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: Gerd Hoffmann , avg.tolik@gmail.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add helper function to place data in the output queue, so we don't duplicate the code and also check the available space every time. Signed-off-by: Gerd Hoffmann --- backends/wctablet.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/backends/wctablet.c b/backends/wctablet.c index 0aee6fe..758c9e8 100644 --- a/backends/wctablet.c +++ b/backends/wctablet.c @@ -165,6 +165,16 @@ static int wctablet_check_command(uint8_t *arr, int count) return -1; } +static void wctablet_queue_output(TabletState *tablet, uint8_t *buf, int count) +{ + if (tablet->outlen + count > sizeof(tablet->outbuf)) { + return; + } + + memcpy(tablet->outbuf + tablet->outlen, buf, count); + tablet->outlen += count; +} + static void wctablet_event(void *opaque, int x, int y, int dz, int buttons_state) { @@ -191,10 +201,7 @@ static void wctablet_event(void *opaque, int x, codes[0] = 0xa0; } - if (tablet->outlen + 7 < WC_OUTPUT_BUF_MAX_LEN) { - memcpy(tablet->outbuf + tablet->outlen, codes, 7); - tablet->outlen += 7; - } + wctablet_queue_output(tablet, codes, 7); } static void wctablet_handler(void *opaque) @@ -250,18 +257,18 @@ static int wctablet_chr_write (struct CharDriverState *s, if (comm != -1) { if (comm == 1 && count == 2) { - memcpy(tablet->outbuf + tablet->outlen, WC_MODEL_STRING, WC_MODEL_STRING_LENGTH); - tablet->outlen += WC_MODEL_STRING_LENGTH; + wctablet_queue_output(tablet, WC_MODEL_STRING, + WC_MODEL_STRING_LENGTH); } if (comm == 3) { - memcpy(tablet->outbuf + tablet->outlen, WC_CONFIG_STRING, WC_CONFIG_STRING_LENGTH); - tablet->outlen += WC_CONFIG_STRING_LENGTH; + wctablet_queue_output(tablet, WC_CONFIG_STRING, + WC_CONFIG_STRING_LENGTH); } if (comm == 18) { - memcpy(tablet->outbuf + tablet->outlen, WC_FULL_CONFIG_STRING, WC_FULL_CONFIG_STRING_LENGTH); - tablet->outlen += WC_FULL_CONFIG_STRING_LENGTH; + wctablet_queue_output(tablet, WC_FULL_CONFIG_STRING, + WC_FULL_CONFIG_STRING_LENGTH); } if (comm == 16) { @@ -278,8 +285,7 @@ static int wctablet_chr_write (struct CharDriverState *s, codes[1] = ((input & 0x80) == 0) ? 0x7e : 0x7f; codes[2] = ( ( ( WC_H4(input) & 0x7 ) ^ 0x5) << 4 ) | (WC_L4(input) ^ 0x7); - memcpy(tablet->outbuf + tablet->outlen, codes, 7); - tablet->outlen += 7; + wctablet_queue_output(tablet, codes, 7); } // DPRINTF("-------- Command: %s\n", wctablet_commands_names[comm]);