From patchwork Thu Feb 26 23:20:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Gottschlag X-Patchwork-Id: 5896711 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BA1ECBF440 for ; Thu, 26 Feb 2015 23:20:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E02C8203AD for ; Thu, 26 Feb 2015 23:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 143F5203AB for ; Thu, 26 Feb 2015 23:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754653AbbBZXUY (ORCPT ); Thu, 26 Feb 2015 18:20:24 -0500 Received: from mail-wg0-f47.google.com ([74.125.82.47]:42541 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754326AbbBZXUX (ORCPT ); Thu, 26 Feb 2015 18:20:23 -0500 Received: by wghl2 with SMTP id l2so15701822wgh.9; Thu, 26 Feb 2015 15:20:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fQC4KEAE7HVQMGZSoNRpGlt2a3o18t8trlXCZb+77HA=; b=fEdGu2zpixrvZTE8W0vekSL+mn4cMvmnf3ea143jEvAUrPO4yqZV9Hasgz/5uihwKz SsQTlo3udCCyww8je3sUiWHfqO1BqwirVp2AZVRfl20wIXHvEwwqNhUlsirjgqm99kWp +gHoslYchbvJ++TL/XJPnSu6ofEpBu/1qDYc8PPSp+PzqAl331Y6UgVIAstHhu27b5Qp 3b9cZk2hJMSiOzsQZrzLnA85NweCl6Yz5+71GtZKO4xhNZIGSkfu7qY1Bio6LdTMi1qk 3x3fYh7jhd+/GPr7fCbY085RtVJStbprEJe62v6Y1e9r+V+FMSAbz5Y8T0I6vleQQkFZ Qmzw== X-Received: by 10.194.2.75 with SMTP id 11mr21606657wjs.78.1424992822241; Thu, 26 Feb 2015 15:20:22 -0800 (PST) Received: from mathias-laptop.lan (HSI-KBW-37-209-111-36.hsi15.kabel-badenwuerttemberg.de. [37.209.111.36]) by mx.google.com with ESMTPSA id q10sm3408376wjr.41.2015.02.26.15.20.21 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Feb 2015 15:20:21 -0800 (PST) From: Mathias Gottschlag To: Dmitry Torokhov Cc: Hans de Goede , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Mathias Gottschlag Subject: [PATCHv2 2/4] psmouse: Ensure that the focaltech driver reports consistent coordinates. Date: Fri, 27 Feb 2015 00:20:06 +0100 Message-Id: <1424992808-29891-3-git-send-email-mgottschlag@gmail.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1424992808-29891-1-git-send-email-mgottschlag@gmail.com> References: <1423940502-12353-1-git-send-email-mgottschlag@gmail.com> <1424992808-29891-1-git-send-email-mgottschlag@gmail.com> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We don't know whether x_max or y_max really hold the maximum possible coordinates, and we don't know for sure whether we correctly interpret the coordinates sent by the touchpad, so we clamp the reported values to prevent confusion in userspace code. Signed-off-by: Mathias Gottschlag --- drivers/input/mouse/focaltech.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/input/mouse/focaltech.c b/drivers/input/mouse/focaltech.c index 5d8cf98..0cfc646 100644 --- a/drivers/input/mouse/focaltech.c +++ b/drivers/input/mouse/focaltech.c @@ -126,9 +126,17 @@ static void focaltech_report_state(struct psmouse *psmouse) input_mt_slot(dev, i); input_mt_report_slot_state(dev, MT_TOOL_FINGER, active); if (active) { - input_report_abs(dev, ABS_MT_POSITION_X, finger->x); + int clamped_x, clamped_y; + /* + * The touchpad might report invalid data, so we clamp + * the resulting values so that we do not confuse + * userspace. + */ + clamped_x = clamp((int)finger->x, 0, (int)priv->x_max); + clamped_y = clamp((int)finger->y, 0, (int)priv->y_max); + input_report_abs(dev, ABS_MT_POSITION_X, clamped_x); input_report_abs(dev, ABS_MT_POSITION_Y, - priv->y_max - finger->y); + priv->y_max - clamped_y); } } input_mt_report_pointer_emulation(dev, true);