From patchwork Wed Oct 18 01:37:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Duggan X-Patchwork-Id: 10013313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 39B19600CC for ; Wed, 18 Oct 2017 01:38:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AEE928A7D for ; Wed, 18 Oct 2017 01:38:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1DE5428A81; Wed, 18 Oct 2017 01:38:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BE5E28A7D for ; Wed, 18 Oct 2017 01:38:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1762165AbdJRBiA (ORCPT ); Tue, 17 Oct 2017 21:38:00 -0400 Received: from mail-sn1nam01on0062.outbound.protection.outlook.com ([104.47.32.62]:37546 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1756726AbdJRBh6 (ORCPT ); Tue, 17 Oct 2017 21:37:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector1-synaptics-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3AEzbs2/BVPouaV84U9HAJjqGyV87srjmWoLzUXohlc=; b=saet0sDE9D/R5yL0pg1Iz23YBiPegIzysbQ14OlzDinAKAYBylRxiBQuyDqhODppysqHkcA7I3OzvA6ksKniJ4P/cLoBGeY2hmKZigYPshvawyg0PN89zXixNSyYrdt5r0RXsSEpU5Sk+JIpoQEiqkMhxaoL2tU2qQMMYj/3tis= Received: from noble.synaptics-inc.local (192.147.44.15) by MWHPR03MB2589.namprd03.prod.outlook.com (10.168.206.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.77.7; Wed, 18 Oct 2017 01:37:54 +0000 From: Andrew Duggan To: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Duggan , Jiri Kosina , Benjamin Tissoires , Hendrik Langer Subject: [PATCH] HID: rmi: Check that a device is a RMI device before calling RMI functions Date: Tue, 17 Oct 2017 18:37:36 -0700 Message-Id: <1508290656-18871-1-git-send-email-aduggan@synaptics.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [192.147.44.15] X-ClientProxiedBy: MWHPR2201CA0006.namprd22.prod.outlook.com (10.174.164.19) To MWHPR03MB2589.namprd03.prod.outlook.com (10.168.206.139) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00575cc5-4ecd-43c1-6b81-08d515c8da42 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(2017030254152)(2017052603199)(201703131423075)(201703031133081)(201702281549075); SRVR:MWHPR03MB2589; X-Microsoft-Exchange-Diagnostics: 1; MWHPR03MB2589; 3:CQVQhehNFl7u3IzSnGyCsArz48ytMmK19eIFRhOEUTO8Atn08wcbnHMIFb2NvAxAPpgyHKZY17+bF+UaK7CV6JpX2pZQu8hUAK6OXHeH0HTuE7YYJ0u9FzS1fvy0I+5iDPNq+/g31V/4bT/FbaAuZP+LBpdJZ7Qe+PCfgvTS/PsL5LdaqaPVeFsVzRrNQ/pxmRI2RRJ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uC0/Sj+qFbE6GZ+t7kep5Ts6N+eNoWh+ZpYcjyHT3OHvXALXlCaaE=; 4:q2llh3GOA3N+SqatAHtDdcnNFq4HeLEn0HdhsRKuFIgNYU/gmxJ7G2wzPWFkO+uJAJpi1q5QhZlkhEuF5hL4Vnd+3aEP+Wt+2N2jGCK+C+E6USC4wMfjk4qD8JPRjVgJSuKBg2mVkM/1L5QfjHamJk57381xNChJUdlTFJbezi/9ufrRfVn8a4Tw/hqXJiUE6vvH0pRUtBVQtuFjwPS/6yPZ5Qq+42Z2yhVISXwQV0Jw+DvTPRwz0bmlbXLQ+7Af X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(8121501046)(5005006)(3002001)(10201501046)(93006095)(93001095)(100000703101)(100105400095)(6041248)(20161123558100)(20161123564025)(20161123560025)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:MWHPR03MB2589; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:MWHPR03MB2589; X-Forefront-PRVS: 0464DBBBC4 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(346002)(376002)(54094003)(52314003)(199003)(189002)(48376002)(81156014)(106356001)(86362001)(101416001)(36756003)(3846002)(6666003)(6512007)(50226002)(66066001)(50986999)(16586007)(68736007)(8936002)(47776003)(8666007)(16526018)(8676002)(50466002)(6306002)(105586002)(25786009)(6116002)(54906003)(5003940100001)(81166006)(6486002)(5660300001)(7736002)(6506006)(33646002)(4326008)(189998001)(53936002)(478600001)(316002)(5890100001)(966005)(97736004)(305945005)(2906002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR03MB2589; H:noble.synaptics-inc.local; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=aduggan@synaptics.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR03MB2589; 23:tsO2lyxqgyxEMaVBxZSlzLbI4kntlwSofv/AFFWCR?= =?us-ascii?Q?sCYjNBvCFa4j0QOpnP1kKogM48DFvqNsGwH+hbTjwNzLt7kRJYZ3mSQ12Jo6?= =?us-ascii?Q?tkQb1Gv8Q8/INJ6xAh0qMl6iLWRGd+OUVm0cX+GmbMEN0HQ35OXgi95li8bj?= =?us-ascii?Q?Rqb5/fFWBu7bOdfaQ8gfaTqUInDdJ8h02tkyfZZLFm/tZ7SfuA0+wfP6ayEu?= =?us-ascii?Q?NenY0NvzfBqD2giMMw1LoVRGES6l9bdxiZUFoj5enFXRgiMQykuY4SZEuOOC?= =?us-ascii?Q?YdYyyXSBTyFxHFAYTsOCjcIj6NrgEpiojdLsm3GrJW6H+bSi7fCg9U1+6/5D?= =?us-ascii?Q?LDNRMo2lcJCiT92ybkSf+iYsDTYcaRg3+XcCxtgmVQfptyOwX4yZoprAN44h?= =?us-ascii?Q?88oyH7izXrlL+Woy+NHX3tNKFjnki9q+s4sVhGGyCIuGJ5SsPXjTyd88gV1n?= =?us-ascii?Q?uiz7gEkk7YYLFto+eezdMYGYJgAtxhHcK0IxbawRUaOkQlsFJli8Mb4MoSbF?= =?us-ascii?Q?+Pd40UqA8ggDNb6Bp8kHsVYa5j2QwDIruCXP4+0GStAZyzIi2s4Ri1f4//gL?= =?us-ascii?Q?74ZC22O+5x4qXnnYHmjUZDbmXBakLH3Rv26B25wmhxGL2dqql0dRKO/CwxUs?= =?us-ascii?Q?td1REoNQLdIQDiC5RHROvdltB8Z3VtRe6Fw+Z+KholretIiKn60oLC+GODBs?= =?us-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CUAoay/9Rbqg0kZZ4CE8A==; 24:sFq3lEHSyr6GtjsnT+sAQ7rYZt/roEVi5tlo4qvVoUe6FeYZZqo2GE/02cJZ8rbSH9wiDbt3igIOtrjJKj0i5zaGo08603MZoSGOX1Y/IIA=; 7:yBYwvz4mkUUQASH6FOStTqnDepsH/W0X4+re0UpEiBhZEmO6DuO+iMbpq9Nc3pdxsxRiAToxq7NWIXYiSMa2QoF/kFO+kc7ZjQAut7kXJ4+nOAFmTKu1zthcqpP999aTGAqtPXwprXGlv5VkRaMB3RKQODAx2syadFbVmUMYOn/El8isBKntT6SWgsfRqzhHX1NfFBokKbvM5wFuEE5hwpLWTwW4xZMCjd6bJmH+F3A= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2017 01:37:54.0190 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR03MB2589 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The hid-rmi driver may handle non rmi devices on composite USB devices. Callbacks need to make sure that the current device is a RMI device before calling RMI specific functions. Most callbacks already have this check, but this patch adds checks to the remaining callbacks. Signed-off-by: Andrew Duggan Tested-by: Hendrik Langer Reviewed-by: Benjamin Tissoires --- This is the patch which hopefully will address the X1 tablet dock freeze: http://www.spinics.net/lists/linux-input/msg53582.html I was not able to test on a composite USB device so I have not tested confirmed this will fix the reported issues. But, based on the description I think it will. I also added a check for rmi_raw_event() since it could be possible that another hid device using one of the same report IDs as an RMI device could result in calling into unitialized RMI functions. It was also the only callbacl left not checking the RMI_DEVICE flag. I wonder if this explains the attach crash. Anyway, I would appriciate it if Hendrik or someone else with the device could test this patch to confirm it fixes the reported behavior. Thanks, Andrew drivers/hid/hid-rmi.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/hid/hid-rmi.c b/drivers/hid/hid-rmi.c index 5b40c26..d987e02 100644 --- a/drivers/hid/hid-rmi.c +++ b/drivers/hid/hid-rmi.c @@ -368,6 +368,11 @@ static int rmi_check_sanity(struct hid_device *hdev, u8 *data, int size) static int rmi_raw_event(struct hid_device *hdev, struct hid_report *report, u8 *data, int size) { + struct rmi_data *hdata = hid_get_drvdata(hdev); + + if (!(hdata->device_flags & RMI_DEVICE)) + return 0; + size = rmi_check_sanity(hdev, data, size); if (size < 2) return 0; @@ -706,9 +711,11 @@ static void rmi_remove(struct hid_device *hdev) { struct rmi_data *hdata = hid_get_drvdata(hdev); - clear_bit(RMI_STARTED, &hdata->flags); - cancel_work_sync(&hdata->reset_work); - rmi_unregister_transport_device(&hdata->xport); + if (hdata->device_flags & RMI_DEVICE) { + clear_bit(RMI_STARTED, &hdata->flags); + cancel_work_sync(&hdata->reset_work); + rmi_unregister_transport_device(&hdata->xport); + } hid_hw_stop(hdev); }