Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 2ff7360 in mainline


Ignore:
Timestamp:
2011-05-18T15:23:16Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
45e0e07
Parents:
aeca5a3
Message:

Use better error handling in root hub registration routine

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/ohci/hc.c

    raeca5a3 r2ff7360  
    5656        assert(hub_fun);
    5757
    58         int ret;
    59 
    60         usb_address_t hub_address =
     58        const usb_address_t hub_address =
    6159            device_keeper_get_free_address(&instance->manager, USB_SPEED_FULL);
    6260        if (hub_address <= 0) {
    63                 usb_log_error("Failed to get OHCI root hub address.\n");
     61                usb_log_error("Failed(%d) to get OHCI root hub address.\n",
     62                    hub_address);
    6463                return hub_address;
    6564        }
     
    6867            &instance->manager, hub_address, hub_fun->handle);
    6968
    70         ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
     69#define CHECK_RET_RELEASE(ret, message...) \
     70if (ret != EOK) { \
     71        usb_log_error(message); \
     72        hc_remove_endpoint(instance, hub_address, 0, USB_DIRECTION_BOTH); \
     73        usb_device_keeper_release(&instance->manager, hub_address); \
     74        return ret; \
     75} else (void)0
     76
     77        int ret = hc_add_endpoint(instance, hub_address, 0, USB_SPEED_FULL,
    7178            USB_TRANSFER_CONTROL, USB_DIRECTION_BOTH, 64, 0, 0);
    72         if (ret != EOK) {
    73                 usb_log_error("Failed to add OHCI rh endpoint 0.\n");
    74                 usb_device_keeper_release(&instance->manager, hub_address);
    75                 return ret;
    76         }
     79        CHECK_RET_RELEASE(ret, "Failed(%d) to add OHCI rh endpoint 0.\n", ret);
    7780
    7881        char *match_str = NULL;
    7982        /* DDF needs heap allocated string */
    8083        ret = asprintf(&match_str, "usb&class=hub");
    81         if (ret < 0) {
    82                 usb_log_error(
    83                     "Failed(%d) to create root hub match-id string.\n", ret);
    84                 usb_device_keeper_release(&instance->manager, hub_address);
    85                 return ret;
    86         }
     84        ret = ret > 0 ? 0 : ret;
     85        CHECK_RET_RELEASE(ret, "Failed(%d) to create match-id string.\n", ret);
    8786
    8887        ret = ddf_fun_add_match_id(hub_fun, match_str, 100);
    89         if (ret != EOK) {
    90                 usb_log_error("Failed add root hub match-id.\n");
    91         }
     88        CHECK_RET_RELEASE(ret, "Failed(%d) add root hub match-id.\n", ret);
     89
    9290        ret = ddf_fun_bind(hub_fun);
    93         return ret;
     91        CHECK_RET_RELEASE(ret, "Failed(%d) to bind root hub function.\n", ret);
     92
     93        return EOK;
     94#undef CHECK_RET_RELEASE
    9495}
    9596/*----------------------------------------------------------------------------*/
     
    121122#undef CHECK_RET_RETURN
    122123
    123 
    124 //      hc_init_hw(instance);
     124        fibril_mutex_initialize(&instance->guard);
    125125        hc_gain_control(instance);
    126         fibril_mutex_initialize(&instance->guard);
    127126
    128127        rh_init(&instance->rh, instance->registers);
Note: See TracChangeset for help on using the changeset viewer.