Changeset 90d7033 in mainline for uspace/lib/usbdev/src/hub.c


Ignore:
Timestamp:
2011-10-31T11:04:57Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
59c163c
Parents:
10059a68
Message:

libusbdev: Fix memory leak in error path. Check input arguments.

File:
1 edited

Legend:

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

    r10059a68 r90d7033  
    171171 *
    172172 * @param[in] parent Parent device (i.e. the hub device).
    173  * @param[in] connection Connection to host controller.
     173 * @param[in] connection Connection to host controller. Must be non-null.
    174174 * @param[in] dev_speed New device speed.
    175175 * @param[in] enable_port Function for enabling signaling through the port the
     
    181181 *      as @c driver_data.
    182182 * @param[out] new_fun Storage where pointer to allocated child function
    183  *      will be written.
     183 *      will be written. Must be non-null.
    184184 * @return Error code.
     185 * @retval EINVAL Either connection or new_fun is a NULL pointer.
    185186 * @retval ENOENT Connection to HC not opened.
    186187 * @retval EADDRNOTAVAIL Failed retrieving free address from host controller.
     
    195196    ddf_dev_ops_t *dev_ops, void *new_dev_data, ddf_fun_t **new_fun)
    196197{
    197         assert(connection != NULL);
     198        if (new_fun == NULL || connection == NULL)
     199                return EINVAL;
     200
    198201        // FIXME: this is awful, we are accessing directly the structure.
     202        // TODO: Why not use provided connection?
    199203        usb_hc_connection_t hc_conn = {
    200204                .hc_handle = connection->hc_handle,
     
    321325            parent, dev_ops, new_dev_data, &child_fun);
    322326        if (rc != EOK) {
    323                 rc = ESTALL;
    324327                goto leave_release_free_address;
    325328        }
     
    328331         * And now inform the host controller about the handle.
    329332         */
    330         usb_hub_attached_device_t new_device = {
     333        const usb_hub_attached_device_t new_device = {
    331334                .address = dev_addr,
    332335                .fun = child_fun,
     
    334337        rc = usb_hc_register_device(&hc_conn, &new_device);
    335338        if (rc != EOK) {
     339                /* The child function is already created. */
     340                child_fun->driver_data = NULL;
     341                ddf_fun_destroy(child_fun);
    336342                rc = EDESTADDRREQ;
    337343                goto leave_release_free_address;
    338344        }
    339 
    340345
    341346        /*
Note: See TracChangeset for help on using the changeset viewer.