From patchwork Thu Nov 22 06:34:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Hutterer X-Patchwork-Id: 10693565 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F0D4614BD for ; Thu, 22 Nov 2018 06:35:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E67B92C57E for ; Thu, 22 Nov 2018 06:35:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA84D2C59A; Thu, 22 Nov 2018 06:35:42 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 87A8C2C57E for ; Thu, 22 Nov 2018 06:35:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbeKVRM4 (ORCPT ); Thu, 22 Nov 2018 12:12:56 -0500 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:43355 "EHLO out4-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732955AbeKVRMz (ORCPT ); Thu, 22 Nov 2018 12:12:55 -0500 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 57A5021F6E; Thu, 22 Nov 2018 01:34:56 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Thu, 22 Nov 2018 01:34:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=who-t.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm1; bh=7YaYxM3zwhxAd S2G9qdRSd9LLkUOArdQ0uT0AOMl/P4=; b=NQBADYNuq66+bizkD+PsogwK//5XK XaplCH/ogqORUBAT9y0qZlWB1Z1B7O1jc9W8ZAdUnJPaTEqQaZuN5fOqTnBQQYSM dVHW7DHW+UJ8ymg20oxgeG5D1uyu9YzafPFw6kzRbJmasmdvBSOjvIqyy7sch7KO nthmqYIb/v8aEUVoJd/w2vmQNfjkh5/x/Jm4J32HZD7oD9ryO1CP9lq1CHsHnbVD p6caGlG7muwekiKVf/70+o2u89jqz5IJ9mbUBhq2jCG4BB5ZM0JODi37OV6BRCyO qyvyB+TMvxZzLVrIZPRv++dQTOLJTAL1cv/9t45XwldVUr+Fogxl9S3iA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=7YaYxM3zwhxAdS2G9qdRSd9LLkUOArdQ0uT0AOMl/P4=; b=VLyj8fyk VN91hNwrmLJMwubdd2dCw+HpDJttioQp2ZUPoofEzO8AL0TUk1PwXeqIdMvPdpaM ZsKsouRfLyfkXNVlYXuJBT/FjPVEaNIatUv4Q2S8f/UwxMsKsi5hCOw2lyGoGk7N uf6oar+cwT0A9KKBz2H7WDeJAykWUG+JvxcDAte2a0iOTzopsSX3S9t5jq/YMuhX 2BzxBl/s8Eh8VQ0vGE4Oj9/J9LDA6JatJ8IpyOEP5qOHYtfBnt6jDOzFQSFtU93j JWxm89pWGUYhQzQYORrK0dy961+aXkb0FI85ufV+uzA1qUsWiE75vzbPSRL45g4o QV383Qt2H5CfTQ== X-ME-Sender: X-ME-Proxy: Received: from jelly.home.gateway (167-179-166-29.a7b3a6.bne.nbn.aussiebb.net [167.179.166.29]) by mail.messagingengine.com (Postfix) with ESMTPA id 6A6E5102EE; Thu, 22 Nov 2018 01:34:53 -0500 (EST) From: Peter Hutterer To: linux-input@vger.kernel.org Cc: Dmitry Torokhov , Jiri Kosina , Harry Cutts , torvalds@linux-foundation.org, Nestor Lopez Casado , linux-kernel@vger.kernel.org, Benjamin Tissoires Subject: [PATCH 2/8] HID: core: store the collections as a basic tree Date: Thu, 22 Nov 2018 16:34:03 +1000 Message-Id: <20181122063409.15816-3-peter.hutterer@who-t.net> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181122063409.15816-1-peter.hutterer@who-t.net> References: <20181122063409.15816-1-peter.hutterer@who-t.net> MIME-Version: 1.0 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 For each collection parsed, store a pointer to the parent collection (if any). This makes it a lot easier to look up which collection(s) any given item is part of Signed-off-by: Peter Hutterer --- drivers/hid/hid-core.c | 4 ++++ include/linux/hid.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index 5bec9244c45b..43d488a45120 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -172,6 +172,8 @@ static int open_collection(struct hid_parser *parser, unsigned type) collection->type = type; collection->usage = usage; collection->level = parser->collection_stack_ptr - 1; + collection->parent = parser->active_collection; + parser->active_collection = collection; if (type == HID_COLLECTION_APPLICATION) parser->device->maxapplication++; @@ -190,6 +192,8 @@ static int close_collection(struct hid_parser *parser) return -EINVAL; } parser->collection_stack_ptr--; + if (parser->active_collection) + parser->active_collection = parser->active_collection->parent; return 0; } diff --git a/include/linux/hid.h b/include/linux/hid.h index a355d61940f2..fdfda898656c 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -427,6 +427,7 @@ struct hid_local { */ struct hid_collection { + struct hid_collection *parent; unsigned type; unsigned usage; unsigned level; @@ -650,6 +651,7 @@ struct hid_parser { unsigned int *collection_stack; unsigned int collection_stack_ptr; unsigned int collection_stack_size; + struct hid_collection *active_collection; struct hid_device *device; unsigned int scan_flags; };