[PATCH 2/2] HID: core: simplify active collection tracking

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Manually tracking an active collection to set collection parents is not
necessary, we just have to look one step back into the collection stack
to find the correct parent.

Signed-off-by: Philipp Zabel <philipp.zabel@xxxxxxxxx>
---
This could be squashed into the previous patch.
---
 drivers/hid/hid-core.c | 11 +++--------
 include/linux/hid.h    |  1 -
 2 files changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 5424f7f59680..ebeb7fc50033 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -168,12 +168,12 @@ static int open_collection(struct hid_parser *parser, unsigned type)
 		parser->device->maxcollection;
 
 	collection = parser->device->collection +
-		parser->device->maxcollection;
+		parser->device->maxcollection++;
 	collection->type = type;
 	collection->usage = usage;
 	collection->level = parser->collection_stack_ptr - 1;
-	collection->parent = parser->active_collection;
-	parser->active_collection = parser->device->maxcollection++;
+	collection->parent = (collection->level == 0) ? UINT_MAX :
+		parser->collection_stack[collection->level - 1];
 
 	if (type == HID_COLLECTION_APPLICATION)
 		parser->device->maxapplication++;
@@ -192,9 +192,6 @@ static int close_collection(struct hid_parser *parser)
 		return -EINVAL;
 	}
 	parser->collection_stack_ptr--;
-	if (parser->active_collection != UINT_MAX)
-		parser->active_collection =
-			parser->device->collection[parser->active_collection].parent;
 	return 0;
 }
 
@@ -820,7 +817,6 @@ static int hid_scan_report(struct hid_device *hid)
 		return -ENOMEM;
 
 	parser->device = hid;
-	parser->active_collection = UINT_MAX;
 	hid->group = HID_GROUP_GENERIC;
 
 	/*
@@ -1177,7 +1173,6 @@ int hid_open_report(struct hid_device *device)
 	}
 
 	parser->device = device;
-	parser->active_collection = UINT_MAX;
 
 	end = start + size;
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index e7b1b388a990..3288b06ec6bf 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -658,7 +658,6 @@ struct hid_parser {
 	unsigned int         *collection_stack;
 	unsigned int          collection_stack_ptr;
 	unsigned int          collection_stack_size;
-	unsigned int          active_collection;
 	struct hid_device    *device;
 	unsigned int          scan_flags;
 };
-- 
2.20.1




[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux