Changeset 904dcc6 in mainline


Ignore:
Timestamp:
2011-11-05T13:54:01Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7fc260ff
Parents:
99a1a56
Message:

libusbdev: Convert usb_alternate_interfaces_t interrface to init/deinit.

Location:
uspace/lib/usbdev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r99a1a56 r904dcc6  
    8787        int interface_no;
    8888
    89         /** Alternative interfaces.
    90          * Set to NULL when the driver controls whole device
    91          * (i.e. more (or any) interfaces).
    92          */
    93         usb_alternate_interfaces_t *alternate_interfaces;
     89        /** Alternative interfaces. */
     90        usb_alternate_interfaces_t alternate_interfaces;
    9491
    9592        /** Some useful descriptors. */
     
    178175
    179176size_t usb_interface_count_alternates(const uint8_t *, size_t, uint8_t);
    180 int usb_alternate_interfaces_create(const uint8_t *, size_t, int,
    181     usb_alternate_interfaces_t **);
    182 void usb_alternate_interfaces_destroy(usb_alternate_interfaces_t *);
     177int usb_alternate_interfaces_init(usb_alternate_interfaces_t *,
     178    const uint8_t *, size_t, int);
     179void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *);
    183180#endif
    184181/**
  • uspace/lib/usbdev/src/altiface.c

    r99a1a56 r904dcc6  
    9090 * @return Error code.
    9191 */
    92 int usb_alternate_interfaces_create(const uint8_t *config_descr,
    93     size_t config_descr_size, int interface_number,
    94     usb_alternate_interfaces_t **alternates_ptr)
     92int usb_alternate_interfaces_init(usb_alternate_interfaces_t *alternates,
     93    const uint8_t *config_descr, size_t config_descr_size, int interface_number)
    9594{
    96         assert(alternates_ptr != NULL);
     95        assert(alternates != NULL);
    9796        assert(config_descr != NULL);
    9897        assert(config_descr_size > 0);
    9998
    100         *alternates_ptr = NULL;
     99        alternates->alternatives = NULL;
     100        alternates->alternative_count = 0;
     101        alternates->current = 0;
     102
    101103        if (interface_number < 0) {
    102104                return EOK;
    103         }
    104 
    105         usb_alternate_interfaces_t *alternates
    106             = malloc(sizeof(usb_alternate_interfaces_t));
    107         if (alternates == NULL) {
    108                 return ENOMEM;
    109105        }
    110106
     
    114110
    115111        if (alternates->alternative_count == 0) {
    116                 free(alternates);
    117112                return ENOENT;
    118113        }
     
    121116            sizeof(usb_alternate_interface_descriptors_t));
    122117        if (alternates->alternatives == NULL) {
    123                 free(alternates);
    124118                return ENOMEM;
    125119        }
    126120
    127         alternates->current = 0;
    128 
    129         usb_dp_parser_t dp_parser = {
     121        const usb_dp_parser_t dp_parser = {
    130122                .nesting = usb_dp_standard_descriptor_nesting
    131123        };
    132         usb_dp_parser_data_t dp_data = {
     124        const usb_dp_parser_data_t dp_data = {
    133125                .data = config_descr,
    134126                .size = config_descr_size,
     
    170162        }
    171163
    172         *alternates_ptr = alternates;
    173 
    174164        return EOK;
    175165}
    176166
    177 void usb_alternate_interfaces_destroy(usb_alternate_interfaces_t *alternate)
     167void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate)
    178168{
    179169        if (!alternate)
    180170                return;
    181171        free(alternate->alternatives);
    182         free(alternate);
    183172}
    184173/**
  • uspace/lib/usbdev/src/devdrv.c

    r99a1a56 r904dcc6  
    536536        usb_dev->driver_data = NULL;
    537537        usb_dev->descriptors.configuration = NULL;
    538         usb_dev->alternate_interfaces = NULL;
    539538        usb_dev->pipes_count = 0;
    540539        usb_dev->pipes = NULL;
     
    560559        /* Create alternate interfaces. We will silently ignore failure. */
    561560        //TODO Why ignore?
    562         usb_alternate_interfaces_create(usb_dev->descriptors.configuration,
    563             usb_dev->descriptors.configuration_size, usb_dev->interface_no,
    564             &usb_dev->alternate_interfaces);
     561        usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
     562            usb_dev->descriptors.configuration,
     563            usb_dev->descriptors.configuration_size, usb_dev->interface_no);
    565564
    566565        rc = initialize_other_pipes(endpoints, usb_dev, 0);
     
    569568                free(usb_dev->descriptors.configuration);
    570569                /* Alternate interfaces may be allocated */
    571                 usb_alternate_interfaces_destroy(usb_dev->alternate_interfaces);
     570                usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
    572571                *errstr_ptr = "pipes initialization";
    573572                return rc;
     
    591590                destroy_current_pipes(dev);
    592591
    593                 usb_alternate_interfaces_destroy(dev->alternate_interfaces);
     592                usb_alternate_interfaces_deinit(&dev->alternate_interfaces);
    594593                free(dev->descriptors.configuration);
    595594                free(dev->driver_data);
Note: See TracChangeset for help on using the changeset viewer.