Changeset feeac0d in mainline for uspace/lib


Ignore:
Timestamp:
2013-09-10T16:32:35Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4982d87
Parents:
e8d6ce2
Message:

Simplify use of list_foreach.

Location:
uspace/lib
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/block.c

    re8d6ce2 rfeeac0d  
    9393        fibril_mutex_lock(&dcl_lock);
    9494       
    95         list_foreach(dcl, cur) {
    96                 devcon_t *devcon = list_get_instance(cur, devcon_t, link);
     95        list_foreach(dcl, link, devcon_t, devcon) {
    9796                if (devcon->service_id == service_id) {
    9897                        fibril_mutex_unlock(&dcl_lock);
     
    124123       
    125124        fibril_mutex_lock(&dcl_lock);
    126         list_foreach(dcl, cur) {
    127                 devcon_t *d = list_get_instance(cur, devcon_t, link);
     125        list_foreach(dcl, link, devcon_t, d) {
    128126                if (d->service_id == service_id) {
    129127                        fibril_mutex_unlock(&dcl_lock);
  • uspace/lib/c/generic/adt/hash_table.c

    re8d6ce2 rfeeac0d  
    227227       
    228228        /* Check for duplicates. */
    229         list_foreach(h->bucket[idx], cur) {
     229        list_foreach(h->bucket[idx], link, ht_link_t, cur_link) {
    230230                /*
    231231                 * We could filter out items using their hashes first, but
    232232                 * calling equal() might very well be just as fast.
    233233                 */
    234                 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
    235234                if (h->op->equal(cur_link, item))
    236235                        return false;
     
    258257        size_t idx = h->op->key_hash(key) % h->bucket_cnt;
    259258
    260         list_foreach(h->bucket[idx], cur) {
    261                 ht_link_t *cur_link = member_to_inst(cur, ht_link_t, link);
     259        list_foreach(h->bucket[idx], link, ht_link_t, cur_link) {
    262260                /*
    263261                 * Is this is the item we are looking for? We could have first
  • uspace/lib/c/generic/adt/list.c

    re8d6ce2 rfeeac0d  
    102102        unsigned int count = 0;
    103103       
    104         list_foreach(*list, link) {
     104        link_t *link = list_first(list);
     105        while (link != NULL) {
    105106                count++;
     107                link = list_next(link, list);
    106108        }
    107109       
  • uspace/lib/c/generic/cfg.c

    re8d6ce2 rfeeac0d  
    8383                return true;
    8484       
    85         list_foreach(data->sections, link) {
    86                 const cfg_section_t *section = cfg_section_instance(link);
    87                
     85        cfg_file_foreach(data, section) {
    8886                if (!list_empty(&section->entries))
    8987                        return false;
     
    413411const cfg_section_t *cfg_find_section(const cfg_file_t *data, const char *title)
    414412{
    415         list_foreach(data->sections, link) {
    416                 const cfg_section_t *section = cfg_section_instance(link);
    417                
     413        cfg_file_foreach(data, section) {
    418414                if (str_cmp(section->title, title) == 0)
    419415                        return section;
     
    434430const char *cfg_find_value(const cfg_section_t *section, const char *key)
    435431{
    436         list_foreach(section->entries, link) {
    437                 const cfg_entry_t *entry = cfg_entry_instance(link);
    438                
     432        cfg_section_foreach(section, entry) {
    439433                if (str_cmp(entry->key, key) == 0)
    440434                        return entry->value;
  • uspace/lib/c/generic/devman.c

    re8d6ce2 rfeeac0d  
    230230        }
    231231       
    232         match_id_t *match_id = NULL;
    233        
    234         list_foreach(match_ids->ids, link) {
    235                 match_id = list_get_instance(link, match_id_t, link);
    236                
     232        list_foreach(match_ids->ids, link, match_id_t, match_id) {
    237233                ipc_call_t answer2;
    238234                aid_t req2 = async_send_1(exch, DEVMAN_ADD_MATCH_ID,
  • uspace/lib/c/generic/pio_trace.c

    re8d6ce2 rfeeac0d  
    9595        pio_regions_t *regions = get_regions();
    9696        fibril_rwlock_read_lock(&regions->guard);
    97         list_foreach(regions->list, it) {
    98                 assert(it);
    99                 region_t *reg = region_instance(it);
    100                 assert(reg);
     97        list_foreach(regions->list, link, region_t, reg) {
    10198                if ((r >= reg->base) && (r < reg->base + reg->size)) {
    10299                        if (reg->log)
     
    131128        fibril_rwlock_write_lock(&regions->guard);
    132129        list_foreach_safe(regions->list, it, next) {
    133                 assert(it);
    134130                region_t *reg = region_instance(it);
    135                 assert(reg);
    136131                if (r >= reg->base && (r < reg->base + reg->size)) {
    137                                 list_remove(&reg->link);
    138                                 region_destroy(reg);
     132                        list_remove(&reg->link);
     133                        region_destroy(reg);
    139134                }
    140135        }
  • uspace/lib/c/include/adt/list.h

    re8d6ce2 rfeeac0d  
    6767        ((type *) (((void *)(link)) - list_link_to_void(&(((type *) NULL)->member))))
    6868
    69 #define list_foreach(list, iterator) \
    70         for (link_t *iterator = (list).head.next; \
    71             iterator != &(list).head; iterator = iterator->next)
     69#define list_foreach(list, member, itype, iterator) \
     70        for (itype *iterator = NULL; iterator == NULL; iterator =(itype *)1) \
     71            for (link_t *_link = (list).head.next; \
     72            iterator = list_get_instance(_link, itype, member), \
     73            _link != &(list).head; _link = _link->next)
    7274
    7375/** Unlike list_foreach(), allows removing items while traversing a list.
     
    238240static inline link_t *list_last(list_t *list)
    239241{
    240         return ((list->head.prev == &list->head) ? NULL : list->head.prev);
     242        return (list->head.prev == &list->head) ? NULL : list->head.prev;
     243}
     244
     245/** Get next item in list.
     246 *
     247 * @param link Current item link
     248 * @param list List containing @a link
     249 *
     250 * @return Next item or NULL if @a link is the last item.
     251 */
     252static inline link_t *list_next(link_t *link, const list_t *list)
     253{
     254        return (link->next == &list->head) ? NULL : link->next;
     255}
     256
     257/** Get previous item in list.
     258 *
     259 * @param link Current item link
     260 * @param list List containing @a link
     261 *
     262 * @return Previous item or NULL if @a link is the first item.
     263 */
     264static inline link_t *list_prev(link_t *link, const list_t *list)
     265{
     266        return (link->prev == &list->head) ? NULL : link->prev;
    241267}
    242268
     
    308334        unsigned int cnt = 0;
    309335       
    310         list_foreach(*list, link) {
     336        link_t *link = list_first(list);
     337        while (link != NULL) {
    311338                if (cnt == n)
    312339                        return link;
    313340               
    314341                cnt++;
     342                link = list_next(link, list);
    315343        }
    316344       
  • uspace/lib/c/include/cfg.h

    re8d6ce2 rfeeac0d  
    8080
    8181#define cfg_file_foreach(file, cur) \
    82         list_foreach((file)->sections, (cur))
     82        list_foreach((file)->sections, link, const cfg_section_t, (cur))
    8383
    8484#define cfg_section_instance(cur) \
     
    8686
    8787#define cfg_section_foreach(section, cur) \
    88         list_foreach((section)->entries, (cur))
     88        list_foreach((section)->entries, link, const cfg_entry_t, (cur))
    8989
    9090#define cfg_entry_instance(cur) \
  • uspace/lib/draw/drawctx.c

    re8d6ce2 rfeeac0d  
    188188         * transferred to the original surface. */
    189189
    190         list_foreach(*((list_t *) path), link) {
    191                 path_step_t *step = (path_step_t *) link;
     190        list_foreach(*((list_t *) path), link, path_step_t, step) {
    192191                switch (step->type) {
    193192                case PATH_STEP_MOVETO:
  • uspace/lib/drv/generic/driver.c

    re8d6ce2 rfeeac0d  
    9898static ddf_dev_t *driver_get_device(devman_handle_t handle)
    9999{
    100         ddf_dev_t *dev = NULL;
    101        
    102100        assert(fibril_mutex_is_locked(&devices_mutex));
    103101       
    104         list_foreach(devices, link) {
    105                 dev = list_get_instance(link, ddf_dev_t, link);
     102        list_foreach(devices, link, ddf_dev_t, dev) {
    106103                if (dev->handle == handle)
    107104                        return dev;
     
    113110static ddf_fun_t *driver_get_function(devman_handle_t handle)
    114111{
    115         ddf_fun_t *fun = NULL;
    116        
    117112        assert(fibril_mutex_is_locked(&functions_mutex));
    118113       
    119         list_foreach(functions, link) {
    120                 fun = list_get_instance(link, ddf_fun_t, link);
     114        list_foreach(functions, link, ddf_fun_t, fun) {
    121115                if (fun->handle == handle)
    122116                        return fun;
  • uspace/lib/drv/generic/interrupt.c

    re8d6ce2 rfeeac0d  
    138138    interrupt_context_list_t *list, int id)
    139139{
    140         interrupt_context_t *ctx;
    141        
    142         fibril_mutex_lock(&list->mutex);
    143        
    144         list_foreach(list->contexts, link) {
    145                 ctx = list_get_instance(link, interrupt_context_t, link);
     140        fibril_mutex_lock(&list->mutex);
     141       
     142        list_foreach(list->contexts, link, interrupt_context_t, ctx) {
    146143                if (ctx->id == id) {
    147144                        fibril_mutex_unlock(&list->mutex);
     
    157154    interrupt_context_list_t *list, ddf_dev_t *dev, int irq)
    158155{
    159         interrupt_context_t *ctx;
    160        
    161         fibril_mutex_lock(&list->mutex);
    162        
    163         list_foreach(list->contexts, link) {
    164                 ctx = list_get_instance(link, interrupt_context_t, link);
     156        fibril_mutex_lock(&list->mutex);
     157       
     158        list_foreach(list->contexts, link, interrupt_context_t, ctx) {
    165159                if (ctx->irq == irq && ctx->dev == dev) {
    166160                        fibril_mutex_unlock(&list->mutex);
  • uspace/lib/fs/libfs.c

    re8d6ce2 rfeeac0d  
    882882
    883883        fibril_mutex_lock(&instances_mutex);
    884         list_foreach(instances_list, link) {
    885                 fs_instance_t *cur = list_get_instance(link, fs_instance_t,
    886                     link);
    887 
     884        list_foreach(instances_list, link, fs_instance_t, cur) {
    888885                if (cur->service_id == service_id) {
    889886                        fibril_mutex_unlock(&instances_mutex);
     
    908905{
    909906        fibril_mutex_lock(&instances_mutex);
    910         list_foreach(instances_list, link) {
    911                 fs_instance_t *inst = list_get_instance(link, fs_instance_t,
    912                     link);
    913 
     907        list_foreach(instances_list, link, fs_instance_t, inst) {
    914908                if (inst->service_id == service_id) {
    915909                        *idp = inst->data;
     
    925919{
    926920        fibril_mutex_lock(&instances_mutex);
    927         list_foreach(instances_list, link) {
    928                 fs_instance_t *inst = list_get_instance(link, fs_instance_t,
    929                     link);
    930 
     921        list_foreach(instances_list, link, fs_instance_t, inst) {
    931922                if (inst->service_id == service_id) {
    932923                        list_remove(&inst->link);
  • uspace/lib/graph/graph.c

    re8d6ce2 rfeeac0d  
    165165
    166166        fibril_mutex_lock(&visualizer_list_mtx);
    167         list_foreach(visualizer_list, link) {
    168                 visualizer_t *cur = list_get_instance(link, visualizer_t, link);
    169                 if (cur->reg_svc_handle == handle) {
    170                         vs = cur;
     167        list_foreach(visualizer_list, link, visualizer_t, vcur) {
     168                if (vcur->reg_svc_handle == handle) {
     169                        vs = vcur;
    171170                        break;
    172171                }
     
    182181
    183182        fibril_mutex_lock(&renderer_list_mtx);
    184         list_foreach(renderer_list, link) {
    185                 renderer_t *cur = list_get_instance(link, renderer_t, link);
    186                 if (cur->reg_svc_handle == handle) {
    187                         rnd = cur;
     183        list_foreach(renderer_list, link, renderer_t, rcur) {
     184                if (rcur->reg_svc_handle == handle) {
     185                        rnd = rcur;
    188186                        break;
    189187                }
     
    322320        fibril_mutex_lock(&vs->mode_mtx);
    323321        vslmode_list_element_t *mode_elem = NULL;
    324         list_foreach(vs->modes, link) {
    325                 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     322        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    326323                if (cur->mode.index == vs->def_mode_idx) {
    327324                        mode_elem = cur;
     
    382379        fibril_mutex_lock(&vs->mode_mtx);
    383380        vslmode_list_element_t *mode_elem = NULL;
    384         list_foreach(vs->modes, link) {
    385                 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     381        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    386382                if (cur->mode.index == mode_idx) {
    387383                        mode_elem = cur;
     
    425421        fibril_mutex_lock(&vs->mode_mtx);
    426422        vslmode_list_element_t *mode_elem = NULL;
    427         list_foreach(vs->modes, link) {
    428                 vslmode_list_element_t *cur = list_get_instance(link, vslmode_list_element_t, link);
     423        list_foreach(vs->modes, link, vslmode_list_element_t, cur) {
    429424                if (cur->mode.index == mode_idx) {
    430425                        mode_elem = cur;
  • uspace/lib/gui/connection.c

    re8d6ce2 rfeeac0d  
    6565
    6666        signal_node_t *sig_node = NULL;
    67         list_foreach(connection_list, link) {
    68                 signal_node_t *cur = list_get_instance(link, signal_node_t, link);
     67        list_foreach(connection_list, link, signal_node_t, cur) {
    6968                if (cur->signal == signal) {
    7069                        sig_node = cur;
     
    8887
    8988        slot_node_t *slt_node = NULL;
    90         list_foreach(sig_node->slots, link) {
    91                 slot_node_t *cur = list_get_instance(link, slot_node_t, link);
     89        list_foreach(sig_node->slots, link, slot_node_t, cur) {
    9290                if (cur->widget == widget && cur->slot == slot) {
    9391                        slt_node = cur;
     
    121119
    122120        signal_node_t *sig_node = NULL;
    123         list_foreach(connection_list, link) {
    124                 signal_node_t *cur = list_get_instance(link, signal_node_t, link);
     121        list_foreach(connection_list, link, signal_node_t, cur) {
    125122                if (cur->signal == signal) {
    126123                        sig_node = cur;
     
    135132
    136133        slot_node_t *slt_node = NULL;
    137         list_foreach(sig_node->slots, link) {
    138                 slot_node_t *cur = list_get_instance(link, slot_node_t, link);
     134        list_foreach(sig_node->slots, link, slot_node_t, cur) {
    139135                if (cur->widget == widget && cur->slot == slot) {
    140136                        slt_node = cur;
     
    164160
    165161        signal_node_t *sig_node = NULL;
    166         list_foreach(connection_list, link) {
    167                 signal_node_t *cur = list_get_instance(link, signal_node_t, link);
     162        list_foreach(connection_list, link, signal_node_t, cur) {
    168163                if (cur->signal == signal) {
    169164                        sig_node = cur;
     
    177172        }
    178173
    179         list_foreach(sig_node->slots, link) {
    180                 slot_node_t *cur = list_get_instance(link, slot_node_t, link);
     174        list_foreach(sig_node->slots, link, slot_node_t, cur) {
    181175                cur->slot(cur->widget, data);
    182176        }
     
    190184
    191185        signal_node_t *sig_node = NULL;
    192         list_foreach(connection_list, link) {
    193                 signal_node_t *cur = list_get_instance(link, signal_node_t, link);
     186        list_foreach(connection_list, link, signal_node_t, cur) {
    194187                if (cur->signal == signal) {
    195188                        sig_node = cur;
     
    203196        }
    204197
    205         list_foreach(sig_node->slots, link) {
    206                 slot_node_t *cur = list_get_instance(link, slot_node_t, link);
    207 
     198        list_foreach(sig_node->slots, link, slot_node_t, cur) {
    208199                void *data_copy = NULL;
    209200                if (data != NULL) {
  • uspace/lib/gui/grid.c

    re8d6ce2 rfeeac0d  
    298298        paint_internal(widget);
    299299       
    300         list_foreach(widget->children, link) {
    301                 widget_t *child = list_get_instance(link, widget_t, link);
     300        list_foreach(widget->children, link, widget_t, child) {
    302301                child->repaint(child);
    303302        }
  • uspace/lib/gui/terminal.c

    re8d6ce2 rfeeac0d  
    685685        terminal_t *term = NULL;
    686686       
    687         list_foreach(terms, link) {
    688                 terminal_t *cur = list_get_instance(link, terminal_t, link);
    689                
     687        list_foreach(terms, link, terminal_t, cur) {
    690688                if (cur->dsid == (service_id_t) IPC_GET_ARG1(*icall)) {
    691689                        term = cur;
  • uspace/lib/gui/window.c

    re8d6ce2 rfeeac0d  
    137137{
    138138        if (widget->window->is_decorated) {
    139                 list_foreach(widget->children, link) {
    140                         widget_t *child = list_get_instance(link, widget_t, link);
     139                list_foreach(widget->children, link, widget_t, child) {
    141140                        child->rearrange(child,
    142141                            widget->hpos + border_thickness,
     
    146145                }
    147146        } else {
    148                 list_foreach(widget->children, link) {
    149                         widget_t *child = list_get_instance(link, widget_t, link);
     147                list_foreach(widget->children, link, widget_t, child) {
    150148                        child->rearrange(child, widget->hpos, widget->vpos,
    151149                            widget->width, widget->height);
     
    160158        if (widget->window->is_decorated) {
    161159                paint_internal(widget);
    162                 list_foreach(widget->children, link) {
    163                         widget_t *child = list_get_instance(link, widget_t, link);
     160                list_foreach(widget->children, link, widget_t, child) {
    164161                        child->rearrange(child,
    165162                            hpos + border_thickness,
     
    169166                }
    170167        } else {
    171                 list_foreach(widget->children, link) {
    172                         widget_t *child = list_get_instance(link, widget_t, link);
     168                list_foreach(widget->children, link, widget_t, child) {
    173169                        child->rearrange(child, hpos, vpos, width, height);
    174170                }
     
    181177                paint_internal(widget);
    182178        }
    183         list_foreach(widget->children, link) {
    184                 widget_t *child = list_get_instance(link, widget_t, link);
     179        list_foreach(widget->children, link, widget_t, child) {
    185180                child->repaint(child);
    186181        }
     
    268263                        win_grab(widget->window->osess, event.pos_id, flags);
    269264                } else {
    270                         list_foreach(widget->children, link) {
    271                                 widget_t *child = list_get_instance(link, widget_t, link);
     265                        list_foreach(widget->children, link, widget_t, child) {
    272266                                child->handle_position_event(child, event);
    273267                        }
    274268                }
    275269        } else {
    276                 list_foreach(widget->children, link) {
    277                         widget_t *child = list_get_instance(link, widget_t, link);
     270                list_foreach(widget->children, link, widget_t, child) {
    278271                        child->handle_position_event(child, event);
    279272                }
  • uspace/lib/usbdev/src/recognise.c

    re8d6ce2 rfeeac0d  
    383383                goto failure;
    384384       
    385         list_foreach(match_ids.ids, id_link) {
    386                 match_id_t *match_id = list_get_instance(id_link, match_id_t, link);
     385        list_foreach(match_ids.ids, link, match_id_t, match_id) {
    387386                rc = ddf_fun_add_match_id(child, match_id->id, match_id->score);
    388387                if (rc != EOK) {
  • uspace/lib/usbhid/src/hiddescriptor.c

    re8d6ce2 rfeeac0d  
    333333        }
    334334
    335         usb_hid_report_description_t *report_des = NULL;
    336        
    337         list_foreach(report->reports, report_it) {
    338                 report_des = list_get_instance(report_it,
    339                                 usb_hid_report_description_t, reports_link);
    340 
     335        list_foreach(report->reports, reports_link,
     336            usb_hid_report_description_t, report_des) {
    341337                // if report id not set, return the first of the type
    342338                if(((report_des->report_id == report_id) || (report_id == 0)) &&
     
    902898void usb_hid_descriptor_print_list(list_t *list)
    903899{
    904         usb_hid_report_field_t *report_item;
    905 
    906900        if(list == NULL || list_empty(list)) {
    907901            usb_log_debug("\tempty\n");
     
    909903        }
    910904
    911         list_foreach(*list, item) {
    912                 report_item = list_get_instance(item, usb_hid_report_field_t,
    913                                 ritems_link);
    914 
     905        list_foreach(*list, ritems_link, usb_hid_report_field_t,
     906            report_item) {
    915907                usb_log_debug("\t\tOFFSET: %X\n", report_item->offset);
    916908                usb_log_debug("\t\tSIZE: %zu\n", report_item->size);
     
    937929
    938930                usb_log_debug("\n");
    939 
    940         }
    941 
     931        }
    942932}
    943933
     
    951941void usb_hid_descriptor_print(usb_hid_report_t *report)
    952942{
    953         if(report == NULL) {
     943        if (report == NULL)
    954944                return;
    955         }
    956 
    957         usb_hid_report_description_t *report_des;
    958 
    959         list_foreach(report->reports, report_it) {
    960                 report_des = list_get_instance(report_it,
    961                         usb_hid_report_description_t, reports_link);
     945
     946        list_foreach(report->reports, reports_link,
     947            usb_hid_report_description_t, report_des) {
    962948                usb_log_debug("Report ID: %d\n", report_des->report_id);
    963949                usb_log_debug("\tType: %d\n", report_des->type);
  • uspace/lib/usbhid/src/hidparser.c

    re8d6ce2 rfeeac0d  
    130130    size_t size, uint8_t *report_id)
    131131{
    132         usb_hid_report_field_t *item;
    133 
    134132        usb_hid_report_description_t *report_des;
    135133        usb_hid_report_type_t type = USB_HID_REPORT_TYPE_INPUT;
    136        
     134
    137135        if (report == NULL) {
    138136                return EINVAL;
     
    153151
    154152        /* read data */
    155         list_foreach(report_des->report_items, list_item) {
    156                 item = list_get_instance(list_item, usb_hid_report_field_t,
    157                     ritems_link);
     153        list_foreach(report_des->report_items, ritems_link,
     154            usb_hid_report_field_t, item) {
    158155
    159156                if (USB_HID_ITEM_FLAG_CONSTANT(item->item_flags) == 0) {
    160                        
     157
    161158                        if (USB_HID_ITEM_FLAG_VARIABLE(item->item_flags) == 0) {
    162159                                /* array */
    163160                                item->value =
    164161                                        usb_hid_translate_data(item, data);
    165                
     162
    166163                                item->usage = USB_HID_EXTENDED_USAGE(
    167164                                    item->usages[item->value -
     
    184181                                /* variable item */
    185182                                item->value = usb_hid_translate_data(item,
    186                                     data);                             
    187                         }                       
     183                                    data);
     184                        }
    188185                }
    189186        }
    190        
     187
    191188        return EOK;
    192189}
     
    295292        usb_hid_report_description_t *report_des = NULL;
    296293
    297         list_foreach(report->reports, report_it) {
    298                 report_des = list_get_instance(report_it,
    299                     usb_hid_report_description_t, reports_link);
    300                
     294        list_foreach(report->reports, reports_link,
     295            usb_hid_report_description_t, report_des) {
    301296                if ((report_des->report_id == report_id) &&
    302297                    (report_des->type == USB_HID_REPORT_TYPE_OUTPUT)) {
     
    345340        int length;
    346341        int32_t tmp_value;
    347        
     342
    348343        if (report == NULL) {
    349344                return EINVAL;
     
    351346
    352347        if (report->use_report_ids != 0) {
    353                 buffer[0] = report_id;         
     348                buffer[0] = report_id;
    354349        }
    355350
     
    357352        report_des = usb_hid_report_find_description(report, report_id,
    358353            USB_HID_REPORT_TYPE_OUTPUT);
    359        
     354
    360355        if (report_des == NULL) {
    361356                return EINVAL;
    362357        }
    363358
    364         usb_hid_report_field_t *report_item;
    365 
    366         list_foreach(report_des->report_items, item) {
    367                 report_item = list_get_instance(item, usb_hid_report_field_t,
    368                     ritems_link);
    369 
     359        list_foreach(report_des->report_items, ritems_link,
     360            usb_hid_report_field_t, report_item) {
    370361                value = usb_hid_translate_data_reverse(report_item,
    371362                    report_item->value);
     
    373364                offset = report_des->bit_length - report_item->offset - 1;
    374365                length = report_item->size;
    375                
     366
    376367                usb_log_debug("\ttranslated value: %x\n", value);
    377368
     
    382373                        }
    383374                        size_t shift = 8 - offset % 8 - length;
    384                         value = value << shift;                                                 
     375                        value = value << shift;
    385376                        value = value & (((1 << length) - 1) << shift);
    386                                
     377
    387378                        uint8_t mask = 0;
    388379                        mask = 0xff - (((1 << length) - 1) << shift);
     
    400391
    401392                                        tmp_value = tmp_value << (offset % 8);
    402        
     393
    403394                                        mask = ~(((1 << (8 - (offset % 8))) - 1)
    404395                                            << (offset % 8));
     
    407398                                            tmp_value;
    408399                                } else if (i == ((offset + length - 1) / 8)) {
    409                                        
     400
    410401                                        value = value >> (length -
    411402                                            ((offset + length) % 8));
     
    413404                                        value = value & ((1 << (length -
    414405                                            ((offset + length) % 8))) - 1);
    415                                
     406
    416407                                        mask = (1 << (length -
    417408                                            ((offset + length) % 8))) - 1;
     
    427418                report_item->value = 0;
    428419        }
    429        
     420
    430421        return EOK;
    431422}
  • uspace/lib/usbhid/src/hidpath.c

    re8d6ce2 rfeeac0d  
    176176        usb_log_debug("\tLENGTH: %d\n", path->depth);
    177177
    178         usb_hid_report_usage_path_t *path_item;
    179 
    180         list_foreach(path->items, item) {
    181                 path_item = list_get_instance(item, usb_hid_report_usage_path_t,
    182                         rpath_items_link);
     178        list_foreach(path->items, rpath_items_link,
     179            usb_hid_report_usage_path_t, path_item) {
    183180
    184181                usb_log_debug("\tUSAGE_PAGE: %X\n", path_item->usage_page);
     
    237234                        usb_hid_report_usage_path_t, rpath_items_link);
    238235
    239                 list_foreach(report_path->items, report_link) {
    240                         report_item = list_get_instance(report_link,
    241                                 usb_hid_report_usage_path_t, rpath_items_link);
    242                                
     236                list_foreach(report_path->items, rpath_items_link,
     237                    usb_hid_report_usage_path_t, report_item) {
     238
    243239                        if(USB_HID_SAME_USAGE_PAGE(report_item->usage_page,
    244240                                path_item->usage_page)){
    245                                        
     241
    246242                                if(only_page == 0){
    247243                                        if(USB_HID_SAME_USAGE(
    248244                                                report_item->usage,
    249245                                                path_item->usage)) {
    250                                                        
     246
    251247                                                return EOK;
    252248                                        }
     
    266262                        return 1;
    267263                }
    268                
     264
    269265        /* path is prefix of the report_path */
    270266        case USB_HID_PATH_COMPARE_BEGIN:
    271        
     267
    272268                report_link = report_path->items.head.next;
    273269                path_link = path->items.head.next;
    274                        
     270
    275271                while((report_link != &report_path->items.head) &&
    276272                      (path_link != &path->items.head)) {
    277                                          
     273
    278274                        report_item = list_get_instance(report_link,
    279275                                usb_hid_report_usage_path_t, rpath_items_link);
    280                                          
     276
    281277                        path_item = list_get_instance(path_link,
    282278                                usb_hid_report_usage_path_t, rpath_items_link);
     
    286282                            !USB_HID_SAME_USAGE(report_item->usage,
    287283                                path_item->usage))) {
    288                        
     284
    289285                                return 1;
    290                         }
    291                         else {
     286                        } else {
    292287                                report_link = report_link->next;
    293                                 path_link = path_link->next;                   
     288                                path_link = path_link->next;
    294289                        }
    295                        
    296290                }
    297291
     
    300294                   ((report_link == &report_path->items.head) &&
    301295                        (path_link == &path->items.head))) {
    302                                
     296
    303297                        return EOK;
    304298                }
     
    405399        usb_hid_report_path_t *usage_path)
    406400{
    407         usb_hid_report_usage_path_t *path_item;
    408401        usb_hid_report_usage_path_t *new_path_item;
    409402        usb_hid_report_path_t *new_usage_path = usb_hid_report_path ();
     
    419412        }
    420413
    421         list_foreach(usage_path->items, path_link) {
    422                 path_item = list_get_instance(path_link,
    423                         usb_hid_report_usage_path_t, rpath_items_link);
     414        list_foreach(usage_path->items, rpath_items_link,
     415            usb_hid_report_usage_path_t, path_item) {
    424416
    425417                new_path_item = malloc(sizeof(usb_hid_report_usage_path_t));
  • uspace/lib/usbhost/src/usb_endpoint_manager.c

    re8d6ce2 rfeeac0d  
    9090        if (address < 0)
    9191                return NULL;
    92         list_foreach(*get_list(instance, address), iterator) {
    93                 endpoint_t *ep = endpoint_get_instance(iterator);
     92        list_foreach(*get_list(instance, address), link, endpoint_t, ep) {
    9493                if (ep_match(ep, address, endpoint, direction))
    9594                        return ep;
     
    196195                        fibril_mutex_lock(&instance->guard);
    197196                        /* endpoint number is < 16, thus first byte is enough */
    198                         list_foreach(*get_list(instance, target.address), it) {
    199                                 endpoint_t *ep = endpoint_get_instance(it);
     197                        list_foreach(*get_list(instance, target.address),
     198                            link, endpoint_t, ep) {
    200199                                if ((ep->address == target.address)
    201200                                    && (ep->endpoint = data[4])) {
     
    216215                if ((data[0] & 0xf) == 0) {
    217216                        fibril_mutex_lock(&instance->guard);
    218                         list_foreach(*get_list(instance, target.address), it) {
    219                                 endpoint_t *ep = endpoint_get_instance(it);
     217                        list_foreach(*get_list(instance, target.address),
     218                            link, endpoint_t, ep) {
    220219                                if (ep->address == target.address) {
    221220                                        endpoint_toggle_set(ep,0);
     
    408407    usb_address_t address, void (*callback)(endpoint_t *, void *), void *arg)
    409408{
     409        list_t *list;
     410        link_t *link;
     411        link_t *next;
     412
    410413        assert(address >= 0);
    411414        assert(instance);
    412415        fibril_mutex_lock(&instance->guard);
    413         list_foreach(*get_list(instance, address), iterator) {
    414                 endpoint_t *ep = endpoint_get_instance(iterator);
     416
     417        list = get_list(instance, address);
     418        link = list_first(list);
     419        while (link != NULL) {
     420                endpoint_t *ep = list_get_instance(link, endpoint_t, link);
     421                next = list_next(link, list);
     422
    415423                if (ep->address == address) {
    416                         iterator = iterator->next;
    417424                        list_remove(&ep->link);
    418425                        if (callback)
     
    420427                        endpoint_destroy(ep);
    421428                }
     429                link = next;
    422430        }
    423431        fibril_mutex_unlock(&instance->guard);
Note: See TracChangeset for help on using the changeset viewer.