Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2655928pxa; Mon, 17 Aug 2020 15:40:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5n9ax2ZYZZO980VoqJNdba7sWkOMOzVoADBI62R9NSoHYlM7lvtE0vXgfjrtoTiRl/PIX X-Received: by 2002:a50:93a2:: with SMTP id o31mr17459437eda.203.1597704032026; Mon, 17 Aug 2020 15:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597704032; cv=none; d=google.com; s=arc-20160816; b=xIGcpFhOXi/QEoIAhPQIPB1rsNp47rH2HekvKxR8fRP/GGTIvQUk+H72/MFMDLbH7r yTYzC/E55hgKrD7E5LmFsXpCMWu/AqefmXY1JJm59yL/q/lQtjsbFw/iUWfb3K4SqhrL rLX0jTJucfOH3rnv6MW131B6JQO9yWAMTwh9tHtXn62z4IvpJhjFq9lOg4Zlwga6zm1Y JKoKfNx2fmztSP99u0Iq/sfo+mncxSNd/2zae0V+6sOLMZ4FxGGDpCxeMVycpcTJ6K+m EQRlEVHHZhq7V75uJBt1/0woBmT+R2wBxjg//sTVvOZJVM2sTu4UO23iy8h1Mn6FQYj6 R5Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VPWzSTcK0IIsmg7iZubERAsnvszSmteBhbCqE4MP/JE=; b=eO9Qe85sNGdvLQGNsZbOX6t803CTyhOZpDnZeVXK/9ZAzm0g9Fb+70QvfVibHYVGWU I0C41n2K5B8CtTuKxJO72SouhOoAI5YnfG2PhrEVbxCVg2abJ/PCDiNNlkU8AERIMhIH t6IhxeCzV9y4G0QjCbAPRIDRJxDioER0eyp8a5PHr88DD3alH2y8llC8k16h0xj2RloS 0ay+Gpk/3vOMpuYXr7QsVMl5thedweci9eVEw4c4CKLlivXm/JJ1M7yGG3GVx1eHYYly 4n02xgiPX2rQ3xb3LByIsWbW+qZXSyzhVW0x+G2dtMI5Ba8wdpwLbacZThMyWIiouQ34 3Okg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WaL864TQ; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si10014064edp.481.2020.08.17.15.40.08; Mon, 17 Aug 2020 15:40:32 -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=pass header.i=@kernel.org header.s=default header.b=WaL864TQ; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731650AbgHQRxu (ORCPT + 99 others); Mon, 17 Aug 2020 13:53:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:40390 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388628AbgHQQLh (ORCPT ); Mon, 17 Aug 2020 12:11:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 65E8422BED; Mon, 17 Aug 2020 16:11:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680695; bh=kVRhEtl+UAk4V947xnY62S2SgqgbROmEWjYLUe4PZH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WaL864TQJctIMb952BwhbdwDG6rQ+phUePy2T3WnGw/LbVu1RuwKBjLLDM14NdD5q BMDqX5lbJilyvv8Bz7zNW179OAFc5UiROh56GxggAKrAxnpISmeAtLvZt2A0Pden85 8NB9NFpSwRXKQAC7weMNhISySSz2TEFNL6hQiNqc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Grant Likely , Darren Hart , Jiri Kosina , Benjamin Tissoires , Darren Hart , Jiri Kosina Subject: [PATCH 4.19 002/168] HID: input: Fix devices that return multiple bytes in battery report Date: Mon, 17 Aug 2020 17:15:33 +0200 Message-Id: <20200817143733.824503362@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143733.692105228@linuxfoundation.org> References: <20200817143733.692105228@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Grant Likely commit 4f57cace81438cc873a96f9f13f08298815c9b51 upstream. 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. Signed-off-by: Grant Likely Cc: Darren Hart Cc: Jiri Kosina Cc: Benjamin Tissoires Cc: stable@vger.kernel.org Tested-by: Darren Hart Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-input.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -362,13 +362,13 @@ static int hidinput_query_battery_capaci 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; }