Changeset d46b13d in mainline


Ignore:
Timestamp:
2011-09-19T13:07:40Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
983e135
Parents:
ee9ea16
Message:

usbhub: Fix device initialization error paths.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbhub/usbhub.c

    ree9ea16 rd46b13d  
    5555#include <usb/classes/classes.h>
    5656
     57#define HUB_FNC_NAME "hub"
    5758
    5859static usb_hub_info_t * usb_hub_info_create(usb_device_t *usb_dev);
    5960static int usb_hub_process_hub_specific_info(usb_hub_info_t *hub_info);
    6061static int usb_hub_set_configuration(usb_hub_info_t *hub_info);
    61 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info);
    6262static int usb_process_hub_over_current(usb_hub_info_t *hub_info,
    6363    usb_hub_status_t status);
     
    8383 * @return error code
    8484 */
    85 int usb_hub_add_device(usb_device_t *usb_dev) {
     85int usb_hub_add_device(usb_device_t *usb_dev)
     86{
    8687        if (!usb_dev) return EINVAL;
    8788        usb_hub_info_t *hub_info = usb_hub_info_create(usb_dev);
     
    106107                return opResult;
    107108        }
     109
    108110        //get port count and create attached_devs
    109111        opResult = usb_hub_process_hub_specific_info(hub_info);
     
    115117        }
    116118
    117         usb_log_debug("Creating 'hub' function in DDF.\n");
     119        usb_log_debug("Creating DDF function '" HUB_FNC_NAME "'.\n");
    118120        ddf_fun_t *hub_fun = ddf_fun_create(hub_info->usb_device->ddf_dev,
    119             fun_exposed, "hub");
    120         assert(hub_fun != NULL);
    121         hub_fun->ops = NULL;
     121            fun_exposed, HUB_FNC_NAME);
     122        if (hub_fun == NULL) {
     123                usb_log_error("Failed to create hub function.\n");
     124                free(hub_info);
     125                return ENOMEM;
     126        }
    122127
    123128        opResult = ddf_fun_bind(hub_fun);
    124         assert(opResult == EOK);
    125 
    126         opResult = usb_hub_start_hub_fibril(hub_info);
    127         if (opResult != EOK)
     129        if (opResult != EOK) {
     130                usb_log_error("Failed to bind hub function: %s.\n",
     131                   str_error(opResult));
    128132                free(hub_info);
    129         return opResult;
     133                ddf_fun_destroy(hub_fun);
     134                return opResult;
     135        }
     136
     137        opResult = usb_device_auto_poll(hub_info->usb_device, 0,
     138            hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
     139            usb_hub_polling_terminated_callback, hub_info);
     140        if (opResult != EOK) {
     141                ddf_fun_destroy(hub_fun);
     142                free(hub_info);
     143                usb_log_error("Failed to create polling fibril: %s.\n",
     144                    str_error(opResult));
     145                return opResult;
     146        }
     147        usb_log_info("Controlling hub '%s' (%zu ports).\n",
     148            hub_info->usb_device->ddf_dev->name, hub_info->port_count);
     149
     150        return EOK;
    130151}
    131152
     
    322343            config_descriptor->configuration_number);
    323344
    324         return EOK;
    325 }
    326 
    327 /**
    328  * create and start fibril with hub control loop
    329  *
    330  * Before the fibril is started, the control pipe and host controller
    331  * connection of the hub is open.
    332  *
    333  * @param hub_info hub representing structure
    334  * @return error code
    335  */
    336 static int usb_hub_start_hub_fibril(usb_hub_info_t *hub_info) {
    337         int rc;
    338 
    339         rc = usb_device_auto_poll(hub_info->usb_device, 0,
    340             hub_port_changes_callback, ((hub_info->port_count + 1) / 8) + 1,
    341             usb_hub_polling_terminated_callback, hub_info);
    342         if (rc != EOK) {
    343                 usb_log_error("Failed to create polling fibril: %s.\n",
    344                     str_error(rc));
    345                 free(hub_info);
    346                 return rc;
    347         }
    348 
    349         usb_log_info("Controlling hub `%s' (%zu ports).\n",
    350             hub_info->usb_device->ddf_dev->name, hub_info->port_count);
    351345        return EOK;
    352346}
Note: See TracChangeset for help on using the changeset viewer.