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


Ignore:
Timestamp:
2011-10-15T12:49:18Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e3f7418
Parents:
7c95d6f5
Message:

usb: Add and use usb_device_data_alloc.

Inspired by ddf_dev_data_alloc and ddf_fun_data_alloc.
Fix possible double free (hid dev and hid fun shared driver_data).

File:
1 edited

Legend:

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

    r7c95d6f5 r065064e6  
    152152        gen_dev->driver_data = dev;
    153153
    154         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;
    155158}
    156159/*----------------------------------------------------------------------------*/
     
    185188        if (driver->ops->device_gone == NULL)
    186189                return ENOTSUP;
    187         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);
    188192        if (ret == EOK)
    189                 usb_device_destroy(gen_dev->driver_data);
     193                usb_device_destroy(usb_dev);
    190194
    191195        return ret;
     
    595599
    596600        /* Ignore errors and hope for the best. */
    597         usb_device_destroy_pipes(dev->ddf_dev, dev->pipes, dev->pipes_count);
    598         free(dev->descriptors.configuration);
     601        destroy_current_pipes(dev);
    599602
    600603        if (dev->alternate_interfaces != NULL) {
     
    602605        }
    603606        free(dev->alternate_interfaces);
    604 
    605         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
    606617}
    607618
Note: See TracChangeset for help on using the changeset viewer.