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

Changeset 0255d36 in mainline


Ignore:
Timestamp:
2011-11-28T17:07:51Z (10 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
69b9740
Parents:
d085fbbe
Message:

libusbdev: Minor refactoring of alternate interfaces.

File:
1 edited

Legend:

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

    rd085fbbe r0255d36  
    6565        size_t alternate_count = 0;
    6666
    67         const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    68             &dp_data, config_descr);
     67        const void *iface_ptr =
     68            usb_dp_get_nested_descriptor(&dp_parser, &dp_data, config_descr);
    6969        while (iface_ptr != NULL) {
    70                 usb_standard_interface_descriptor_t *iface
    71                     = (usb_standard_interface_descriptor_t *) iface_ptr;
    72                 if (iface->descriptor_type == USB_DESCTYPE_INTERFACE) {
    73                         if (iface->interface_number == interface_no) {
    74                                 alternate_count++;
    75                         }
     70                const usb_standard_interface_descriptor_t *iface = iface_ptr;
     71                if (iface->descriptor_type == USB_DESCTYPE_INTERFACE
     72                    && iface->interface_number == interface_no) {
     73                        ++alternate_count;
    7674                }
    7775                iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
     
    8280}
    8381
    84 /** Create alternate interface representation structure.
     82/** Initialize alternate interface representation structure.
    8583 *
     84 * @param[in] alternates Pointer to allocated structure.
    8685 * @param[in] config_descr Configuration descriptor.
    8786 * @param[in] config_descr_size Size of configuration descriptor.
    8887 * @param[in] interface_number Interface number.
    89  * @param[out] alternates_ptr Where to store pointer to allocated structure.
    9088 * @return Error code.
    9189 */
     
    10199        alternates->current = 0;
    102100
     101        /* No interfaces. */
    103102        if (interface_number < 0) {
    104103                return EOK;
     
    107106        alternates->alternative_count
    108107            = usb_interface_count_alternates(config_descr, config_descr_size,
    109             interface_number);
     108                interface_number);
    110109
    111110        if (alternates->alternative_count == 0) {
     
    131130            = &alternates->alternatives[0];
    132131
    133         const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,
    134             &dp_data, dp_data.data);
     132        const void *iface_ptr =
     133            usb_dp_get_nested_descriptor(&dp_parser, &dp_data, dp_data.data);
     134
    135135        while (iface_ptr != NULL) {
    136                 usb_standard_interface_descriptor_t *iface
    137                     = (usb_standard_interface_descriptor_t *) iface_ptr;
     136                const usb_standard_interface_descriptor_t *iface = iface_ptr;
     137
    138138                if ((iface->descriptor_type != USB_DESCTYPE_INTERFACE)
    139139                    || (iface->interface_number != interface_number)) {
     140                        /* This is not a valid alternate interface descriptor
     141                         * for interface with number == interface_number. */
    140142                        iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser,
    141143                            &dp_data, dp_data.data, iface_ptr);
     
    149151                iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    150152                    dp_data.data, iface_ptr);
    151                 if (iface_ptr == NULL) {
    152                         const uint8_t *next = dp_data.data + dp_data.size;
    153                         cur_alt_iface->nested_descriptors_size
    154                             = next - cur_alt_iface->nested_descriptors;
    155                 } else {
    156                         cur_alt_iface->nested_descriptors_size
    157                             = iface_ptr - cur_alt_iface->nested_descriptors;
    158                 }
    159153
    160                 cur_alt_iface++;
     154                const uint8_t *next = (iface_ptr == NULL) ?
     155                    dp_data.data + dp_data.size : iface_ptr;
     156
     157                cur_alt_iface->nested_descriptors_size
     158                    = next - cur_alt_iface->nested_descriptors;
     159
     160                ++cur_alt_iface;
    161161        }
    162162
Note: See TracChangeset for help on using the changeset viewer.