Ignore:
File:
1 edited

Legend:

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

    r93f8da1 r9753220  
    104104} async_transaction_t;
    105105
    106 static 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 
    122 static 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 
    137106void remote_usbhc_get_address(device_t *device, void *iface,
    138107    ipc_callid_t callid, ipc_call_t *call)
     
    167136        if (trans->buffer == NULL) {
    168137                ipc_answer_0(callid, EINVAL);
    169                 async_transaction_destroy(trans);
     138                free(trans);
    170139                return;
    171140        }
     
    175144        if (!async_data_read_receive(&cid, &accepted_size)) {
    176145                ipc_answer_0(callid, EINVAL);
    177                 async_transaction_destroy(trans);
    178146                return;
    179147        }
     
    186154        ipc_answer_1(callid, EOK, accepted_size);
    187155
    188         async_transaction_destroy(trans);
     156        free(trans->buffer);
     157        free(trans);
    189158}
    190159
     
    279248        async_transaction_t *trans = (async_transaction_t *)arg;
    280249
     250        // FIXME - answer according to outcome
    281251        ipc_answer_0(trans->caller, outcome);
    282252
    283         async_transaction_destroy(trans);
     253        free(trans);
    284254}
    285255
     
    289259        async_transaction_t *trans = (async_transaction_t *)arg;
    290260
    291         if (outcome != USB_OUTCOME_OK) {
    292                 ipc_answer_0(trans->caller, outcome);
    293                 async_transaction_destroy(trans);
    294                 return;
    295         }
     261        // FIXME - answer according to outcome
     262        ipc_answer_1(trans->caller, outcome, (sysarg_t)trans);
    296263
    297264        trans->size = actual_size;
    298         ipc_answer_1(trans->caller, USB_OUTCOME_OK, (sysarg_t)trans);
    299265}
    300266
     
    334300        }
    335301
    336         async_transaction_t *trans = async_transaction_create(callid);
    337         if (trans == NULL) {
     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);
    338313                if (buffer != NULL) {
    339314                        free(buffer);
    340315                }
    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);
     316                free(trans);
    354317        }
    355318}
     
    377340        };
    378341
    379         async_transaction_t *trans = async_transaction_create(callid);
    380         if (trans == NULL) {
    381                 ipc_answer_0(callid, ENOMEM);
    382                 return;
    383         }
     342        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     343        trans->caller = callid;
    384344        trans->buffer = malloc(len);
     345        trans->setup_packet = NULL;
    385346        trans->size = len;
    386347
     
    390351        if (rc != EOK) {
    391352                ipc_answer_0(callid, rc);
    392                 async_transaction_destroy(trans);
     353                free(trans->buffer);
     354                free(trans);
    393355        }
    394356}
     
    434396        };
    435397
    436         async_transaction_t *trans = async_transaction_create(callid);
    437         if (trans == NULL) {
    438                 ipc_answer_0(callid, ENOMEM);
    439                 return;
    440         }
     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;
    441403
    442404        int rc;
     
    457419        if (rc != EOK) {
    458420                ipc_answer_0(callid, rc);
    459                 async_transaction_destroy(trans);
    460         }
     421                free(trans);
     422        }
     423        return;
    461424}
    462425
     
    574537            1, USB_MAX_PAYLOAD_SIZE, 0, &data_buffer_len);
    575538        if (rc != EOK) {
    576                 ipc_answer_0(callid, rc);
    577539                free(setup_packet);
    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         }
     540                ipc_answer_0(callid, rc);
     541                return;
     542        }
     543
     544        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     545        trans->caller = callid;
    588546        trans->setup_packet = setup_packet;
    589547        trans->buffer = data_buffer;
     
    597555        if (rc != EOK) {
    598556                ipc_answer_0(callid, rc);
    599                 async_transaction_destroy(trans);
     557                free(setup_packet);
     558                free(data_buffer);
     559                free(trans);
    600560        }
    601561}
     
    631591        }
    632592
    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         }
     593        async_transaction_t *trans = malloc(sizeof(async_transaction_t));
     594        trans->caller = callid;
    639595        trans->setup_packet = setup_packet;
     596        trans->buffer = malloc(data_len);
    640597        trans->size = data_len;
    641         trans->buffer = malloc(data_len);
    642         if (trans->buffer == NULL) {
    643                 ipc_answer_0(callid, ENOMEM);
    644                 async_transaction_destroy(trans);
    645                 return;
    646         }
    647598
    648599        rc = usb_iface->control_read(device, target,
     
    653604        if (rc != EOK) {
    654605                ipc_answer_0(callid, rc);
    655                 async_transaction_destroy(trans);
     606                free(setup_packet);
     607                free(trans->buffer);
     608                free(trans);
    656609        }
    657610}
Note: See TracChangeset for help on using the changeset viewer.