Ignore:
File:
1 edited

Legend:

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

    r563d9d0a r3e4f2e0  
    3535
    3636#include <assert.h>
    37 #include <stdlib.h>
    3837#include <errno.h>
    3938#include <usb/host/endpoint.h>
    4039
    41 endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
    42     usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
    43     size_t max_packet_size)
     40int endpoint_init(endpoint_t *instance, usb_address_t address,
     41    usb_endpoint_t endpoint, usb_direction_t direction,
     42    usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size)
    4443{
    45         endpoint_t *instance = malloc(sizeof(endpoint_t));
    46         if (instance) {
    47                 instance->address = address;
    48                 instance->endpoint = endpoint;
    49                 instance->direction = direction;
    50                 instance->transfer_type = type;
    51                 instance->speed = speed;
    52                 instance->max_packet_size = max_packet_size;
    53                 instance->toggle = 0;
    54                 instance->active = false;
    55                 instance->destroy_hook = NULL;
    56                 instance->hc_data.data = NULL;
    57                 instance->hc_data.toggle_get = NULL;
    58                 instance->hc_data.toggle_set = NULL;
    59                 fibril_mutex_initialize(&instance->guard);
    60                 fibril_condvar_initialize(&instance->avail);
    61                 endpoint_clear_hc_data(instance);
    62         }
    63         return instance;
     44        assert(instance);
     45        instance->address = address;
     46        instance->endpoint = endpoint;
     47        instance->direction = direction;
     48        instance->transfer_type = type;
     49        instance->speed = speed;
     50        instance->max_packet_size = max_packet_size;
     51        instance->toggle = 0;
     52        instance->active = false;
     53        fibril_mutex_initialize(&instance->guard);
     54        fibril_condvar_initialize(&instance->avail);
     55        endpoint_clear_hc_data(instance);
     56        return EOK;
    6457}
    6558/*----------------------------------------------------------------------------*/
     
    6861        assert(instance);
    6962        assert(!instance->active);
    70         if (instance->hc_data.data) {
    71                 assert(instance->destroy_hook);
    72                 instance->destroy_hook(instance);
    73         }
    7463        free(instance);
    7564}
    7665/*----------------------------------------------------------------------------*/
    7766void endpoint_set_hc_data(endpoint_t *instance,
    78     void *data, void (*destroy_hook)(endpoint_t *),
    79     int (*toggle_get)(void *), void (*toggle_set)(void *, int))
     67    void *data, int (*toggle_get)(void *), void (*toggle_set)(void *, int))
    8068{
    8169        assert(instance);
    82         instance->destroy_hook = destroy_hook;
    8370        instance->hc_data.data = data;
    8471        instance->hc_data.toggle_get = toggle_get;
     
    8976{
    9077        assert(instance);
    91         instance->destroy_hook = NULL;
    9278        instance->hc_data.data = NULL;
    9379        instance->hc_data.toggle_get = NULL;
Note: See TracChangeset for help on using the changeset viewer.