Changeset d70e0a3c in mainline for uspace/drv/usbhid/hiddev.c


Ignore:
Timestamp:
2011-03-02T18:17:27Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a6567ed
Parents:
4723444
Message:

Allocating "get full config desc" put into action

Yes, all that removed code is now replaced with a single function.
And yes, it was the same in all drivers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/hiddev.c

    r4723444 rd70e0a3c  
    149149        usb_log_info("Processing descriptors...\n");
    150150       
    151         // get the first configuration descriptor
    152         usb_standard_configuration_descriptor_t config_desc;
    153        
    154151        int rc;
    155         rc = usb_request_get_bare_configuration_descriptor(&hid_dev->ctrl_pipe,
    156             0, &config_desc);
    157        
    158         if (rc != EOK) {
    159                 usb_log_error("Failed to get bare config descriptor: %s.\n",
     152
     153        uint8_t *descriptors = NULL;
     154        size_t descriptors_size;
     155        rc = usb_request_get_full_configuration_descriptor_alloc(
     156            &hid_dev->ctrl_pipe, 0, (void **) &descriptors, &descriptors_size);
     157        if (rc != EOK) {
     158                usb_log_error("Failed to retrieve config descriptor: %s.\n",
    160159                    str_error(rc));
    161160                return rc;
    162         }
    163        
    164         // prepare space for all underlying descriptors
    165         uint8_t *descriptors = (uint8_t *)malloc(config_desc.total_length);
    166         if (descriptors == NULL) {
    167                 usb_log_error("No memory!.\n");
    168                 return ENOMEM;
    169         }
    170        
    171         size_t transferred = 0;
    172         // get full configuration descriptor
    173         rc = usb_request_get_full_configuration_descriptor(&hid_dev->ctrl_pipe,
    174             0, descriptors, config_desc.total_length, &transferred);
    175        
    176         if (rc != EOK) {
    177                 usb_log_error("Failed to get full config descriptor: %s.\n",
    178                     str_error(rc));
    179                 free(descriptors);
    180                 return rc;
    181         }
    182        
    183         if (transferred != config_desc.total_length) {
    184                 usb_log_error("Configuration descriptor has wrong size (%u, "
    185                     "expected %u).\n", transferred, config_desc.total_length);
    186                 free(descriptors);
    187                 return ELIMIT;
    188161        }
    189162       
     
    201174       
    202175        rc = usb_endpoint_pipe_initialize_from_configuration(
    203             endpoint_mapping, 1, descriptors, config_desc.total_length,
     176            endpoint_mapping, 1, descriptors, descriptors_size,
    204177            &hid_dev->wire);
    205178       
     
    233206        assert(endpoint_mapping[0].interface != NULL);
    234207       
    235         rc = usbhid_dev_get_report_descriptor(hid_dev, descriptors, transferred,
     208        rc = usbhid_dev_get_report_descriptor(hid_dev,
     209            descriptors, descriptors_size,
    236210            (uint8_t *)endpoint_mapping[0].interface);
    237211       
Note: See TracChangeset for help on using the changeset viewer.