From nobody Wed May 8 07:53:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 149063934747431.565457691128245; Mon, 27 Mar 2017 11:29:07 -0700 (PDT) Received: from localhost ([::1]:48457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csZO5-0004WM-Qg for importer@patchew.org; Mon, 27 Mar 2017 14:29:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1csZLh-0002mV-2Z for qemu-devel@nongnu.org; Mon, 27 Mar 2017 14:26:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1csZLd-000523-40 for qemu-devel@nongnu.org; Mon, 27 Mar 2017 14:26:37 -0400 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:35731) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1csZLc-00051N-Uj for qemu-devel@nongnu.org; Mon, 27 Mar 2017 14:26:33 -0400 Received: by mail-wr0-x241.google.com with SMTP id p52so12782843wrc.2 for ; Mon, 27 Mar 2017 11:26:32 -0700 (PDT) Received: from localhost.localdomain (208.red-83-50-117.dynamicip.rima-tde.net. [83.50.117.208]) by smtp.gmail.com with ESMTPSA id x127sm417582wmf.31.2017.03.27.11.26.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 11:26:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=xeshqXwCAQ0173Kuc4LwW5V+OoHBNp3nfhnDuPRsckY=; b=cHPlQNlC2ElL2hqTyqARZ64uGRYKZZIxnoTQcOJtfFfbf02zWOdVJ7to08pByl8RDE Ekd3IfjiiCoi15CERPFjZP6qemA1Ynm+FAiW/U8xYthPCZbINytYhFNIO1nzx02p2gfV PIP/nE8dLlNbs2MO14ub/hpxX9rhVYyf0ErlmieO05OYR28bwrR6nonR5BpwWW93f0sD ywOfrGPgF0JSdgW/GzFD65vkYIPdsj1trhj09Wq6uldPJ3q+MkOtWLeSXj2u7+riJDtj FK7brkeQnOycKzmFz5ak6WaR5XamnBoAiteQD+kjV/maw5xAn3bSFOKhGWch0afm+ex/ iMCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xeshqXwCAQ0173Kuc4LwW5V+OoHBNp3nfhnDuPRsckY=; b=XMeT88rYsccOoSeTa58Y16crjQ6qNK9ZZGGdKJkoDt6yfhN3gpK3PirT1c+Bz1G4ae dbbbjgQCmlcMwLGuwc2OoA26yxyIQng3gkP8gz5EKKibuTORBX8VPO5h4Iy0M4H65zKF xa0KXMoJrjJCjbSRtHo5OJF+amk1Yfp7/n16mEgxWimcmugD7PQXUPUh4NO+sNZyzWlq KagLmkowKEOTx4B3PeNJAEp0xv/R/HWEpEr0PZJncJBAf7Nacn8WHMFyBBMuDMgnb/Q6 2OfaeV/0VAhna4FgSnRTwJ5tWyFCm+gpWOpORbzGWK6yrtMqhhryMmZoj1raqOshi5OC nP7A== X-Gm-Message-State: AFeK/H2ihWWeUUBtnSyW8aEf3ddUZOBZ+EbN8aQUl9OuYHE1/TstdQ/hNCmyf73dAUrG2Q== X-Received: by 10.223.134.173 with SMTP id 42mr8672991wrx.130.1490639191904; Mon, 27 Mar 2017 11:26:31 -0700 (PDT) From: Javier Celaya To: qemu-devel@nongnu.org Date: Mon, 27 Mar 2017 20:26:24 +0200 Message-Id: <20170327182624.2914-1-jcelaya@gmail.com> X-Mailer: git-send-email 2.11.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH v3] Fix input-linux reading from device 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: kraxel@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The evdev devices in input-linux.c are read in blocks of one whole event. If there are not enough bytes available, they are discarded, instead of being kept for the next read operation. This results in lost events, of even non-working devices. This patch keeps track of the number of bytes to be read to fill up a whole event, and then handle it. Changes from v1 to v2: - Fix: Calculate offset on each iteration Changes from v2 to v3: - Fix coding style - Store offset instead of bytes to be read Signed-off-by: Javier Celaya --- ui/input-linux.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/ui/input-linux.c b/ui/input-linux.c index ac31f47719..dc0613ca1f 100644 --- a/ui/input-linux.c +++ b/ui/input-linux.c @@ -169,6 +169,8 @@ struct InputLinux { bool has_abs_x; int num_keys; int num_btns; + struct input_event event; + int read_offset; =20 QTAILQ_ENTRY(InputLinux) next; }; @@ -327,25 +329,30 @@ static void input_linux_handle_mouse(InputLinux *il, = struct input_event *event) static void input_linux_event(void *opaque) { InputLinux *il =3D opaque; - struct input_event event; int rc; + int read_size; + uint8_t *p =3D (uint8_t *)&il->event; =20 for (;;) { - rc =3D read(il->fd, &event, sizeof(event)); - if (rc !=3D sizeof(event)) { + read_size =3D sizeof(il->event) - il->read_offset; + rc =3D read(il->fd, &p[il->read_offset], read_size); + if (rc !=3D read_size) { if (rc < 0 && errno !=3D EAGAIN) { fprintf(stderr, "%s: read: %s\n", __func__, strerror(errno= )); qemu_set_fd_handler(il->fd, NULL, NULL, NULL); close(il->fd); + } else if (rc > 0) { + il->read_offset +=3D rc; } break; } + il->read_offset =3D 0; =20 if (il->num_keys) { - input_linux_handle_keyboard(il, &event); + input_linux_handle_keyboard(il, &il->event); } if (il->has_rel_x && il->num_btns) { - input_linux_handle_mouse(il, &event); + input_linux_handle_mouse(il, &il->event); } } } --=20 2.11.0