Ignore:
Timestamp:
2011-02-02T21:21:08Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
93ef8f6
Parents:
2f4438f5 (diff), 3597dab (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge development/ changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_usbhc.c

    r2f4438f5 rab65fa1  
    104104} async_transaction_t;
    105105
     106static void async_transaction_destroy(async_transaction_t *trans)
     107{
     108        if (trans == NULL) {
     109                return;
     110        }
     111
     112        if (trans->setup_packet != NULL) {
     113                free(trans->setup_packet);
     114        }
     115        if (trans->buffer != NULL) {
     116                free(trans->buffer);
     117        }
     118
     119        free(trans);
     120}
     121
     122static async_transaction_t *async_transaction_create(ipc_callid_t caller)
     123{
     124        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     125        if (trans == NULL) {
     126                return NULL;
     127        }
     128
     129        trans->caller = caller;
     130        trans->buffer = NULL;
     131        trans->setup_packet = NULL;
     132        trans->size = 0;
     133
     134        return trans;
     135}
     136
    106137void remote_usbhc_get_address(device_t *device, void *iface,
    107138    ipc_callid_t callid, ipc_call_t *call)
     
    136167        if (trans->buffer == NULL) {
    137168                ipc_answer_0(callid, EINVAL);
    138                 free(trans);
     169                async_transaction_destroy(trans);
    139170                return;
    140171        }
     
    144175        if (!async_data_read_receive(&cid, &accepted_size)) {
    145176                ipc_answer_0(callid, EINVAL);
     177                async_transaction_destroy(trans);
    146178                return;
    147179        }
     
    154186        ipc_answer_1(callid, EOK, accepted_size);
    155187
    156         free(trans->buffer);
    157         free(trans);
     188        async_transaction_destroy(trans);
    158189}
    159190
     
    248279        async_transaction_t *trans = (async_transaction_t *)arg;
    249280
    250         // FIXME - answer according to outcome
    251281        ipc_answer_0(trans->caller, outcome);
    252282
    253         free(trans);
     283        async_transaction_destroy(trans);
    254284}
    255285
     
    259289        async_transaction_t *trans = (async_transaction_t *)arg;
    260290
    261         // FIXME - answer according to outcome
    262         ipc_answer_1(trans->caller, outcome, (sysarg_t)trans);
     291        if (outcome != USB_OUTCOME_OK) {
     292                ipc_answer_0(trans->caller, outcome);
     293                async_transaction_destroy(trans);
     294                return;
     295        }
    263296
    264297        trans->size = actual_size;
     298        ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
    265299}
    266300
     
    300334        }
    301335
    302         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    303         trans->caller = callid;
    304         trans->buffer = buffer;
    305         trans->setup_packet = NULL;
    306         trans->size = len;
    307 
    308         int rc = transfer_func(device, target, buffer, len,
    309             callback_out, trans);
    310 
    311         if (rc != EOK) {
    312                 ipc_answer_0(callid, rc);
     336        async_transaction_t *trans = async_transaction_create(callid);
     337        if (trans == NULL) {
    313338                if (buffer != NULL) {
    314339                        free(buffer);
    315340                }
    316                 free(trans);
     341                ipc_answer_0(callid, ENOMEM);
     342                return;
     343        }
     344
     345        trans->buffer = buffer;
     346        trans->size = len;
     347
     348        int rc = transfer_func(device, target, buffer, len,
     349            callback_out, trans);
     350
     351        if (rc != EOK) {
     352                ipc_answer_0(callid, rc);
     353                async_transaction_destroy(trans);
    317354        }
    318355}
     
    340377        };
    341378
    342         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    343         trans->caller = callid;
     379        async_transaction_t *trans = async_transaction_create(callid);
     380        if (trans == NULL) {
     381                ipc_answer_0(callid, ENOMEM);
     382                return;
     383        }
    344384        trans->buffer = malloc(len);
    345         trans->setup_packet = NULL;
    346385        trans->size = len;
    347386
     
    351390        if (rc != EOK) {
    352391                ipc_answer_0(callid, rc);
    353                 free(trans->buffer);
    354                 free(trans);
     392                async_transaction_destroy(trans);
    355393        }
    356394}
     
    396434        };
    397435
    398         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    399         trans->caller = callid;
    400         trans->buffer = NULL;
    401         trans->setup_packet = NULL;
    402         trans->size = 0;
     436        async_transaction_t *trans = async_transaction_create(callid);
     437        if (trans == NULL) {
     438                ipc_answer_0(callid, ENOMEM);
     439                return;
     440        }
    403441
    404442        int rc;
     
    419457        if (rc != EOK) {
    420458                ipc_answer_0(callid, rc);
    421                 free(trans);
    422         }
    423         return;
     459                async_transaction_destroy(trans);
     460        }
    424461}
    425462
     
    537574            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    538575        if (rc != EOK) {
     576                ipc_answer_0(callid, rc);
    539577                free(setup_packet);
    540                 ipc_answer_0(callid, rc);
    541                 return;
    542         }
    543 
    544         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    545         trans->caller = callid;
     578                return;
     579        }
     580
     581        async_transaction_t *trans = async_transaction_create(callid);
     582        if (trans == NULL) {
     583                ipc_answer_0(callid, ENOMEM);
     584                free(setup_packet);
     585                free(data_buffer);
     586                return;
     587        }
    546588        trans->setup_packet = setup_packet;
    547589        trans->buffer = data_buffer;
     
    555597        if (rc != EOK) {
    556598                ipc_answer_0(callid, rc);
    557                 free(setup_packet);
    558                 free(data_buffer);
    559                 free(trans);
     599                async_transaction_destroy(trans);
    560600        }
    561601}
     
    591631        }
    592632
    593         async_transaction_t *trans = malloc(sizeof(async_transaction_t));
    594         trans->caller = callid;
     633        async_transaction_t *trans = async_transaction_create(callid);
     634        if (trans == NULL) {
     635                ipc_answer_0(callid, ENOMEM);
     636                free(setup_packet);
     637                return;
     638        }
    595639        trans->setup_packet = setup_packet;
     640        trans->size = data_len;
    596641        trans->buffer = malloc(data_len);
    597         trans->size = data_len;
     642        if (trans->buffer == NULL) {
     643                ipc_answer_0(callid, ENOMEM);
     644                async_transaction_destroy(trans);
     645                return;
     646        }
    598647
    599648        rc = usb_iface->control_read(device, target,
     
    604653        if (rc != EOK) {
    605654                ipc_answer_0(callid, rc);
    606                 free(setup_packet);
    607                 free(trans->buffer);
    608                 free(trans);
     655                async_transaction_destroy(trans);
    609656        }
    610657}
Note: See TracChangeset for help on using the changeset viewer.