Ignore:
Timestamp:
2011-09-07T10:17:00Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7099861
Parents:
52eead3e
Message:

libusbhost: minor cleanup and fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/usb_endpoint_manager.c

    r52eead3e r563d9d0a  
    146146        fibril_condvar_initialize(&instance->change);
    147147        instance->free_bw = available_bandwidth;
    148         bool ht =
     148        const bool ht =
    149149            hash_table_create(&instance->ep_table, BUCKET_COUNT, MAX_KEYS, &op);
    150150        return ht ? EOK : ENOMEM;
     
    160160{
    161161        assert(ep);
    162         size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
     162        const size_t bw = bandwidth_count_usb11(ep->speed, ep->transfer_type,
    163163            data_size, ep->max_packet_size);
    164164        assert(instance);
     165
     166        fibril_mutex_lock(&instance->guard);
     167
     168        if (bw > instance->free_bw) {
     169                fibril_mutex_unlock(&instance->guard);
     170                return ENOSPC;
     171        }
    165172
    166173        unsigned long key[MAX_KEYS] =
    167174            {ep->address, ep->endpoint, ep->direction};
    168         fibril_mutex_lock(&instance->guard);
    169 
    170         link_t *item =
     175
     176        const link_t *item =
    171177            hash_table_find(&instance->ep_table, key);
    172178        if (item != NULL) {
    173179                fibril_mutex_unlock(&instance->guard);
    174180                return EEXISTS;
    175         }
    176 
    177         if (bw > instance->free_bw) {
    178                 fibril_mutex_unlock(&instance->guard);
    179                 return ENOSPC;
    180181        }
    181182
     
    211212
    212213        node_t *node = hash_table_get_instance(item, node_t, link);
    213         if (node->ep->active)
     214        if (node->ep->active) {
     215                fibril_mutex_unlock(&instance->guard);
    214216                return EBUSY;
     217        }
    215218
    216219        instance->free_bw += node->bw;
     
    230233
    231234        fibril_mutex_lock(&instance->guard);
    232         link_t *item = hash_table_find(&instance->ep_table, key);
     235        const link_t *item = hash_table_find(&instance->ep_table, key);
    233236        if (item == NULL) {
    234237                fibril_mutex_unlock(&instance->guard);
    235238                return NULL;
    236239        }
    237         node_t *node = hash_table_get_instance(item, node_t, link);
     240        const node_t *node = hash_table_get_instance(item, node_t, link);
    238241        if (bw)
    239242                *bw = node->bw;
     
    255258{
    256259        assert(instance);
    257         if (target.endpoint > 15 || target.endpoint < 0
    258             || target.address >= USB11_ADDRESS_MAX || target.address < 0) {
     260        if (!usb_target_is_valid(target)) {
    259261                usb_log_error("Invalid data when checking for toggle reset.\n");
    260262                return;
    261263        }
    262264
     265        assert(data);
    263266        switch (data[1])
    264267        {
    265         case 0x01: /*clear feature*/
    266                 /* recipient is endpoint, value is zero (ENDPOINT_STALL) */
     268        case 0x01: /* Clear Feature -- resets only cleared ep */
     269                /* Recipient is endpoint, value is zero (ENDPOINT_STALL) */
    267270                if (((data[0] & 0xf) == 1) && ((data[2] | data[3]) == 0)) {
    268271                        /* endpoint number is < 16, thus first byte is enough */
     
    276279        break;
    277280
    278         case 0x9: /* set configuration */
    279         case 0x11: /* set interface */
    280                 /* target must be device */
     281        case 0x9: /* Set Configuration */
     282        case 0x11: /* Set Interface */
     283                /* Recipient must be device */
    281284                if ((data[0] & 0xf) == 0) {
    282285                        usb_target_t reset_target =
Note: See TracChangeset for help on using the changeset viewer.