From patchwork Tue Feb 2 04:22:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cameron Gutman X-Patchwork-Id: 8186831 Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 1848F9F3CD for ; Tue, 2 Feb 2016 04:22:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 120E120260 for ; Tue, 2 Feb 2016 04:22:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22E76201FA for ; Tue, 2 Feb 2016 04:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751728AbcBBEWk (ORCPT ); Mon, 1 Feb 2016 23:22:40 -0500 Received: from mail-io0-f172.google.com ([209.85.223.172]:36296 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751656AbcBBEWj (ORCPT ); Mon, 1 Feb 2016 23:22:39 -0500 Received: by mail-io0-f172.google.com with SMTP id g73so4343409ioe.3 for ; Mon, 01 Feb 2016 20:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-type:content-transfer-encoding; bh=Ax3+s84bjdxY/mgWw+6UtHCQehF2qcEI+p7pXfO7w18=; b=jKzspFVcj8QJEzY00p7zSc11Nm86If+o6WRy1B3tD3416I+XZgtOyPZqasDP3ITpm/ VDTLfildgSYHaY8TpwHrQQHJnAcveFXzFoUp1ALCvUSM+Bc9BHO/0hBBcUSHVOQSKxok cl3zRR0ZO3B2UYf3ggUAqXlrNCDw+mSYgYITSyiLATG9dJmXMnp7oWNUBwaCYQJXIaFe FH/T9E8PUwgomez+LxCcVLCn75zgCHOWRiSmb1/3joyScLLSTR+fbiICmDI3WwhPGTAF UijLv0+2vN9vu419+TryLwVPHpV4wBIg5ZykaJT6xR0YYWYQJdkVf9o15WJ3hPTkmrwQ bFAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-type:content-transfer-encoding; bh=Ax3+s84bjdxY/mgWw+6UtHCQehF2qcEI+p7pXfO7w18=; b=NvXHRmk1dT94yj6BE2jS6AE0MR8FrZoU0QQkumZoG2DQkIVO+g890wk3ZDA5Xdy58x JBHHP0oztkcTtE+WdTsCKRoWaf+0PtTMzZV8ZdPICjsf4z7eB6TYjXR6ZuZzb0ZMwzlL zLh/Ud+C/HIm0DLZcOJ95HAMoX/KWusoerZcIpWCT7wDgS2ezS7xjG87U3C+b9YdeydJ UttIVtabPgPkXFumgEpzVOhuFd8H+njnPMYIq/2yMg4q2ZM6lGw0peMGDnwvlRX1OIW1 bH2KdPvi7i1vcWUwDwQ7u3VTlSyOQqu+20PwF23MCy6u+opiOO9pzITF7Ij6ooAi1FtU +lAA== X-Gm-Message-State: AG10YOQt6K3uqxUC1Ce5g3MmDfOh4aMPBQaqX9cRQGIyHNP1g72yHfx6NOc7TQeQgABwWQ== X-Received: by 10.107.136.159 with SMTP id s31mr23085355ioi.155.1454386958804; Mon, 01 Feb 2016 20:22:38 -0800 (PST) Received: from [192.168.50.128] (casewireless03.CWRU.Edu. [129.22.1.19]) by smtp.gmail.com with ESMTPSA id e32sm490096iod.25.2016.02.01.20.22.37 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 01 Feb 2016 20:22:38 -0800 (PST) To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, rojtberg@gmail.com, pgriffais@valvesoftware.com From: Cameron Gutman Subject: [PATCH] Input: xpad - prevent spurious input from wired Xbox 360 controllers Message-ID: <56B02F0B.40804@gmail.com> Date: Mon, 1 Feb 2016 20:22:35 -0800 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 After initially connecting a wired Xbox 360 controller or sending it a command to change LEDs, a status/response packet is interpreted as controller input. This causes the state of buttons represented in byte 2 of the controller data packet to be incorrect until the next valid input packet. Wireless Xbox 360 controllers are not affected. Writing a new value to the LED device while holding the Start button and running jstest is sufficient to reproduce this bug. An event will come through with the Start button released. Xboxdrv also won't attempt to read controller input from a packet where byte 0 is non-zero. It also checks that byte 1 is 0x14, but that value differs between wired and wireless controllers and this code is shared by both. I think just checking byte 0 is enough to eliminate unwanted packets. The following are some examples of 3-byte status packets I saw: 01 03 02 02 03 00 03 03 03 08 03 00 Signed-off-by: Cameron Gutman --- drivers/input/joystick/xpad.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 6727954..8b8ed9f 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c @@ -455,6 +455,10 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d static void xpad360_process_packet(struct usb_xpad *xpad, struct input_dev *dev, u16 cmd, unsigned char *data) { + /* valid pad data */ + if (data[0] != 0x00) + return; + /* digital pad */ if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { /* dpad as buttons (left, right, up, down) */