Ignore:
Timestamp:
2011-11-10T11:29:10Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
54464f6a, c2245a3, c6f189f7
Parents:
2e1b9dc (diff), 2d1ba51 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge USB changes.

Interface changes:

  • GET_ADDRESS has been renamed to GET_MY_ADDRESS and the handle parameter was dropped. Tis call no longer cascades up to the root hub, but it is answered in the first place the information is available (nearest hub)
  • Reintroduced address reservation for USB_DEFAULT_ADDRESS. The interface now enables device drivers to request specific address on initialization and either insists on that address or accept any other if the address is not available. Note that it is not possible to get the default address if the driver does not insist.
  • Any endpoint registered is removed when address is released and a warning is produced if there were any such endpoints.
  • It is no longer necessary or possible to pass device speed information when registering endpoints.

Driver fixes: memory leaks and crashes (not only) in error paths.
Fixes or removes flaky device_remove implementation in device drivers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhid/generic/hiddev.c

    r2e1b9dc r747ef72  
    6161
    6262/*----------------------------------------------------------------------------*/
    63 
    6463static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun);
    65 
    66 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     64static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
    6765    size_t size, size_t *act_size, int *event_nr, unsigned int flags);
    68 
    6966static int usb_generic_hid_client_connected(ddf_fun_t *fun);
    70 
    7167static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun);
    72 
    73 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     68static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
    7469    size_t size, size_t *actual_size);
    75 
    76 /*----------------------------------------------------------------------------*/
    77 
     70/*----------------------------------------------------------------------------*/
    7871static usbhid_iface_t usb_generic_iface = {
    7972        .get_event = usb_generic_hid_get_event,
     
    8275        .get_report_descriptor = usb_generic_get_report_descriptor
    8376};
    84 
     77/*----------------------------------------------------------------------------*/
    8578static ddf_dev_ops_t usb_generic_hid_ops = {
    8679        .interfaces[USBHID_DEV_IFACE] = &usb_generic_iface,
    8780        .open = usb_generic_hid_client_connected
    8881};
    89 
    90 /*----------------------------------------------------------------------------*/
    91 
     82/*----------------------------------------------------------------------------*/
    9283static size_t usb_generic_hid_get_event_length(ddf_fun_t *fun)
    9384{
     
    9990        }
    10091
    101         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     92        const usb_hid_dev_t *hid_dev = fun->driver_data;
    10293
    10394        usb_log_debug2("hid_dev: %p, Max input report size (%zu).\n",
     
    10697        return hid_dev->max_input_report_size;
    10798}
    108 
    109 /*----------------------------------------------------------------------------*/
    110 
    111 static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
     99/*----------------------------------------------------------------------------*/
     100static int usb_generic_hid_get_event(ddf_fun_t *fun, uint8_t *buffer,
    112101    size_t size, size_t *act_size, int *event_nr, unsigned int flags)
    113102{
     
    120109        }
    121110
    122         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     111        const usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    123112
    124113        if (hid_dev->input_report_size > size) {
    125                 usb_log_debug("input_report_size > size (%zu, %zu)\n", 
     114                usb_log_debug("input_report_size > size (%zu, %zu)\n",
    126115                    hid_dev->input_report_size, size);
    127116                return EINVAL;  // TODO: other error code
     
    129118
    130119        /*! @todo This should probably be somehow atomic. */
    131         memcpy(buffer, hid_dev->input_report, 
     120        memcpy(buffer, hid_dev->input_report,
    132121            hid_dev->input_report_size);
    133122        *act_size = hid_dev->input_report_size;
     
    138127        return EOK;
    139128}
    140 
    141 /*----------------------------------------------------------------------------*/
    142 
     129/*----------------------------------------------------------------------------*/
    143130static size_t usb_generic_get_report_descriptor_length(ddf_fun_t *fun)
    144131{
     
    150137        }
    151138
    152         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
    153 
    154         usb_log_debug2("hid_dev->report_desc_size = %zu\n", 
     139        const usb_hid_dev_t *hid_dev = fun->driver_data;
     140
     141        usb_log_debug2("hid_dev->report_desc_size = %zu\n",
    155142            hid_dev->report_desc_size);
    156143
    157144        return hid_dev->report_desc_size;
    158145}
    159 
    160 /*----------------------------------------------------------------------------*/
    161 
    162 static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
     146/*----------------------------------------------------------------------------*/
     147static int usb_generic_get_report_descriptor(ddf_fun_t *fun, uint8_t *desc,
    163148    size_t size, size_t *actual_size)
    164149{
     
    170155        }
    171156
    172         usb_hid_dev_t *hid_dev = (usb_hid_dev_t *)fun->driver_data;
     157        const usb_hid_dev_t *hid_dev = fun->driver_data;
    173158
    174159        if (hid_dev->report_desc_size > size) {
     
    181166        return EOK;
    182167}
    183 
    184 /*----------------------------------------------------------------------------*/
    185 
     168/*----------------------------------------------------------------------------*/
    186169static int usb_generic_hid_client_connected(ddf_fun_t *fun)
    187170{
     
    189172        return EOK;
    190173}
    191 
    192 /*----------------------------------------------------------------------------*/
    193 
     174/*----------------------------------------------------------------------------*/
    194175void usb_generic_hid_deinit(usb_hid_dev_t *hid_dev, void *data)
    195176{
    196177        ddf_fun_t *fun = data;
    197         const int ret = ddf_fun_unbind(fun);
    198         if (ret != EOK) {
     178        if (fun == NULL)
     179                return;
     180
     181        if (ddf_fun_unbind(fun) != EOK) {
    199182                usb_log_error("Failed to unbind generic hid fun.\n");
    200183                return;
     
    206189        ddf_fun_destroy(fun);
    207190}
    208 
    209 /*----------------------------------------------------------------------------*/
    210 
     191/*----------------------------------------------------------------------------*/
    211192int usb_generic_hid_init(usb_hid_dev_t *hid_dev, void **data)
    212193{
     
    216197
    217198        /* Create the exposed function. */
    218         /** @todo Generate numbers for the devices? */
    219199        usb_log_debug("Creating DDF function %s...\n", HID_GENERIC_FUN_NAME);
    220200        ddf_fun_t *fun = ddf_fun_create(hid_dev->usb_dev->ddf_dev, fun_exposed,
     
    225205        }
    226206
     207        /* This is nasty, both device and this function have the same
     208         * driver data, thus destruction causes to double free */
     209        fun->driver_data = hid_dev;
    227210        fun->ops = &usb_generic_hid_ops;
    228211
     
    231214                usb_log_error("Could not bind DDF function: %s.\n",
    232215                    str_error(rc));
     216                fun->driver_data = NULL;
    233217                ddf_fun_destroy(fun);
    234218                return rc;
    235219        }
    236         /* This is nasty both device and this function have the same
    237          * driver data, thus destruction would lead to double free */
    238         fun->driver_data = hid_dev;
    239220
    240221        usb_log_debug("HID function created. Handle: %" PRIun "\n", fun->handle);
     
    243224        return EOK;
    244225}
    245 
    246 /*----------------------------------------------------------------------------*/
    247 
     226/*----------------------------------------------------------------------------*/
    248227bool usb_generic_hid_polling_callback(usb_hid_dev_t *hid_dev, void *data)
    249228{
    250229        return true;
    251230}
    252 
    253231/**
    254232 * @}
Note: See TracChangeset for help on using the changeset viewer.