Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset aa81adc in mainline


Ignore:
Timestamp:
2011-07-11T09:28:00Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
ece7f78
Parents:
1cb4f05
Message:

libusbhost: endpoint_t uses get/destroy pair, instead of init/destroy.

endpoint_init always returned EOK, thus allocation could be moved in.
Also, it makes no sense to create this structures on stack.

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/ohci/hc.c

    r1cb4f05 raa81adc  
    235235    size_t mps, size_t size, unsigned interval)
    236236{
    237         endpoint_t *ep = malloc(sizeof(endpoint_t));
     237        endpoint_t *ep =
     238            endpoint_get(address, endpoint, direction, type, speed, mps);
    238239        if (ep == NULL)
    239240                return ENOMEM;
    240         int ret =
    241             endpoint_init(ep, address, endpoint, direction, type, speed, mps);
    242         if (ret != EOK) {
    243                 free(ep);
    244                 return ret;
    245         }
    246241
    247242        hcd_endpoint_t *hcd_ep = hcd_endpoint_assign(ep);
     
    251246        }
    252247
    253         ret = usb_endpoint_manager_register_ep(&instance->ep_manager, ep, size);
     248        int ret =
     249            usb_endpoint_manager_register_ep(&instance->ep_manager, ep, size);
    254250        if (ret != EOK) {
    255251                hcd_endpoint_clear(ep);
     
    279275                    &instance->lists[ep->transfer_type], hcd_ep);
    280276                instance->registers->control |= C_PLE | C_IE;
    281                 break;
    282         default:
    283277                break;
    284278        }
  • uspace/drv/bus/usb/vhc/connhost.c

    r1cb4f05 raa81adc  
    141141    size_t max_packet_size, unsigned int interval)
    142142{
    143         VHC_DATA(vhc, fun);
    144 
    145         endpoint_t *ep = malloc(sizeof(endpoint_t));
     143        /* TODO: Use usb_endpoint_manager_add_ep */
     144        VHC_DATA(vhc, fun);
     145
     146        endpoint_t *ep = endpoint_get(
     147            address, endpoint, direction, transfer_type, USB_SPEED_FULL, 1);
    146148        if (ep == NULL) {
    147149                return ENOMEM;
    148150        }
    149151
    150         int rc = endpoint_init(ep, address, endpoint, direction, transfer_type,
    151             USB_SPEED_FULL, 1);
    152         if (rc != EOK) {
    153                 free(ep);
    154                 return rc;
    155         }
    156 
    157         rc = usb_endpoint_manager_register_ep(&vhc->ep_manager, ep, 1);
     152        int rc = usb_endpoint_manager_register_ep(&vhc->ep_manager, ep, 1);
    158153        if (rc != EOK) {
    159154                endpoint_destroy(ep);
  • uspace/lib/usbhost/include/usb/host/endpoint.h

    r1cb4f05 raa81adc  
    6161} endpoint_t;
    6262
    63 int endpoint_init(endpoint_t *instance, usb_address_t address,
    64     usb_endpoint_t endpoint, usb_direction_t direction,
    65     usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size);
     63endpoint_t * endpoint_get(usb_address_t address, usb_endpoint_t endpoint,
     64    usb_direction_t direction, usb_transfer_type_t type, usb_speed_t speed,
     65    size_t max_packet_size);
    6666
    6767void endpoint_destroy(endpoint_t *instance);
  • uspace/lib/usbhost/include/usb/host/usb_endpoint_manager.h

    r1cb4f05 raa81adc  
    8282    size_t data_size)
    8383{
    84         endpoint_t *ep = malloc(sizeof(endpoint_t));
    85         if (ep == NULL)
     84        endpoint_t *ep = endpoint_get(
     85            address, endpoint, direction, type, speed, max_packet_size);
     86        if (!ep)
    8687                return ENOMEM;
    8788
    88         int ret = endpoint_init(ep, address, endpoint, direction, type, speed,
    89             max_packet_size);
    90         if (ret != EOK) {
    91                 free(ep);
    92                 return ret;
    93         }
    94 
    95         ret = usb_endpoint_manager_register_ep(instance, ep, data_size);
     89        const int ret =
     90            usb_endpoint_manager_register_ep(instance, ep, data_size);
    9691        if (ret != EOK) {
    9792                endpoint_destroy(ep);
    98                 return ret;
    9993        }
    100         return EOK;
     94        return ret;
    10195}
    10296#endif
  • uspace/lib/usbhost/src/endpoint.c

    r1cb4f05 raa81adc  
    3939#include <usb/host/endpoint.h>
    4040
    41 int endpoint_init(endpoint_t *instance, usb_address_t address,
    42     usb_endpoint_t endpoint, usb_direction_t direction,
    43     usb_transfer_type_t type, usb_speed_t speed, size_t max_packet_size)
     41endpoint_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)
    4444{
    45         assert(instance);
    46         instance->address = address;
    47         instance->endpoint = endpoint;
    48         instance->direction = direction;
    49         instance->transfer_type = type;
    50         instance->speed = speed;
    51         instance->max_packet_size = max_packet_size;
    52         instance->toggle = 0;
    53         instance->active = false;
    54         fibril_mutex_initialize(&instance->guard);
    55         fibril_condvar_initialize(&instance->avail);
    56         endpoint_clear_hc_data(instance);
    57         return EOK;
     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                fibril_mutex_initialize(&instance->guard);
     56                fibril_condvar_initialize(&instance->avail);
     57                endpoint_clear_hc_data(instance);
     58        }
     59        return instance;
    5860}
    5961/*----------------------------------------------------------------------------*/
Note: See TracChangeset for help on using the changeset viewer.