From patchwork Mon Feb 23 13:52:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mika Westerberg X-Patchwork-Id: 5865541 X-Patchwork-Delegate: jikos@jikos.cz 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 6221FBF440 for ; Mon, 23 Feb 2015 13:53:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8AAFB20569 for ; Mon, 23 Feb 2015 13:52:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8D6CB20648 for ; Mon, 23 Feb 2015 13:52:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752323AbbBWNwv (ORCPT ); Mon, 23 Feb 2015 08:52:51 -0500 Received: from mga02.intel.com ([134.134.136.20]:30905 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752032AbbBWNwt (ORCPT ); Mon, 23 Feb 2015 08:52:49 -0500 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP; 23 Feb 2015 05:52:48 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.09,631,1418112000"; d="scan'208";a="458341324" Received: from black.fi.intel.com ([10.237.72.86]) by FMSMGA003.fm.intel.com with ESMTP; 23 Feb 2015 05:37:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1001) id B0EA34CE; Mon, 23 Feb 2015 15:52:45 +0200 (EET) From: Mika Westerberg To: Jiri Kosina Cc: Benjamin Tissoires , Mark Rutland , sb@m-labs.hk, Mika Westerberg , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] HID: i2c-hid: Read wMaxInputLength of input report instead of bufsize Date: Mon, 23 Feb 2015 15:52:44 +0200 Message-Id: <1424699565-138045-3-git-send-email-mika.westerberg@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424699565-138045-1-git-send-email-mika.westerberg@linux.intel.com> References: <1424699565-138045-1-git-send-email-mika.westerberg@linux.intel.com> 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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 Wacom digitizer (WCOM0008) on Lenovo Thinkpad 10 seems to allow reading of subsequent reports (or part of them) if we read more than wMaxInputLength of data at the time. This data is not always aligned so that the next report would start right after another. For example we might get following sequence: i2c_hid i2c-WCOM0008:00: input: 0a 00 02 21 20 17 ad 22 11 03 i2c_hid i2c-WCOM0008:00: input: ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 i2c_hid i2c-WCOM0008:00: input: 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 ad 22 11 03 0a 00 02 21 20 17 i2c_hid i2c-WCOM0008:00: i2c_hid_get_input: incomplete report (76/8450) The bufsize is 76 and wMaxInputLength is 10. In above example the first read gets right amount of data. The second and third reads get full bufsize (76 bytes) but the report is missing a start already. This causes the driver to reject the report because we got less than was expected by the report length (0x2102 = 8450). If we read only wMaxInputLength at the time this does not happen at all and the digitizer works fine. Based on this change the driver to read wMaxInputLength bytes instead of bufsize if the value looks sane. Reported-by: Sébastien Bourdeauducq Signed-off-by: Mika Westerberg --- drivers/hid/i2c-hid/i2c-hid.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index 8f1dfc5c5d9c..404ccde49acd 100644 --- a/drivers/hid/i2c-hid/i2c-hid.c +++ b/drivers/hid/i2c-hid/i2c-hid.c @@ -369,9 +369,17 @@ static int i2c_hid_hwreset(struct i2c_client *client) static void i2c_hid_get_input(struct i2c_hid *ihid) { + unsigned max_input_length = le16_to_cpu(ihid->hdesc.wMaxInputLength); int ret, ret_size; int size = ihid->bufsize; + /* + * Take the input length from HID descriptor if it is available and + * looks reasonable. + */ + if (max_input_length > 0) + size = min_t(unsigned, ihid->bufsize, max_input_length); + ret = i2c_master_recv(ihid->client, ihid->inbuf, size); if (ret != size) { if (ret < 0)