Changeset 89a0485a in mainline for uspace/drv/uhci/uhci.c


Ignore:
Timestamp:
2011-01-25T20:44:28Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b00163f
Parents:
7977fa1
Message:

Move function implementations to .c files

Unify error reporting in uhci_in()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci/uhci.c

    r7977fa1 r89a0485a  
    2222        if (!instance)
    2323                { return ENOMEM; }
    24         memset( instance, 0, sizeof(uhci_t) );
     24        bzero( instance, sizeof(uhci_t) );
    2525
    2626        /* init address keeper(libusb) */
     
    8686                return ENOTSUP;
    8787
    88         callback_t *job = malloc(sizeof(callback_t));
    89         if (job == NULL) {
    90                 uhci_print_error("Failed to allocate callback structure.\n");
    91                 return ENOMEM;
    92         }
     88        transfer_descriptor_t *td = NULL;
     89        callback_t *job = NULL;
     90        int ret = EOK;
    9391
    94 #define CHECK_RET_FREE_JOB(r, message) \
    95         if (r != EOK) { \
     92#define CHECK_RET_TRANS_FREE_JOB_TD(message) \
     93        if (ret != EOK) { \
    9694                uhci_print_error(message); \
    97                 callback_fini(job); \
    98                 trans_free(job); \
    99                 return r; \
     95                if (job) { \
     96                        callback_fini(job); \
     97                        trans_free(job); \
     98                } \
     99                if (td) { trans_free(td); } \
     100                return ret; \
    100101        } else (void) 0
    101102
    102         int ret = callback_in_init(job, dev, buffer, size, callback, arg);
    103         CHECK_RET_FREE_JOB(ret, "Failed to initialize callback structure.\n");
    104103
    105         transfer_descriptor_t *td = trans_malloc(sizeof(transfer_descriptor_t));
    106         ret = (td == NULL) ? ENOMEM : EOK;
    107         CHECK_RET_FREE_JOB(ret, "Failed to allocate tranfer descriptor.\n");
     104        job = malloc(sizeof(callback_t));
     105        ret= job ? EOK : ENOMEM;
     106        CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate callback structure.\n");
     107
     108        ret = callback_in_init(job, dev, buffer, size, callback, arg);
     109        CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize callback structure.\n");
     110
     111        td = trans_malloc(sizeof(transfer_descriptor_t));
     112        ret = td ? ENOMEM : EOK;
     113        CHECK_RET_TRANS_FREE_JOB_TD("Failed to allocate tranfer descriptor.\n");
    108114
    109115        ret = transfer_descriptor_init(td, 3, size, false, target, USB_PID_IN);
    110         if (ret != EOK) {
    111                 uhci_print_error("Failed to initialize transfer descriptor.\n");
    112                 trans_free(td);
    113                 trans_free(job);
    114                 return ret;
    115         }
     116        CHECK_RET_TRANS_FREE_JOB_TD("Failed to initialize transfer descriptor.\n");
     117
    116118        td->callback = job;
    117119
     120        assert(dev);
     121        uhci_t *instance = (uhci_t*)dev->driver_data;
     122        assert(instance);
    118123
    119         // TODO: add to list
    120 //      callback(dev, USB_OUTCOME_OK, size, arg);
     124        ret = transfer_list_append(&instance->transfers[transfer_type], td);
     125        CHECK_RET_TRANS_FREE_JOB_TD("Failed to append transfer descriptor.\n");
    121126
    122127        return EOK;
Note: See TracChangeset for help on using the changeset viewer.