Changeset 3f2af64 in mainline for uspace/lib/usb/src/devdrv.c


Ignore:
Timestamp:
2011-04-10T14:08:12Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4776ba9, d8b275d
Parents:
231748a
Message:

libusb: refactoring

File:
1 edited

Legend:

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

    r231748a r3f2af64  
    180180 * with usb_pipe_initialize_from_configuration().
    181181 *
     182 * @warning This is a wrapper function that does several operations that
     183 * can fail and that cannot be rollbacked easily. That means that a failure
     184 * during the SET_INTERFACE request would result in having a device with
     185 * no pipes at all (except the default control one). That is because the old
     186 * pipes needs to be unregistered at HC first and the new ones could not
     187 * be created.
     188 *
    182189 * @param dev USB device.
    183190 * @param alternate_setting Alternate setting to choose.
     
    193200
    194201        int rc;
    195 
    196         /* TODO: more transactional behavior. */
    197202
    198203        /* Destroy existing pipes. */
     
    431436}
    432437
    433 /** Initialize control pipe and device descriptors. */
    434 static int initialize_ctrl_pipe_and_descriptors(usb_device_t *dev,
    435      const char **errmsg)
     438/** Initialize control pipe in a device.
     439 *
     440 * @param dev USB device in question.
     441 * @param errmsg Where to store error context.
     442 * @return
     443 */
     444static int init_wire_and_ctrl_pipe(usb_device_t *dev, const char **errmsg)
    436445{
    437446        int rc;
     
    451460        }
    452461
    453         /* Get our interface. */
    454         dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
    455 
    456         /* Retrieve the descriptors. */
    457         rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe,
    458             &dev->descriptors);
    459         if (rc != EOK) {
    460                 *errmsg = "descriptor retrieval";
    461         }
    462 
    463         return rc;
     462        return EOK;
    464463}
    465464
     
    489488        }
    490489
     490        // FIXME: proper deallocation in case of errors
     491
    491492        dev->ddf_dev = ddf_dev;
    492493        dev->driver_data = NULL;
     
    497498        dev->pipes = NULL;
    498499
    499         rc = initialize_ctrl_pipe_and_descriptors(dev, errstr_ptr);
    500         if (rc != EOK) {
    501                 return rc;
    502         }
    503 
     500        /* Initialize backing wire and control pipe. */
     501        rc = init_wire_and_ctrl_pipe(dev, errstr_ptr);
     502        if (rc != EOK) {
     503                return rc;
     504        }
     505
     506        /* Get our interface. */
     507        dev->interface_no = usb_device_get_assigned_interface(dev->ddf_dev);
     508
     509        /* Retrieve standard descriptors. */
     510        rc = usb_device_retrieve_descriptors(&dev->ctrl_pipe,
     511            &dev->descriptors);
     512        if (rc != EOK) {
     513                *errstr_ptr = "descriptor retrieval";
     514                return rc;
     515        }
     516
     517        /* Create alternate interfaces. */
    504518        rc = usb_alternate_interfaces_create(dev->descriptors.configuration,
    505519            dev->descriptors.configuration_size, dev->interface_no,
     
    513527        if (rc != EOK) {
    514528                *errstr_ptr = "pipes initialization";
    515                 /* TODO: deallocate */
    516529                return rc;
    517530        }
Note: See TracChangeset for help on using the changeset viewer.