Changeset 7fc260ff in mainline


Ignore:
Timestamp:
2011-11-05T14:33:07Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ab27e01
Parents:
904dcc6
Message:

libusbdev: Merge init_wire_and_ctrl_pipe to the only place it was called.

Add usb_device_release_descriptors function that properly clears the descriptor
structure.

Location:
uspace/lib/usbdev
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/driver.h

    r904dcc6 r7fc260ff  
    7272/** USB device structure. */
    7373typedef struct {
     74        /** Connection backing the pipes.
     75         * Typically, you will not need to use this attribute at all.
     76         */
     77        usb_device_connection_t wire;
    7478        /** The default control pipe. */
    7579        usb_pipe_t ctrl_pipe;
     
    9397        usb_device_descriptors_t descriptors;
    9498
    95         /** Generic DDF device backing this one. RO: DO NOT TOUCH!*/
     99        /** Generic DDF device backing this one. DO NOT TOUCH! */
    96100        ddf_dev_t *ddf_dev;
    97101        /** Custom driver data.
     
    100104         */
    101105        void *driver_data;
    102 
    103         /** Connection backing the pipes.
    104          * Typically, you will not need to use this attribute at all.
    105          */
    106         usb_device_connection_t wire;
    107106} usb_device_t;
    108107
     
    160159int usb_driver_main(const usb_driver_t *);
    161160
     161int usb_device_init(usb_device_t *, ddf_dev_t *,
     162    const usb_endpoint_description_t **, const char **);
     163void usb_device_deinit(usb_device_t *);
     164
    162165int usb_device_select_interface(usb_device_t *, uint8_t,
    163166    const usb_endpoint_description_t **);
    164167
    165168int usb_device_retrieve_descriptors(usb_pipe_t *, usb_device_descriptors_t *);
     169void usb_device_release_descriptors(usb_device_descriptors_t *);
     170
    166171int usb_device_create_pipes(const ddf_dev_t *, usb_device_connection_t *,
    167172    const usb_endpoint_description_t **, const uint8_t *, size_t, int, int,
    168173    usb_endpoint_mapping_t **, size_t *);
    169174int usb_device_destroy_pipes(const ddf_dev_t *, usb_endpoint_mapping_t *, size_t);
    170 int usb_device_init(usb_device_t *, ddf_dev_t *,
    171     const usb_endpoint_description_t **, const char **);
    172 void usb_device_deinit(usb_device_t *);
    173175
    174176void * usb_device_data_alloc(usb_device_t *, size_t);
  • uspace/lib/usbdev/src/devdrv.c

    r904dcc6 r7fc260ff  
    300300
    301301        return rc;
     302}
     303
     304/** Cleanup structure initialized via usb_device_retrieve_descriptors.
     305 *
     306 * @param[in] descriptors Where to store the descriptors.
     307 */
     308void usb_device_release_descriptors(usb_device_descriptors_t *descriptors)
     309{
     310        assert(descriptors);
     311        free(descriptors->configuration);
     312        descriptors->configuration = NULL;
    302313}
    303314
     
    490501}
    491502
    492 /** Initialize control pipe in a device.
    493  *
    494  * @param dev USB device in question.
    495  * @param errmsg Where to store error context.
    496  * @return
    497  */
    498 static int init_wire_and_ctrl_pipe(usb_device_t *dev, const char **errmsg)
    499 {
    500         int rc;
    501 
    502         rc = usb_device_connection_initialize_from_device(&dev->wire,
    503             dev->ddf_dev);
    504         if (rc != EOK) {
    505                 *errmsg = "device connection initialization";
    506                 return rc;
    507         }
    508 
    509         rc = usb_pipe_initialize_default_control(&dev->ctrl_pipe,
    510             &dev->wire);
    511         if (rc != EOK) {
    512                 *errmsg = "default control pipe initialization";
    513                 return rc;
    514         }
    515 
    516         return EOK;
    517 }
    518 
    519 
    520503/** Initialize new instance of USB device.
    521504 *
     
    533516        assert(ddf_dev != NULL);
    534517
     518        *errstr_ptr = NULL;
     519
    535520        usb_dev->ddf_dev = ddf_dev;
    536521        usb_dev->driver_data = NULL;
     
    540525
    541526        /* Initialize backing wire and control pipe. */
    542         int rc = init_wire_and_ctrl_pipe(usb_dev, errstr_ptr);
    543         if (rc != EOK) {
     527        int rc = usb_device_connection_initialize_from_device(
     528            &usb_dev->wire, ddf_dev);
     529        if (rc != EOK) {
     530                *errstr_ptr = "device connection initialization";
     531                return rc;
     532        }
     533
     534        /* This pipe was registered by the hub driver,
     535         * during device initialization. */
     536        rc = usb_pipe_initialize_default_control(&usb_dev->ctrl_pipe,
     537            &usb_dev->wire);
     538        if (rc != EOK) {
     539                *errstr_ptr = "default control pipe initialization";
    544540                return rc;
    545541        }
     
    552548            &usb_dev->descriptors);
    553549        if (rc != EOK) {
    554                 /* Nothing allocated, nothing to free. */
    555550                *errstr_ptr = "descriptor retrieval";
    556551                return rc;
    557552        }
    558553
    559         /* Create alternate interfaces. We will silently ignore failure. */
    560         //TODO Why ignore?
     554        /* Create alternate interfaces. We will silently ignore failure.
     555         * We might either control one interface or an entire device,
     556         * it makes no sense to speak about alternate interfaces when
     557         * controlling a device. */
    561558        usb_alternate_interfaces_init(&usb_dev->alternate_interfaces,
    562559            usb_dev->descriptors.configuration,
    563560            usb_dev->descriptors.configuration_size, usb_dev->interface_no);
    564561
     562        /* TODO Add comment here. */
    565563        rc = initialize_other_pipes(endpoints, usb_dev, 0);
    566564        if (rc != EOK) {
    567565                /* Full configuration descriptor is allocated. */
    568                 free(usb_dev->descriptors.configuration);
     566                usb_device_release_descriptors(&usb_dev->descriptors);
    569567                /* Alternate interfaces may be allocated */
    570568                usb_alternate_interfaces_deinit(&usb_dev->alternate_interfaces);
     
    573571        }
    574572
    575         *errstr_ptr = NULL;
    576 
    577573        return EOK;
    578574}
     
    591587
    592588                usb_alternate_interfaces_deinit(&dev->alternate_interfaces);
    593                 free(dev->descriptors.configuration);
     589                usb_device_release_descriptors(&dev->descriptors);
    594590                free(dev->driver_data);
    595591        }
  • uspace/lib/usbdev/src/pipes.c

    r904dcc6 r7fc260ff  
    7575int usb_device_get_assigned_interface(const ddf_dev_t *device)
    7676{
     77        assert(device);
    7778        async_sess_t *parent_sess =
    7879            devman_parent_device_connect(EXCHANGE_ATOMIC, device->handle,
Note: See TracChangeset for help on using the changeset viewer.