Changes in uspace/lib/usbdev/src/altiface.c [160b75e:ab27e01] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbdev/src/altiface.c
r160b75e rab27e01 48 48 * @return Number of alternate interfaces for @p interface_no interface. 49 49 */ 50 size_t usb_interface_count_alternates( uint8_t *config_descr,50 size_t usb_interface_count_alternates(const uint8_t *config_descr, 51 51 size_t config_descr_size, uint8_t interface_no) 52 52 { … … 54 54 assert(config_descr_size > 0); 55 55 56 usb_dp_parser_t dp_parser = {56 const usb_dp_parser_t dp_parser = { 57 57 .nesting = usb_dp_standard_descriptor_nesting 58 58 }; 59 usb_dp_parser_data_t dp_data = {59 const usb_dp_parser_data_t dp_data = { 60 60 .data = config_descr, 61 61 .size = config_descr_size, … … 65 65 size_t alternate_count = 0; 66 66 67 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,67 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 68 68 &dp_data, config_descr); 69 69 while (iface_ptr != NULL) { … … 90 90 * @return Error code. 91 91 */ 92 int usb_alternate_interfaces_create(uint8_t *config_descr, 93 size_t config_descr_size, int interface_number, 94 usb_alternate_interfaces_t **alternates_ptr) 92 int usb_alternate_interfaces_init(usb_alternate_interfaces_t *alternates, 93 const uint8_t *config_descr, size_t config_descr_size, int interface_number) 95 94 { 96 assert(alternates _ptr!= NULL);95 assert(alternates != NULL); 97 96 assert(config_descr != NULL); 98 97 assert(config_descr_size > 0); 99 98 99 alternates->alternatives = NULL; 100 alternates->alternative_count = 0; 101 alternates->current = 0; 102 100 103 if (interface_number < 0) { 101 alternates_ptr = NULL;102 104 return EOK; 103 }104 105 usb_alternate_interfaces_t *alternates106 = malloc(sizeof(usb_alternate_interfaces_t));107 108 if (alternates == NULL) {109 return ENOMEM;110 105 } 111 106 … … 115 110 116 111 if (alternates->alternative_count == 0) { 117 free(alternates);118 112 return ENOENT; 119 113 } 120 114 121 alternates->alternatives = malloc(alternates->alternative_count122 *sizeof(usb_alternate_interface_descriptors_t));115 alternates->alternatives = calloc(alternates->alternative_count, 116 sizeof(usb_alternate_interface_descriptors_t)); 123 117 if (alternates->alternatives == NULL) { 124 free(alternates);125 118 return ENOMEM; 126 119 } 127 120 128 alternates->current = 0; 129 130 usb_dp_parser_t dp_parser = { 121 const usb_dp_parser_t dp_parser = { 131 122 .nesting = usb_dp_standard_descriptor_nesting 132 123 }; 133 usb_dp_parser_data_t dp_data = {124 const usb_dp_parser_data_t dp_data = { 134 125 .data = config_descr, 135 126 .size = config_descr_size, … … 140 131 = &alternates->alternatives[0]; 141 132 142 uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser,133 const uint8_t *iface_ptr = usb_dp_get_nested_descriptor(&dp_parser, 143 134 &dp_data, dp_data.data); 144 135 while (iface_ptr != NULL) { … … 148 139 || (iface->interface_number != interface_number)) { 149 140 iface_ptr = usb_dp_get_sibling_descriptor(&dp_parser, 150 &dp_data, 151 dp_data.data, iface_ptr); 141 &dp_data, dp_data.data, iface_ptr); 152 142 continue; 153 143 } … … 160 150 dp_data.data, iface_ptr); 161 151 if (iface_ptr == NULL) { 162 uint8_t *next = dp_data.data + dp_data.size;152 const uint8_t *next = dp_data.data + dp_data.size; 163 153 cur_alt_iface->nested_descriptors_size 164 154 = next - cur_alt_iface->nested_descriptors; … … 171 161 } 172 162 173 *alternates_ptr = alternates;174 175 163 return EOK; 176 164 } 177 165 178 166 void usb_alternate_interfaces_deinit(usb_alternate_interfaces_t *alternate) 167 { 168 if (!alternate) 169 return; 170 free(alternate->alternatives); 171 } 179 172 /** 180 173 * @}
Note:
See TracChangeset
for help on using the changeset viewer.