Changeset f959a20f in mainline for uspace/lib/usbhid


Ignore:
Timestamp:
2019-02-01T22:32:38Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
00b7fc8
Parents:
1a37496
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 21:22:39)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-01 22:32:38)
Message:

Avoid directly using .head/.next/.prev of list_t/link_t

Use existing constructs from <adt/list.h> instead.

Location:
uspace/lib/usbhid/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhid/src/hiddescriptor.c

    r1a37496 rf959a20f  
    8989    usb_hid_report_path_t *cmp_path)
    9090{
    91         link_t *path_it = report->collection_paths.head.next;
    92         usb_hid_report_path_t *path = NULL;
    93 
    94         if ((report == NULL) || (cmp_path == NULL)) {
     91        if (report == NULL || cmp_path == NULL)
    9592                return NULL;
    96         }
    97 
    98         while (path_it != &report->collection_paths.head) {
    99                 path = list_get_instance(path_it, usb_hid_report_path_t,
    100                     cpath_link);
    101 
     93
     94        list_foreach(report->collection_paths, cpath_link, usb_hid_report_path_t, path) {
    10295                if (usb_hid_report_compare_usage_path(path, cmp_path,
    103                     USB_HID_PATH_COMPARE_STRICT) == 0) {
    104                         break;
    105                 }
    106                 path_it = path_it->next;
    107         }
    108         if (path_it == &report->collection_paths.head) {
    109                 path = usb_hid_report_path_clone(cmp_path);
    110                 if (path == NULL) {
    111                         return NULL;
    112                 }
    113                 list_append(&path->cpath_link, &report->collection_paths);
    114                 report->collection_paths_count++;
    115 
    116                 return path;
    117         } else {
    118                 return list_get_instance(path_it, usb_hid_report_path_t,
    119                     cpath_link);
    120         }
     96                    USB_HID_PATH_COMPARE_STRICT) == 0)
     97                        return path;
     98        }
     99
     100        usb_hid_report_path_t *path = usb_hid_report_path_clone(cmp_path);
     101        if (path == NULL)
     102                return NULL;
     103
     104        list_append(&path->cpath_link, &report->collection_paths);
     105        report->collection_paths_count++;
     106
     107        return path;
    121108}
    122109
     
    474461                                    usb_hid_report_item_t, link);
    475462
     463                                link_t *tmp_link = list_prev(
     464                                    &report_item->usage_path->cpath_link,
     465                                    &report->collection_paths);
     466                                assert(tmp_link);
     467
    476468                                usb_hid_report_usage_path_t *tmp_usage_path;
    477                                 tmp_usage_path = list_get_instance(
    478                                     report_item->usage_path->cpath_link.prev,
     469                                tmp_usage_path = list_get_instance(tmp_link,
    479470                                    usb_hid_report_usage_path_t, rpath_items_link);
    480471
     
    486477
    487478                                usb_hid_report_path_free(report_item->usage_path);
    488                                 list_remove (item_link);
     479                                list_remove(item_link);
    489480
    490481                                break;
  • uspace/lib/usbhid/src/hidparser.c

    r1a37496 rf959a20f  
    493493
    494494        if (field == NULL) {
    495                 field_it = report_des->report_items.head.next;
    496         } else {
    497                 field_it = field->ritems_link.next;
    498         }
    499 
    500         while (field_it != &report_des->report_items.head) {
     495                field_it = list_first(&report_des->report_items);
     496        } else {
     497                field_it = list_next(&field->ritems_link, &report_des->report_items);
     498        }
     499
     500        while (field_it != NULL) {
    501501                field = list_get_instance(field_it, usb_hid_report_field_t,
    502502                    ritems_link);
     
    514514                        usb_hid_report_remove_last_item(field->collection_path);
    515515                }
    516                 field_it = field_it->next;
     516                field_it = list_next(field_it, &report_des->report_items);
    517517        }
    518518
     
    547547                        return 0;
    548548                } else {
    549                         report_it = report_des->reports_link.next;
     549                        report_it = list_next(&report_des->reports_link,
     550                            &report->reports);
    550551                }
    551552        } else {
    552                 report_it = report->reports.head.next;
    553         }
    554 
    555         while (report_it != &report->reports.head) {
     553                report_it = list_first(&report->reports);
     554        }
     555
     556        while (report_it != NULL) {
    556557                report_des = list_get_instance(report_it,
    557558                    usb_hid_report_description_t, reports_link);
     
    561562                }
    562563
    563                 report_it = report_it->next;
     564                report_it = list_next(report_it, &report->reports);
    564565        }
    565566
  • uspace/lib/usbhid/src/hidpath.c

    r1a37496 rf959a20f  
    250250                 * Path is prefix of the report_path
    251251                 */
    252                 report_link = report_path->items.head.next;
    253                 path_link = path->items.head.next;
    254 
    255                 while ((report_link != &report_path->items.head) &&
    256                     (path_link != &path->items.head)) {
     252                report_link = list_first(&report_path->items);
     253                path_link = list_first(&path->items);
     254
     255                while (report_link != NULL && path_link != NULL) {
    257256
    258257                        report_item = list_get_instance(report_link,
     
    268267                                return 1;
    269268                        } else {
    270                                 report_link = report_link->next;
    271                                 path_link = path_link->next;
     269                                report_link = list_next(report_link, &report_path->items);
     270                                path_link = list_next(path_link, &path->items);
    272271                        }
    273272                }
    274273
    275274                if ((((flags & USB_HID_PATH_COMPARE_BEGIN) != 0) &&
    276                     (path_link == &path->items.head)) ||
    277                     ((report_link == &report_path->items.head) &&
    278                     (path_link == &path->items.head))) {
     275                    (path_link == NULL)) ||
     276                    (report_link == NULL && path_link == NULL)) {
    279277                        return 0;
    280278                } else {
     
    287285                 * Path is suffix of report_path
    288286                 */
    289                 report_link = report_path->items.head.prev;
    290                 path_link = path->items.head.prev;
     287                report_link = list_last(&report_path->items);
     288                path_link = list_last(&path->items);
    291289
    292290                if (list_empty(&path->items)) {
     
    294292                }
    295293
    296                 while ((report_link != &report_path->items.head) &&
    297                     (path_link != &path->items.head)) {
     294                while (report_link != NULL && path_link != NULL) {
    298295                        report_item = list_get_instance(report_link,
    299296                            usb_hid_report_usage_path_t, rpath_items_link);
     
    308305                                return 1;
    309306                        } else {
    310                                 report_link = report_link->prev;
    311                                 path_link = path_link->prev;
     307                                report_link = list_prev(report_link, &report_path->items);
     308                                path_link = list_prev(path_link, &path->items);
    312309                        }
    313310                }
    314311
    315                 if (path_link == &path->items.head) {
     312                if (path_link == NULL) {
    316313                        return 0;
    317314                } else {
Note: See TracChangeset for help on using the changeset viewer.