Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp996196ybt; Fri, 10 Jul 2020 19:01:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7nDoQa++PvyOuXPCuXnbUTrxLxnEUssv2KkVFuGnLdJOcosPFxcBOVSIMOqMpU03RvWG+ X-Received: by 2002:a17:906:31c8:: with SMTP id f8mr51618979ejf.269.1594432884349; Fri, 10 Jul 2020 19:01:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594432884; cv=none; d=google.com; s=arc-20160816; b=bLcd7ejY7b7RQTbhTF77ou2Wi3/SxoWSynYbgwZki+sXUgl/B2fnJFtaRo/vE9iDcJ lB0vwon3SjkZj7Pnl0sP10WM8mLVepIES+RX+LMf2ZvHAPQW+FTtx38A5J6dOyk5ECa7 TnJmclyXIGH0trGDxstQida4Hqa368gucBhWl652DH5WMCQOjCIcr3gaCu3Vd+qOfkKf /PET4LllqhycOrF3Ff0ty9kV2A82wmNs/pbvoEOU6yPeu1P8lnKXhcog3Wsq41xnwjsT +34vghfiyVoKRZo96NxYlWvQWaHJFWmUtaQxf5Dx4h/w8WywF/eWoXhSb+Yn3jwck9th gI5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=GJ2VXjaXhltgn72DqcDl/jnnOyZmVWOtXKtl2Y057oo=; b=FDk5AVkRq+1wHP3F+zCOmOnSQvhalaEIl91dxB2zFlzo8XW6NpPVCWUsTl29YvV/LK BoHNik2kcZyRJlf1qnpDiFIau4lB2zgnFg7S8VktESWo8rkxi7C+dUAJGc952VQbkrVt Yzu5/YKm5P3ERWrDI885xoD7AQn/UCbuwF5+hsfCVTsLdOahbfoFosR/Dty3/gktozE4 lR0QOhUe2s/71SXlQkn/9zOF90XrbLDafUQJcm5rQEUPo6az1KYFUOQV1ckRJT4iq5uy 0fc236wQJcFly292n0vcebPB/eU/Toi1YviHOkbV+lumuVKOLKXd3gQIHCSBkctgMdjZ iTyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=tk4vRva+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n24si4714314ejx.544.2020.07.10.19.01.00; Fri, 10 Jul 2020 19:01:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=tk4vRva+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727103AbgGKB74 (ORCPT + 99 others); Fri, 10 Jul 2020 21:59:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726605AbgGKB74 (ORCPT ); Fri, 10 Jul 2020 21:59:56 -0400 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420DBC08C5DC; Fri, 10 Jul 2020 18:59:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:Cc:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=GJ2VXjaXhltgn72DqcDl/jnnOyZmVWOtXKtl2Y057oo=; b=tk4vRva+QY4640r/s8MZLCMbZV cVXZMSneHNkeVaHz5yIRAH4KL12fr02XWi/CmEi+sHYaMqB5j4bD3IWUgchxIaTgXlXeLHbfI7ROE 5PY/GS2BxhijpdLfeUR17GFU689anJpACJNXncCMlWv/6nYeyKT4VZf/6Wb3v6WJmB1VbTXhkJ6i+ wSjHR5CxUM1DIRVpmJZJzHiKoXs4fEpFXUjaZ+IhIesRMibdUFviWaP0UZsytNK1uAoLZEckoBl+T 3y6+BNnbcseJzWZjrFDeaeg4gghcSd/d2WiBMQumxK73PqoqDMX7fqm1m+h2d4hNgUBLo99xhvVSh DMIbde9Q==; Received: from mail-pl1-f169.google.com ([209.85.214.169]) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1ju4ny-0006nL-8h; Sat, 11 Jul 2020 01:59:54 +0000 Received: by mail-pl1-f169.google.com with SMTP id x9so2978314plr.2; Fri, 10 Jul 2020 18:59:54 -0700 (PDT) X-Gm-Message-State: AOAM5328m+FspgbAyQToMM1XM+K/ID0iRzaSYNgKo44dlY+vz3pe9y3i DOhtLKcKK8f/HEb+g3icCYanQHW8mEaRZQ5ehRU= X-Received: by 2002:a17:902:121:: with SMTP id 30mr62096147plb.44.1594432793558; Fri, 10 Jul 2020 18:59:53 -0700 (PDT) MIME-Version: 1.0 References: <20200710151939.4894-1-grant.likely@arm.com> In-Reply-To: <20200710151939.4894-1-grant.likely@arm.com> From: Darren Hart Date: Fri, 10 Jul 2020 18:59:42 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] hid-input: Fix devices that return multiple bytes in battery report To: Grant Likely Cc: LKML , linux-input@vger.kernel.org, Grant Likely , Darren Hart , Jiri Kosina , Benjamin Tissoires , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 10, 2020 at 8:19 AM Grant Likely wrote: > > Some devices, particularly the 3DConnexion Spacemouse wireless 3D > controllers, return more than just the battery capacity in the battery > report. The Spacemouse devices return an additional byte with a device > specific field. However, hidinput_query_battery_capacity() only > requests a 2 byte transfer. > > When a spacemouse is connected via USB (direct wire, no wireless dongle) > and it returns a 3 byte report instead of the assumed 2 byte battery > report the larger transfer confuses and frightens the USB subsystem > which chooses to ignore the transfer. Then after 2 seconds assume the > device has stopped responding and reset it. This can be reproduced > easily by using a wired connection with a wireless spacemouse. The > Spacemouse will enter a loop of resetting every 2 seconds which can be > observed in dmesg. > > This patch solves the problem by increasing the transfer request to 4 > bytes instead of 2. The fix isn't particularly elegant, but it is simple > and safe to backport to stable kernels. A further patch will follow to > more elegantly handle battery reports that contain additional data. > Applied and tested on 5.8.0-rc4+ (aa0c9086b40c) with a 3Dconnexion SpaceMouse Wireless (tested connected via USB). Observed the same behavior Grant reports before the patch. After the patch, the device stays connected successfully. Tested-by: Darren Hart Thanks Grant! > Signed-off-by: Grant Likely > Cc: Darren Hart > Cc: Jiri Kosina > Cc: Benjamin Tissoires > Cc: stable@vger.kernel.org > --- > drivers/hid/hid-input.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c > index dea9cc65bf80..e8641ce677e4 100644 > --- a/drivers/hid/hid-input.c > +++ b/drivers/hid/hid-input.c > @@ -350,13 +350,13 @@ static int hidinput_query_battery_capacity(struct hid_device *dev) > u8 *buf; > int ret; > > - buf = kmalloc(2, GFP_KERNEL); > + buf = kmalloc(4, GFP_KERNEL); > if (!buf) > return -ENOMEM; > > - ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 2, > + ret = hid_hw_raw_request(dev, dev->battery_report_id, buf, 4, > dev->battery_report_type, HID_REQ_GET_REPORT); > - if (ret != 2) { > + if (ret < 2) { > kfree(buf); > return -ENODATA; > } > -- > 2.20.1 >