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


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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        }
Note: See TracChangeset for help on using the changeset viewer.