Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usb/src/pipesio.c

    r3954a63b rd48fcc0  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
     51#include "pipepriv.h"
    5152
    5253/** Request an in transfer, no checking of input parameters.
     
    7879        }
    7980
     81        /* Ensure serialization over the phone. */
     82        pipe_start_transaction(pipe);
     83
    8084        /*
    8185         * Make call identifying target USB device and type of transfer.
     
    8791            NULL);
    8892        if (opening_request == 0) {
     93                pipe_end_transaction(pipe);
    8994                return ENOMEM;
    9095        }
     
    96101        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    97102            &data_request_call);
     103
     104        /*
     105         * Since now on, someone else might access the backing phone
     106         * without breaking the transfer IPC protocol.
     107         */
     108        pipe_end_transaction(pipe);
    98109
    99110        if (data_request == 0) {
     
    146157
    147158        if (buffer == NULL) {
    148                         return EINVAL;
     159                return EINVAL;
    149160        }
    150161
    151162        if (size == 0) {
    152163                return EINVAL;
    153         }
    154 
    155         if (!usb_pipe_is_session_started(pipe)) {
    156                 return EBADF;
    157164        }
    158165
     
    165172        }
    166173
     174        int rc;
     175        rc = pipe_add_ref(pipe);
     176        if (rc != EOK) {
     177                return rc;
     178        }
     179
     180
    167181        size_t act_size = 0;
    168         int rc;
    169182
    170183        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
     184
     185        pipe_drop_ref(pipe);
     186
    171187        if (rc != EOK) {
    172188                return rc;
     
    210226        }
    211227
     228        /* Ensure serialization over the phone. */
     229        pipe_start_transaction(pipe);
     230
    212231        /*
    213232         * Make call identifying target USB device and type of transfer.
     
    219238            NULL);
    220239        if (opening_request == 0) {
     240                pipe_end_transaction(pipe);
    221241                return ENOMEM;
    222242        }
     
    226246         */
    227247        int rc = async_data_write_start(pipe->hc_phone, buffer, size);
     248
     249        /*
     250         * Since now on, someone else might access the backing phone
     251         * without breaking the transfer IPC protocol.
     252         */
     253        pipe_end_transaction(pipe);
     254
    228255        if (rc != EOK) {
    229256                async_wait_for(opening_request, NULL);
     
    260287        }
    261288
    262         if (!usb_pipe_is_session_started(pipe)) {
    263                 return EBADF;
    264         }
    265 
    266289        if (pipe->direction != USB_DIRECTION_OUT) {
    267290                return EBADF;
     
    272295        }
    273296
    274         int rc = usb_pipe_write_no_check(pipe, buffer, size);
     297        int rc;
     298
     299        rc = pipe_add_ref(pipe);
     300        if (rc != EOK) {
     301                return rc;
     302        }
     303
     304        rc = usb_pipe_write_no_check(pipe, buffer, size);
     305
     306        pipe_drop_ref(pipe);
    275307
    276308        return rc;
     
    293325    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    294326{
     327        /* Ensure serialization over the phone. */
     328        pipe_start_transaction(pipe);
     329
    295330        /*
    296331         * Make call identifying target USB device and control transfer type.
     
    311346            setup_buffer, setup_buffer_size);
    312347        if (rc != EOK) {
     348                pipe_end_transaction(pipe);
    313349                async_wait_for(opening_request, NULL);
    314350                return rc;
     
    322358            data_buffer, data_buffer_size,
    323359            &data_request_call);
     360
     361        /*
     362         * Since now on, someone else might access the backing phone
     363         * without breaking the transfer IPC protocol.
     364         */
     365        pipe_end_transaction(pipe);
     366
     367
    324368        if (data_request == 0) {
    325369                async_wait_for(opening_request, NULL);
     
    379423        }
    380424
    381         if (!usb_pipe_is_session_started(pipe)) {
    382                 return EBADF;
    383         }
    384 
    385425        if ((pipe->direction != USB_DIRECTION_BOTH)
    386426            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    388428        }
    389429
     430        int rc;
     431
     432        rc = pipe_add_ref(pipe);
     433        if (rc != EOK) {
     434                return rc;
     435        }
     436
    390437        size_t act_size = 0;
    391         int rc = usb_pipe_control_read_no_check(pipe,
     438        rc = usb_pipe_control_read_no_check(pipe,
    392439            setup_buffer, setup_buffer_size,
    393440            data_buffer, data_buffer_size, &act_size);
     441
     442        pipe_drop_ref(pipe);
    394443
    395444        if (rc != EOK) {
     
    418467    void *data_buffer, size_t data_buffer_size)
    419468{
     469        /* Ensure serialization over the phone. */
     470        pipe_start_transaction(pipe);
     471
    420472        /*
    421473         * Make call identifying target USB device and control transfer type.
     
    428480            NULL);
    429481        if (opening_request == 0) {
     482                pipe_end_transaction(pipe);
    430483                return ENOMEM;
    431484        }
     
    437490            setup_buffer, setup_buffer_size);
    438491        if (rc != EOK) {
     492                pipe_end_transaction(pipe);
    439493                async_wait_for(opening_request, NULL);
    440494                return rc;
     
    447501                rc = async_data_write_start(pipe->hc_phone,
    448502                    data_buffer, data_buffer_size);
     503
     504                /* All data sent, pipe can be released. */
     505                pipe_end_transaction(pipe);
     506
    449507                if (rc != EOK) {
    450508                        async_wait_for(opening_request, NULL);
    451509                        return rc;
    452510                }
     511        } else {
     512                /* No data to send, we can release the pipe for others. */
     513                pipe_end_transaction(pipe);
    453514        }
    454515
     
    491552        }
    492553
    493         if (!usb_pipe_is_session_started(pipe)) {
    494                 return EBADF;
    495         }
    496 
    497554        if ((pipe->direction != USB_DIRECTION_BOTH)
    498555            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    500557        }
    501558
    502         int rc = usb_pipe_control_write_no_check(pipe,
     559        int rc;
     560
     561        rc = pipe_add_ref(pipe);
     562        if (rc != EOK) {
     563                return rc;
     564        }
     565
     566        rc = usb_pipe_control_write_no_check(pipe,
    503567            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
     568
     569        pipe_drop_ref(pipe);
    504570
    505571        return rc;
Note: See TracChangeset for help on using the changeset viewer.