Changeset 2ab6875 in mainline


Ignore:
Timestamp:
2011-03-07T11:18:21Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bcaefe3
Parents:
4b4e163
Message:

Further refactoring

Location:
uspace/drv/uhci-hcd
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/batch.c

    r4b4e163 r2ab6875  
    6969        assert(func_in != NULL || func_out != NULL);
    7070
     71#define CHECK_NULL_DISPOSE_RETURN(ptr, message...) \
     72        if (ptr == NULL) { \
     73                usb_log_error(message); \
     74                if (instance) { \
     75                        batch_dispose(instance); \
     76                } \
     77                return NULL; \
     78        } else (void)0
     79
    7180        batch_t *instance = malloc(sizeof(batch_t));
    72         if (instance == NULL) {
    73                 usb_log_error("Failed to allocate batch instance.\n");
    74                 return NULL;
    75         }
    76 
    77         instance->qh = queue_head_get();
    78         if (instance->qh == NULL) {
    79                 usb_log_error("Failed to allocate queue head.\n");
    80                 free(instance);
    81                 return NULL;
    82         }
     81        CHECK_NULL_DISPOSE_RETURN(instance,
     82            "Failed to allocate batch instance.\n");
     83        bzero(instance, sizeof(batch_t));
     84
     85        instance->qh = malloc32(sizeof(queue_head_t));
     86        CHECK_NULL_DISPOSE_RETURN(instance->qh,
     87            "Failed to allocate batch queue head.\n");
     88        queue_head_init(instance->qh);
    8389
    8490        instance->packets = (size + max_packet_size - 1) / max_packet_size;
     
    8894
    8995        instance->tds = malloc32(sizeof(td_t) * instance->packets);
    90         if (instance->tds == NULL) {
    91                 usb_log_error("Failed to allocate transfer descriptors.\n");
    92                 queue_head_dispose(instance->qh);
    93                 free(instance);
    94                 return NULL;
    95         }
     96        CHECK_NULL_DISPOSE_RETURN(
     97            instance->tds, "Failed to allocate transfer descriptors.\n");
    9698        bzero(instance->tds, sizeof(td_t) * instance->packets);
    9799
    98100        const size_t transport_size = max_packet_size * instance->packets;
    99101
    100         instance->transport_buffer =
    101            (size > 0) ? malloc32(transport_size) : NULL;
    102 
    103         if ((size > 0) && (instance->transport_buffer == NULL)) {
    104                 usb_log_error("Failed to allocate device accessible buffer.\n");
    105                 queue_head_dispose(instance->qh);
    106                 free32(instance->tds);
    107                 free(instance);
    108                 return NULL;
    109         }
    110 
    111         instance->setup_buffer = setup_buffer ? malloc32(setup_size) : NULL;
    112         if ((setup_size > 0) && (instance->setup_buffer == NULL)) {
    113                 usb_log_error("Failed to allocate device accessible setup buffer.\n");
    114                 queue_head_dispose(instance->qh);
    115                 free32(instance->tds);
    116                 free32(instance->transport_buffer);
    117                 free(instance);
    118                 return NULL;
    119         }
    120         if (instance->setup_buffer) {
     102        if (size > 0) {
     103                instance->transport_buffer = malloc32(transport_size);
     104                CHECK_NULL_DISPOSE_RETURN(instance->transport_buffer,
     105                    "Failed to allocate device accessible buffer.\n");
     106        }
     107
     108        if (setup_size > 0) {
     109                instance->setup_buffer = malloc32(setup_size);
     110                CHECK_NULL_DISPOSE_RETURN(instance->setup_buffer,
     111                    "Failed to allocate device accessible setup buffer.\n");
    121112                memcpy(instance->setup_buffer, setup_buffer, setup_size);
    122113        }
    123114
     115
     116        link_initialize(&instance->link);
     117
    124118        instance->max_packet_size = max_packet_size;
    125 
    126         link_initialize(&instance->link);
    127 
    128119        instance->target = target;
    129120        instance->transfer_type = transfer_type;
    130 
    131         if (func_out)
    132                 instance->callback_out = func_out;
    133         if (func_in)
    134                 instance->callback_in = func_in;
    135 
    136121        instance->buffer = buffer;
    137122        instance->buffer_size = size;
     
    142127        instance->manager = manager;
    143128
    144         queue_head_element_td(instance->qh, addr_to_phys(instance->tds));
     129        if (func_out)
     130                instance->callback_out = func_out;
     131        if (func_in)
     132                instance->callback_in = func_in;
     133
     134        queue_head_set_element_td(instance->qh, addr_to_phys(instance->tds));
     135
    145136        usb_log_debug("Batch(%p) %d:%d memory structures ready.\n",
    146137            instance, target.address, target.endpoint);
  • uspace/drv/uhci-hcd/transfer_list.c

    r4b4e163 r2ab6875  
    4343        instance->next = NULL;
    4444        instance->name = name;
    45         instance->queue_head = queue_head_get();
     45        instance->queue_head = malloc32(sizeof(queue_head_t));
    4646        if (!instance->queue_head) {
    4747                usb_log_error("Failed to allocate queue head.\n");
    4848                return ENOMEM;
    4949        }
    50         instance->queue_head_pa = (uintptr_t)addr_to_phys(instance->queue_head);
     50        queue_head_init(instance->queue_head);
     51        instance->queue_head_pa = addr_to_phys(instance->queue_head);
    5152
    5253        queue_head_init(instance->queue_head);
  • uspace/drv/uhci-hcd/transfer_list.h

    r4b4e163 r2ab6875  
    5858{
    5959        assert(instance);
    60         queue_head_dispose(instance->queue_head);
     60        free32(instance->queue_head);
    6161}
    6262void transfer_list_remove_finished(transfer_list_t *instance);
  • uspace/drv/uhci-hcd/uhci_struct/queue_head.h

    r4b4e163 r2ab6875  
    7171}
    7272
    73 static inline void queue_head_element_td(queue_head_t *instance, uint32_t pa)
     73static inline void queue_head_set_element_td(queue_head_t *instance, uint32_t pa)
    7474{
    7575        if (pa) {
     
    7878}
    7979
    80 static inline queue_head_t * queue_head_get() {
    81         queue_head_t *ret = malloc32(sizeof(queue_head_t));
    82         if (ret)
    83                 queue_head_init(ret);
    84         return ret;
    85 }
    86 
    87 static inline void queue_head_dispose(queue_head_t *head)
    88         { free32(head); }
    89 
    90 
    9180#endif
    9281/**
Note: See TracChangeset for help on using the changeset viewer.