Changeset e3f7418 in mainline for uspace/lib/usbdev/src/devdrv.c


Ignore:
Timestamp:
2011-10-15T13:06:28Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a044f71
Parents:
3958e315 (diff), 065064e6 (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:

USB improvements.

USB unplug part2; Unplug support in all drivers (except for unused usbmouse driver).
Make descriptor paring work on const pointers.
Fixes several crashes and memory leaks.

File:
1 edited

Legend:

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

    r3958e315 re3f7418  
    5454};
    5555
    56 static usb_driver_t *driver = NULL;
     56static const usb_driver_t *driver = NULL;
    5757
    5858
     
    115115        int rc = usb_device_create_pipes(dev->ddf_dev, &dev->wire, endpoints,
    116116            dev->descriptors.configuration, dev->descriptors.configuration_size,
    117             dev->interface_no, alternate_setting,
    118             &pipes, &pipes_count);
     117            dev->interface_no, alternate_setting, &pipes, &pipes_count);
    119118
    120119        if (rc != EOK) {
     
    153152        gen_dev->driver_data = dev;
    154153
    155         return driver->ops->device_add(dev);
     154        rc = driver->ops->device_add(dev);
     155        if (rc != EOK)
     156                usb_device_destroy(dev);
     157        return rc;
    156158}
    157159/*----------------------------------------------------------------------------*/
     
    186188        if (driver->ops->device_gone == NULL)
    187189                return ENOTSUP;
    188         const int ret = driver->ops->device_gone(gen_dev->driver_data);
     190        usb_device_t *usb_dev = gen_dev->driver_data;
     191        const int ret = driver->ops->device_gone(usb_dev);
    189192        if (ret == EOK)
    190                 usb_device_destroy(gen_dev->driver_data);
     193                usb_device_destroy(usb_dev);
    191194
    192195        return ret;
     
    319322int usb_device_create_pipes(const ddf_dev_t *dev, usb_device_connection_t *wire,
    320323    usb_endpoint_description_t **endpoints,
    321     uint8_t *config_descr, size_t config_descr_size,
     324    const uint8_t *config_descr, size_t config_descr_size,
    322325    int interface_no, int interface_setting,
    323326    usb_endpoint_mapping_t **pipes_ptr, size_t *pipes_count_ptr)
     
    333336        int rc;
    334337
    335         size_t pipe_count = count_other_pipes(endpoints);
     338        const size_t pipe_count = count_other_pipes(endpoints);
    336339        if (pipe_count == 0) {
     340                *pipes_count_ptr = pipe_count;
    337341                *pipes_ptr = NULL;
    338342                return EOK;
     
    445449{
    446450        assert(dev != NULL);
    447         assert(((pipes != NULL) && (pipes_count > 0))
    448             || ((pipes == NULL) && (pipes_count == 0)));
    449451
    450452        if (pipes_count == 0) {
     453                assert(pipes == NULL);
    451454                return EOK;
    452455        }
     456        assert(pipes != NULL);
    453457
    454458        int rc;
     
    468472        size_t i;
    469473        for (i = 0; i < pipes_count; i++) {
    470                 usb_pipe_unregister(pipes[i].pipe, &hc_conn);
     474                usb_log_debug2("Unregistering pipe %zu (%spresent).\n",
     475                    i, pipes[i].present ? "" : "not ");
     476                if (pipes[i].present)
     477                        usb_pipe_unregister(pipes[i].pipe, &hc_conn);
    471478                free(pipes[i].pipe);
    472479        }
     
    592599
    593600        /* Ignore errors and hope for the best. */
    594         usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count);
    595         free(dev->descriptors.configuration);
     601        destroy_current_pipes(dev);
    596602
    597603        if (dev->alternate_interfaces != NULL) {
     
    599605        }
    600606        free(dev->alternate_interfaces);
    601 
    602         free(dev);
     607        free(dev->descriptors.configuration);
     608        free(dev->driver_data);
     609}
     610
     611void * usb_device_data_alloc(usb_device_t *usb_dev, size_t size)
     612{
     613        assert(usb_dev);
     614        assert(usb_dev->driver_data == NULL);
     615        return usb_dev->driver_data = calloc(1, size);
     616
    603617}
    604618
Note: See TracChangeset for help on using the changeset viewer.