Changeset ab27e01 in mainline


Ignore:
Timestamp:
2011-11-05T14:58: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:
b77931d
Parents:
7fc260ff
Message:

liibusbdev: Consider alternate interface when initializing pipes.

Location:
uspace/lib/usbdev/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/altiface.c

    r7fc260ff rab27e01  
    139139                    || (iface->interface_number != interface_number)) {
    140140                        iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser,
    141                             &dp_data,
    142                             dp_data.data, iface_ptr);
     141                            &dp_data, dp_data.data, iface_ptr);
    143142                        continue;
    144143                }
  • uspace/lib/usbdev/src/devdrv.c

    r7fc260ff rab27e01  
    8181 * @return Number of pipes (excluding default control pipe).
    8282 */
    83 static size_t count_other_pipes(const usb_endpoint_description_t **endpoints)
    84 {
    85         size_t count = 0;
    86         if (endpoints == NULL) {
    87                 return 0;
    88         }
    89 
    90         while (endpoints[count] != NULL) {
    91                 count++;
    92         }
    93 
     83static inline size_t count_other_pipes(
     84    const usb_endpoint_description_t **endpoints)
     85{
     86        size_t count;
     87        for (count = 0; endpoints && endpoints[count] != NULL; ++count);
    9488        return count;
    9589}
     
    10498    usb_device_t *dev, int alternate_setting)
    10599{
     100        assert(dev);
     101
    106102        if (endpoints == NULL) {
    107103                dev->pipes = NULL;
     
    330326 *      (not NULL terminated).
    331327 * @param[out] pipes_count_ptr Where to store number of pipes
    332  *      (set to if you wish to ignore the count).
     328 *      (set to NULL if you wish to ignore the count).
    333329 * @return Error code.
    334330 */
     
    351347        const size_t pipe_count = count_other_pipes(endpoints);
    352348        if (pipe_count == 0) {
    353                 *pipes_count_ptr = pipe_count;
     349                if (pipes_count_ptr)
     350                        *pipes_count_ptr = pipe_count;
    354351                *pipes_ptr = NULL;
    355352                return EOK;
     
    357354
    358355        usb_endpoint_mapping_t *pipes
    359             = malloc(sizeof(usb_endpoint_mapping_t) * pipe_count);
     356            = calloc(pipe_count, sizeof(usb_endpoint_mapping_t));
    360357        if (pipes == NULL) {
    361358                return ENOMEM;
    362         }
    363 
    364         /* Initialize to NULL to allow smooth rollback. */
    365         for (i = 0; i < pipe_count; i++) {
    366                 pipes[i].pipe = NULL;
    367359        }
    368360
     
    409401
    410402        if (usb_hc_connection_close(&hc_conn) != EOK)
    411                 usb_log_warning("usb_device_create_pipes(): "
    412                     "Failed to close connection.\n");
     403                usb_log_warning("%s: Failed to close connection.\n",
     404                    __FUNCTION__);
    413405
    414406        *pipes_ptr = pipes;
     
    556548         * it makes no sense to speak about alternate interfaces when
    557549         * controlling a device. */
    558         usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
     550        rc = usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
    559551            usb_dev->descriptors.configuration,
    560552            usb_dev->descriptors.configuration_size, usb_dev->interface_no);
     553        const int alternate_iface =
     554            (rc == EOK) ? usb_dev->alternate_interfaces.current : 0;
    561555
    562556        /* TODO Add comment here. */
    563         rc = initialize_other_pipes(endpoints, usb_dev, 0);
     557        rc = initialize_other_pipes(endpoints, usb_dev, alternate_iface);
    564558        if (rc != EOK) {
    565559                /* Full configuration descriptor is allocated. */
Note: See TracChangeset for help on using the changeset viewer.