Skip to content

Commit c53431e

Browse files
whotbentiss
authored andcommitted
HID: core: store the collections as a basic tree
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 <peter.hutterer@who-t.net> Verified-by: Harry Cutts <hcutts@chromium.org> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
1 parent 52ea899 commit c53431e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

drivers/hid/hid-core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ static int open_collection(struct hid_parser *parser, unsigned type)
172172
collection->type = type;
173173
collection->usage = usage;
174174
collection->level = parser->collection_stack_ptr - 1;
175+
collection->parent = parser->active_collection;
176+
parser->active_collection = collection;
175177

176178
if (type == HID_COLLECTION_APPLICATION)
177179
parser->device->maxapplication++;
@@ -190,6 +192,8 @@ static int close_collection(struct hid_parser *parser)
190192
return -EINVAL;
191193
}
192194
parser->collection_stack_ptr--;
195+
if (parser->active_collection)
196+
parser->active_collection = parser->active_collection->parent;
193197
return 0;
194198
}
195199

include/linux/hid.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ struct hid_local {
427427
*/
428428

429429
struct hid_collection {
430+
struct hid_collection *parent;
430431
unsigned type;
431432
unsigned usage;
432433
unsigned level;
@@ -650,6 +651,7 @@ struct hid_parser {
650651
unsigned int *collection_stack;
651652
unsigned int collection_stack_ptr;
652653
unsigned int collection_stack_size;
654+
struct hid_collection *active_collection;
653655
struct hid_device *device;
654656
unsigned int scan_flags;
655657
};

0 commit comments

Comments
 (0)