Index: uspace/lib/usbhid/src/hiddescriptor.c
===================================================================
--- uspace/lib/usbhid/src/hiddescriptor.c	(revision 1433ecda9b732f3f185f902feb26826ec2496e03)
+++ uspace/lib/usbhid/src/hiddescriptor.c	(revision 902dd4bcbf12a24a5c7153d6f97cf6cd7886c59f)
@@ -96,21 +96,21 @@
 	usb_hid_report_path_t *path = NULL;
 
-	if((report == NULL) || (cmp_path == NULL)) {
+	if ((report == NULL) || (cmp_path == NULL)) {
 		return NULL;
 	}
 
-	while(path_it != &report->collection_paths.head) {
+	while (path_it != &report->collection_paths.head) {
 		path = list_get_instance(path_it, usb_hid_report_path_t,
-				cpath_link);
-
-		if(usb_hid_report_compare_usage_path(path, cmp_path,
-					USB_HID_PATH_COMPARE_STRICT) == 0){
+		    cpath_link);
+
+		if (usb_hid_report_compare_usage_path(path, cmp_path,
+		    USB_HID_PATH_COMPARE_STRICT) == 0) {
 			break;
 		}
 		path_it = path_it->next;
 	}
-	if(path_it == &report->collection_paths.head) {
+	if (path_it == &report->collection_paths.head) {
 		path = usb_hid_report_path_clone(cmp_path);
-		if(path == NULL) {
+		if (path == NULL) {
 			return NULL;
 		}
@@ -119,8 +119,7 @@
 
 		return path;
-	}
-	else {
+	} else {
 		return list_get_instance(path_it, usb_hid_report_path_t,
-				cpath_link);
+		    cpath_link);
 	}
 }
@@ -146,5 +145,5 @@
 
 	report->use_report_ids = 0;
-    return EOK;
+	return EOK;
 }
 
@@ -164,5 +163,6 @@
  */
 errno_t usb_hid_report_append_fields(usb_hid_report_t *report,
-		usb_hid_report_item_t *report_item) {
+    usb_hid_report_item_t *report_item)
+{
 
 	usb_hid_report_field_t *field;
@@ -170,24 +170,23 @@
 
 	uint32_t *usages;
-	int usages_used=0;
-
-	if((report == NULL) || (report_item == NULL)) {
+	int usages_used = 0;
+
+	if ((report == NULL) || (report_item == NULL)) {
 		return EINVAL;
 	}
 
-	if(report_item->usages_count > 0){
+	if (report_item->usages_count > 0) {
 		usages = malloc(sizeof(uint32_t) * report_item->usages_count);
 		memcpy(usages, report_item->usages, sizeof(int32_t) *
-				report_item->usages_count);
-	}
-	else {
+		    report_item->usages_count);
+	} else {
 		usages = NULL;
 	}
 
 	usb_hid_report_path_t *path = report_item->usage_path;
-	for(i=0; i<report_item->count; i++){
+	for (i = 0; i < report_item->count; i++) {
 
 		field = malloc(sizeof(usb_hid_report_field_t));
-		if(field == NULL) {
+		if (field == NULL) {
 			return ENOMEM;
 		}
@@ -202,5 +201,5 @@
 		field->physical_maximum = report_item->physical_maximum;
 
-		if(USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0){
+		if (USB_HID_ITEM_FLAG_VARIABLE(report_item->item_flags) == 0) {
 			/*
 			Store usage array. The Correct Usage Page and Usage is
@@ -213,23 +212,19 @@
 			field->usages = usages;
 			usages_used = 1;
-		}
-		else {
+		} else {
 
 			/* Fill the correct Usage and Usage Page */
 			int32_t usage;
-			if(i < report_item->usages_count) {
+			if (i < report_item->usages_count) {
 				usage = report_item->usages[i];
+			} else {
+				usage = report_item->usages[report_item->usages_count - 1];
 			}
-			else {
-				usage = report_item->usages[
-					report_item->usages_count- 1];
-			}
-
-			if(USB_HID_IS_EXTENDED_USAGE(usage)){
+
+			if (USB_HID_IS_EXTENDED_USAGE(usage)) {
 				field->usage = USB_HID_EXTENDED_USAGE(usage);
 				field->usage_page =
-					USB_HID_EXTENDED_USAGE_PAGE(usage);
-			}
-			else {
+				    USB_HID_EXTENDED_USAGE_PAGE(usage);
+			} else {
 				// should not occur
 				field->usage = usage;
@@ -239,10 +234,10 @@
 
 		usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_GLOBAL,
-				field->usage_page);
+		    field->usage_page);
 		usb_hid_report_set_last_item(path, USB_HID_TAG_CLASS_LOCAL,
-				field->usage);
+		    field->usage);
 
 		field->collection_path =
-			usb_hid_report_path_try_insert(report, path);
+		    usb_hid_report_path_try_insert(report, path);
 
 		field->size = report_item->size;
@@ -250,5 +245,5 @@
 		field->offset = report_item->offset + (i * report_item->size);
 
-		if(report->use_report_ids != 0) {
+		if (report->use_report_ids != 0) {
 			field->offset += 8;
 			report->use_report_ids = 1;
@@ -260,19 +255,19 @@
 		usb_hid_report_description_t *report_des;
 		report_des = usb_hid_report_find_description(report,
-			report_item->id, report_item->type);
-
-		if(report_des == NULL){
+		    report_item->id, report_item->type);
+
+		if (report_des == NULL) {
 			report_des = malloc(
-				sizeof(usb_hid_report_description_t));
-			if(report_des == NULL) {
+			    sizeof(usb_hid_report_description_t));
+			if (report_des == NULL) {
 				return ENOMEM;
 			}
 
 			memset(report_des, 0,
-				sizeof(usb_hid_report_description_t));
+			    sizeof(usb_hid_report_description_t));
 
 			report_des->type = report_item->type;
 			report_des->report_id = report_item->id;
-			if(report_des->report_id != 0) {
+			if (report_des->report_id != 0) {
 				/* set up the bit length by report_id field */
 				report_des->bit_length = 8;
@@ -296,5 +291,5 @@
 
 	// free only when not used!!!
-	if(usages && usages_used == 0) {
+	if (usages && usages_used == 0) {
 		free(usages);
 	}
@@ -313,9 +308,10 @@
  * @retval NULL If no description is founded
  */
-usb_hid_report_description_t * usb_hid_report_find_description(
-		const usb_hid_report_t *report, uint8_t report_id,
-		usb_hid_report_type_t type) {
-
-	if(report == NULL) {
+usb_hid_report_description_t *usb_hid_report_find_description(
+    const usb_hid_report_t *report, uint8_t report_id,
+    usb_hid_report_type_t type)
+{
+
+	if (report == NULL) {
 		return NULL;
 	}
@@ -324,6 +320,6 @@
 	    usb_hid_report_description_t, report_des) {
 		// if report id not set, return the first of the type
-		if(((report_des->report_id == report_id) || (report_id == 0)) &&
-		   (report_des->type == type)) {
+		if (((report_des->report_id == report_id) || (report_id == 0)) &&
+		    (report_des->type == type)) {
 			return report_des;
 		}
@@ -346,16 +342,16 @@
     const uint8_t *data, size_t size)
 {
-	size_t i=0;
-	uint8_t tag=0;
-	uint8_t item_size=0;
-	int class=0;
+	size_t i = 0;
+	uint8_t tag = 0;
+	uint8_t item_size = 0;
+	int class = 0;
 	int ret;
-	usb_hid_report_item_t *report_item=0;
+	usb_hid_report_item_t *report_item = 0;
 	usb_hid_report_item_t *new_report_item;
 	usb_hid_report_path_t *usage_path;
 
-	size_t offset_input=0;
-	size_t offset_output=0;
-	size_t offset_feature=0;
+	size_t offset_input = 0;
+	size_t offset_output = 0;
+	size_t offset_feature = 0;
 
 	link_t *item_link;
@@ -365,10 +361,10 @@
 
 	/* parser structure initialization*/
-	if(usb_hid_report_init(report) != EOK) {
+	if (usb_hid_report_init(report) != EOK) {
 		return EINVAL;
 	}
 
 	/*report item initialization*/
-	if(!(report_item=malloc(sizeof(usb_hid_report_item_t)))){
+	if (!(report_item = malloc(sizeof(usb_hid_report_item_t)))) {
 		return ENOMEM;
 	}
@@ -377,13 +373,13 @@
 
 	/* usage path context initialization */
-	if(!(usage_path=usb_hid_report_path())){
+	if (!(usage_path = usb_hid_report_path())) {
 		return ENOMEM;
 	}
 	usb_hid_report_path_append_item(usage_path, 0, 0);
 
-	while(i<size){
-		if(!USB_HID_ITEM_IS_LONG(data[i])){
-
-			if((i+USB_HID_ITEM_SIZE(data[i]))>= size){
+	while (i < size) {
+		if (!USB_HID_ITEM_IS_LONG(data[i])) {
+
+			if ((i + USB_HID_ITEM_SIZE(data[i])) >= size) {
 				return EINVAL;
 			}
@@ -393,8 +389,8 @@
 			class = USB_HID_ITEM_TAG_CLASS(data[i]);
 
-			ret = usb_hid_report_parse_tag(tag,class,data+i+1,
-				item_size,report_item, usage_path);
-
-			switch(ret){
+			ret = usb_hid_report_parse_tag(tag, class, data + i + 1,
+			    item_size, report_item, usage_path);
+
+			switch (ret) {
 			case USB_HID_NEW_REPORT_ITEM:
 				/* store report item to report and create the
@@ -404,11 +400,11 @@
 
 				usb_hid_report_path_set_report_id(
-				     report_item->usage_path, report_item->id);
-
-				if(report_item->id != 0){
+				    report_item->usage_path, report_item->id);
+
+				if (report_item->id != 0) {
 					report->use_report_ids = 1;
 				}
 
-				switch(tag) {
+				switch (tag) {
 				case USB_HID_REPORT_TAG_INPUT:
 					report_item->type =
@@ -435,5 +431,5 @@
 					report_item->offset = offset_feature;
 					offset_feature += report_item->count *
-						report_item->size;
+					    report_item->size;
 					break;
 
@@ -441,5 +437,5 @@
 					usb_log_debug2(
 					    "\tjump over - tag %X\n", tag);
-				    	break;
+					break;
 				}
 
@@ -508,8 +504,7 @@
 			/* jump over the processed block */
 			i += 1 + USB_HID_ITEM_SIZE(data[i]);
-		}
-		else{
+		} else {
 			// TBD
-			i += 3 + USB_HID_ITEM_SIZE(data[i+1]);
+			i += 3 + USB_HID_ITEM_SIZE(data[i + 1]);
 		}
 
@@ -532,18 +527,18 @@
  */
 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
-	size_t item_size, usb_hid_report_item_t *report_item,
-	usb_hid_report_path_t *usage_path) {
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path)
+{
 
 	int ret;
 
-	switch(class){
+	switch (class) {
 	case USB_HID_TAG_CLASS_MAIN:
 
-		if((ret=usb_hid_report_parse_main_tag(tag, data, item_size,
-			report_item, usage_path)) == 0) {
+		if ((ret = usb_hid_report_parse_main_tag(tag, data, item_size,
+		    report_item, usage_path)) == 0) {
 
 			return USB_HID_NEW_REPORT_ITEM;
-		}
-		else {
+		} else {
 			return ret;
 		}
@@ -552,10 +547,10 @@
 	case USB_HID_TAG_CLASS_GLOBAL:
 		return usb_hid_report_parse_global_tag(tag, data, item_size,
-			report_item, usage_path);
+		    report_item, usage_path);
 		break;
 
 	case USB_HID_TAG_CLASS_LOCAL:
 		return usb_hid_report_parse_local_tag(tag, data, item_size,
-			report_item, usage_path);
+		    report_item, usage_path);
 		break;
 
@@ -576,11 +571,10 @@
 
 int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
-	size_t item_size, usb_hid_report_item_t *report_item,
-	usb_hid_report_path_t *usage_path)
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path)
 {
 	usb_hid_report_usage_path_t *path_item;
 
-	switch(tag)
-	{
+	switch (tag) {
 	case USB_HID_REPORT_TAG_INPUT:
 	case USB_HID_REPORT_TAG_OUTPUT:
@@ -594,23 +588,21 @@
 		/* store collection atributes */
 		path_item = list_get_instance(list_first(&usage_path->items),
-			usb_hid_report_usage_path_t, rpath_items_link);
+		    usb_hid_report_usage_path_t, rpath_items_link);
 		path_item->flags = *data;
 
 		/* set last item */
 		usb_hid_report_set_last_item(usage_path,
-			USB_HID_TAG_CLASS_GLOBAL,
-			USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[
-				report_item->usages_count-1]));
+		    USB_HID_TAG_CLASS_GLOBAL,
+		    USB_HID_EXTENDED_USAGE_PAGE(report_item->usages[report_item->usages_count - 1]));
 
 		usb_hid_report_set_last_item(usage_path,
-			USB_HID_TAG_CLASS_LOCAL,
-			USB_HID_EXTENDED_USAGE(report_item->usages[
-				report_item->usages_count-1]));
+		    USB_HID_TAG_CLASS_LOCAL,
+		    USB_HID_EXTENDED_USAGE(report_item->usages[report_item->usages_count - 1]));
 
 		/* append the new one which will be set by common usage/usage
 		 * page */
 		usb_hid_report_path_append_item(usage_path,
-			report_item->usage_page,
-			report_item->usages[report_item->usages_count-1]);
+		    report_item->usage_page,
+		    report_item->usages[report_item->usages_count - 1]);
 
 		usb_hid_report_reset_local_items (report_item);
@@ -640,61 +632,61 @@
  */
 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
-	size_t item_size, usb_hid_report_item_t *report_item,
-	usb_hid_report_path_t *usage_path) {
-
-	switch(tag)
-	{
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path)
+{
+
+	switch (tag) {
 	case USB_HID_REPORT_TAG_USAGE_PAGE:
 		report_item->usage_page =
-			usb_hid_report_tag_data_uint32(data, item_size);
+		    usb_hid_report_tag_data_uint32(data, item_size);
 		break;
 
 	case USB_HID_REPORT_TAG_LOGICAL_MINIMUM:
 		report_item->logical_minimum = USB_HID_UINT32_TO_INT32(
-			usb_hid_report_tag_data_uint32(data,item_size),
-		       	item_size * 8);
+		    usb_hid_report_tag_data_uint32(data, item_size),
+		    item_size * 8);
 		break;
 
 	case USB_HID_REPORT_TAG_LOGICAL_MAXIMUM:
 		report_item->logical_maximum = USB_HID_UINT32_TO_INT32(
-			usb_hid_report_tag_data_uint32(data,item_size),
-			item_size * 8);
+		    usb_hid_report_tag_data_uint32(data, item_size),
+		    item_size * 8);
 		break;
 
 	case USB_HID_REPORT_TAG_PHYSICAL_MINIMUM:
 		report_item->physical_minimum = USB_HID_UINT32_TO_INT32(
-			usb_hid_report_tag_data_uint32(data,item_size),
-			item_size * 8);
+		    usb_hid_report_tag_data_uint32(data, item_size),
+		    item_size * 8);
 		break;
 
 	case USB_HID_REPORT_TAG_PHYSICAL_MAXIMUM:
 		report_item->physical_maximum = USB_HID_UINT32_TO_INT32(
-			usb_hid_report_tag_data_uint32(data,item_size),
-			item_size * 8);
+		    usb_hid_report_tag_data_uint32(data, item_size),
+		    item_size * 8);
 		break;
 
 	case USB_HID_REPORT_TAG_UNIT_EXPONENT:
 		report_item->unit_exponent = usb_hid_report_tag_data_uint32(
-			data,item_size);
+		    data, item_size);
 		break;
 
 	case USB_HID_REPORT_TAG_UNIT:
 		report_item->unit = usb_hid_report_tag_data_uint32(
-			data,item_size);
+		    data, item_size);
 		break;
 
 	case USB_HID_REPORT_TAG_REPORT_SIZE:
 		report_item->size = usb_hid_report_tag_data_uint32(
-			data,item_size);
+		    data, item_size);
 		break;
 
 	case USB_HID_REPORT_TAG_REPORT_COUNT:
 		report_item->count = usb_hid_report_tag_data_uint32(
-			data,item_size);
+		    data, item_size);
 		break;
 
 	case USB_HID_REPORT_TAG_REPORT_ID:
 		report_item->id = usb_hid_report_tag_data_uint32(data,
-			item_size);
+		    item_size);
 		return USB_HID_RESET_OFFSET;
 		break;
@@ -785,12 +777,12 @@
 			report_item->extended_usage_page =
 			    USB_HID_EXTENDED_USAGE_PAGE(
-			    usb_hid_report_tag_data_uint32(data,item_size));
+			    usb_hid_report_tag_data_uint32(data, item_size));
 
 			report_item->usage_maximum =
 			    USB_HID_EXTENDED_USAGE(
-			    usb_hid_report_tag_data_uint32(data,item_size));
+			    usb_hid_report_tag_data_uint32(data, item_size));
 		} else {
 			report_item->usage_maximum =
-			    usb_hid_report_tag_data_uint32(data,item_size);
+			    usb_hid_report_tag_data_uint32(data, item_size);
 		}
 
@@ -866,6 +858,6 @@
 
 	result = 0;
-	for(i=0; i<size; i++) {
-		result = (result | (data[i]) << (i*8));
+	for (i = 0; i < size; i++) {
+		result = (result | (data[i]) << (i * 8));
 	}
 
@@ -882,27 +874,27 @@
 void usb_hid_descriptor_print_list(list_t *list)
 {
-	if(list == NULL || list_empty(list)) {
-	    usb_log_debug("\tempty");
-	    return;
-	}
-
-        list_foreach(*list, ritems_link, usb_hid_report_field_t,
-    	    report_item) {
+	if (list == NULL || list_empty(list)) {
+		usb_log_debug("\tempty");
+		return;
+	}
+
+	list_foreach(*list, ritems_link, usb_hid_report_field_t,
+	    report_item) {
 		usb_log_debug("\t\tOFFSET: %u", report_item->offset);
 		usb_log_debug("\t\tSIZE: %zu", report_item->size);
 		usb_log_debug("\t\tLOGMIN: %d",
-			report_item->logical_minimum);
+		    report_item->logical_minimum);
 		usb_log_debug("\t\tLOGMAX: %d",
-			report_item->logical_maximum);
+		    report_item->logical_maximum);
 		usb_log_debug("\t\tPHYMIN: %d",
-			report_item->physical_minimum);
+		    report_item->physical_minimum);
 		usb_log_debug("\t\tPHYMAX: %d",
-			report_item->physical_maximum);
+		    report_item->physical_maximum);
 		usb_log_debug("\t\ttUSAGEMIN: %X",
-			report_item->usage_minimum);
+		    report_item->usage_minimum);
 		usb_log_debug("\t\tUSAGEMAX: %X",
-			       report_item->usage_maximum);
+		    report_item->usage_maximum);
 		usb_log_debug("\t\tUSAGES COUNT: %zu",
-			report_item->usages_count);
+		    report_item->usages_count);
 
 		usb_log_debug("\t\tVALUE: %X", report_item->value);
@@ -932,7 +924,7 @@
 		usb_log_debug("\tLength: %zu", report_des->bit_length);
 		usb_log_debug("\tB Size: %zu",
-			usb_hid_report_byte_size(report,
-				report_des->report_id,
-				report_des->type));
+		    usb_hid_report_byte_size(report,
+		    report_des->report_id,
+		    report_des->type));
 		usb_log_debug("\tItems: %zu", report_des->item_length);
 
@@ -950,5 +942,5 @@
 void usb_hid_report_deinit(usb_hid_report_t *report)
 {
-	if(report == NULL){
+	if (report == NULL) {
 		return;
 	}
@@ -957,5 +949,5 @@
 	link_t *path_link;
 	usb_hid_report_path_t *path;
-	while(!list_empty(&report->collection_paths)) {
+	while (!list_empty(&report->collection_paths)) {
 		path_link = list_first(&report->collection_paths);
 		path = list_get_instance(path_link,
@@ -969,11 +961,11 @@
 	usb_hid_report_description_t *report_des;
 	usb_hid_report_field_t *field;
-	while(!list_empty(&report->reports)) {
+	while (!list_empty(&report->reports)) {
 		report_des = list_get_instance(list_first(&report->reports),
-				usb_hid_report_description_t, reports_link);
+		    usb_hid_report_description_t, reports_link);
 
 		list_remove(&report_des->reports_link);
 
-		while(!list_empty(&report_des->report_items)) {
+		while (!list_empty(&report_des->report_items)) {
 			field = list_get_instance(
 			    list_first(&report_des->report_items),
