Changeset cce3228 in mainline


Ignore:
Timestamp:
2013-08-07T08:05:56Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e0d8b740
Parents:
dcbda00
Message:

libusbhost: Use goto instead of macros for error handling.

supposedly lesser evil…

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    rdcbda00 rcce3228  
    603603    usb_speed_t max_speed, size_t bw, bw_count_func_t bw_count)
    604604{
    605         if (device == NULL)
     605        if (!device)
    606606                return EBADMEM;
    607607
     608        int ret = ENOMEM;
    608609        hc_dev_t *instance = ddf_dev_data_alloc(device, sizeof(hc_dev_t));
    609610        if (instance == NULL) {
     
    614615        fibril_mutex_initialize(&instance->guard);
    615616
    616 #define CHECK_RET_DEST_FREE_RETURN(ret, message...) \
    617 if (ret != EOK) { \
    618         if (instance->hc_fun) { \
    619                 ddf_fun_destroy(instance->hc_fun); \
    620         } \
    621         usb_log_error(message); \
    622         return ret; \
    623 } else (void)0
    624 
    625617        instance->hc_fun = ddf_fun_create(device, fun_exposed, "hc");
    626         int ret = instance->hc_fun ? EOK : ENOMEM;
    627         CHECK_RET_DEST_FREE_RETURN(ret,
    628             "Failed to create HCD HC function: %s.\n", str_error(ret));
     618        if (!instance->hc_fun) {
     619                usb_log_error("Failed to create HCD ddf fun.\n");
     620                goto err_destroy_fun;
     621        }
     622
    629623        hcd_t *hcd = ddf_fun_data_alloc(instance->hc_fun, sizeof(hcd_t));
    630         ret = hcd ? EOK : ENOMEM;
    631         CHECK_RET_DEST_FREE_RETURN(ret,
    632             "Failed to allocate HCD structure: %s.\n", str_error(ret));
     624        if (!instance->hc_fun) {
     625                usb_log_error("Failed to allocate HCD ddf fun data.\n");
     626                goto err_destroy_fun;
     627        }
    633628
    634629        hcd_init(hcd, max_speed, bw, bw_count);
    635630
    636631        ret = ddf_fun_bind(instance->hc_fun);
    637         CHECK_RET_DEST_FREE_RETURN(ret,
    638             "Failed to bind HCD device function: %s.\n", str_error(ret));
    639 
    640 #define CHECK_RET_UNBIND_FREE_RETURN(ret, message...) \
    641 if (ret != EOK) { \
    642         ddf_fun_unbind(instance->hc_fun); \
    643         CHECK_RET_DEST_FREE_RETURN(ret, message); \
    644 } else (void)0
     632        if (ret != EOK) {
     633                usb_log_error("Failed to bind hc_fun: %s.\n", str_error(ret));
     634                goto err_destroy_fun;
     635        }
     636
    645637        ret = ddf_fun_add_to_category(instance->hc_fun, USB_HC_CATEGORY);
    646         CHECK_RET_UNBIND_FREE_RETURN(ret,
    647             "Failed to add hc to category: %s\n", str_error(ret));
     638        if (ret != EOK) {
     639                usb_log_error("Failed to add fun to category: %s.\n",
     640                    str_error(ret));
     641                ddf_fun_unbind(instance->hc_fun);
     642                goto err_destroy_fun;
     643        }
    648644
    649645        /* HC should be ok at this point (except it can't do anything) */
    650646        if (hc_fun)
    651647                *hc_fun = instance->hc_fun;
    652 
    653648        return EOK;
     649
     650err_destroy_fun:
     651        ddf_fun_destroy(instance->hc_fun);
     652        instance->hc_fun = NULL;
     653        return ret;
    654654}
    655655
Note: See TracChangeset for help on using the changeset viewer.