Changeset f527f58 in mainline for uspace/lib/usbhost/src/usb_bus.c


Ignore:
Timestamp:
2016-08-03T11:12:24Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
96ef672
Parents:
e657635
Message:

Reference-count endpoint_t structures

Track explicit references to USB endpoints. Call endpoint_destroy()
only after the last reference is destroyed. This prevents the scenario
in which removal was attempted on an endpoint while there was a transfer
in progress.

File:
1 edited

Legend:

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

    re657635 rf527f58  
    242242                return EEXIST;
    243243        }
     244        /* Add endpoint list's reference to ep. */
     245        endpoint_add_ref(ep);
    244246        list_append(&ep->link, get_list(instance, ep->address));
    245247
     
    274276            ep->endpoint, usb_str_transfer_type_short(ep->transfer_type),
    275277            usb_str_direction(ep->direction));
     278        /* Drop endpoint list's reference to ep. */
     279        endpoint_del_ref(ep);
    276280        fibril_mutex_unlock(&instance->guard);
    277281        return EOK;
     
    289293        fibril_mutex_lock(&instance->guard);
    290294        endpoint_t *ep = find_locked(instance, address, endpoint, direction);
     295        if (ep) {
     296                /* We are exporting ep to the outside world, add reference. */
     297                endpoint_add_ref(ep);
     298        }
    291299        fibril_mutex_unlock(&instance->guard);
    292300        return ep;
     
    350358        }
    351359
     360        /* Add our reference to ep. */
     361        endpoint_add_ref(ep);
     362
    352363        if (callback) {
    353364                const int ret = callback(ep, arg);
    354365                if (ret != EOK) {
    355366                        fibril_mutex_unlock(&instance->guard);
    356                         endpoint_destroy(ep);
     367                        endpoint_del_ref(ep);
    357368                        return ret;
    358369                }
    359370        }
     371       
     372        /* Add endpoint list's reference to ep. */
     373        endpoint_add_ref(ep);
    360374        list_append(&ep->link, get_list(instance, ep->address));
    361375
    362376        instance->free_bw -= ep->bandwidth;
    363377        fibril_mutex_unlock(&instance->guard);
     378
     379        /* Drop our reference to ep. */
     380        endpoint_del_ref(ep);
     381
    364382        return EOK;
    365383}
     
    392410                callback(ep, arg);
    393411        }
    394         endpoint_destroy(ep);
     412        /* Drop endpoint list's reference to ep. */
     413        endpoint_del_ref(ep);
    395414        return EOK;
    396415}
     
    445464                        if (callback)
    446465                                callback(ep, arg);
    447                         endpoint_destroy(ep);
     466                        /* Drop endpoint list's reference to ep. */
     467                        endpoint_del_ref(ep);
    448468                }
    449469        }
Note: See TracChangeset for help on using the changeset viewer.