Ignore:
Timestamp:
2018-07-05T09:34:09Z (6 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
63d46341
Parents:
76f566d
Message:

do not expose the call capability handler from the async framework

Keep the call capability handler encapsulated within the async framework
and do not expose it explicitly via its API. Use the pointer to
ipc_call_t as the sole object identifying an IPC call in the code that
uses the async framework.

This plugs a major leak in the abstraction and also simplifies both the
async framework (slightly) and all IPC servers.

File:
1 edited

Legend:

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

    r76f566d r984a9ba  
    283283}
    284284
    285 static void remote_usbhid_get_event_length(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    286 static void remote_usbhid_get_event(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    287 static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
    288 static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, cap_call_handle_t, ipc_call_t *);
     285static void remote_usbhid_get_event_length(ddf_fun_t *, void *, ipc_call_t *);
     286static void remote_usbhid_get_event(ddf_fun_t *, void *, ipc_call_t *);
     287static void remote_usbhid_get_report_descriptor_length(ddf_fun_t *, void *, ipc_call_t *);
     288static void remote_usbhid_get_report_descriptor(ddf_fun_t *, void *, ipc_call_t *);
    289289
    290290/** Remote USB HID interface operations. */
     
    306306
    307307void remote_usbhid_get_event_length(ddf_fun_t *fun, void *iface,
    308     cap_call_handle_t chandle, ipc_call_t *call)
     308    ipc_call_t *call)
    309309{
    310310        printf("remote_usbhid_get_event_length()\n");
     
    314314        if (!hid_iface->get_event_length) {
    315315                printf("Get event length not set!\n");
    316                 async_answer_0(chandle, ENOTSUP);
     316                async_answer_0(call, ENOTSUP);
    317317                return;
    318318        }
    319319
    320320        size_t len = hid_iface->get_event_length(fun);
    321         async_answer_1(chandle, EOK, len);
     321        async_answer_1(call, EOK, len);
    322322}
    323323
    324324void remote_usbhid_get_event(ddf_fun_t *fun, void *iface,
    325     cap_call_handle_t chandle, ipc_call_t *call)
     325    ipc_call_t *call)
    326326{
    327327        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    328328
    329329        if (!hid_iface->get_event) {
    330                 async_answer_0(chandle, ENOTSUP);
     330                async_answer_0(call, ENOTSUP);
    331331                return;
    332332        }
     
    334334        unsigned int flags = DEV_IPC_GET_ARG1(*call);
    335335
     336        ipc_call_t data;
    336337        size_t len;
    337         cap_call_handle_t data_chandle;
    338         if (!async_data_read_receive(&data_chandle, &len)) {
    339                 async_answer_0(chandle, EPARTY);
     338        if (!async_data_read_receive(&data, &len)) {
     339                async_answer_0(call, EPARTY);
    340340                return;
    341341        }
    342342
    343343        if (len == 0) {
    344                 async_answer_0(data_chandle, EINVAL);
    345                 async_answer_0(chandle, EINVAL);
     344                async_answer_0(&data, EINVAL);
     345                async_answer_0(call, EINVAL);
    346346                return;
    347347        }
     
    349349        errno_t rc;
    350350
    351         uint8_t *data = malloc(len);
    352         if (data == NULL) {
    353                 async_answer_0(data_chandle, ENOMEM);
    354                 async_answer_0(chandle, ENOMEM);
     351        uint8_t *event = malloc(len);
     352        if (event == NULL) {
     353                async_answer_0(&data, ENOMEM);
     354                async_answer_0(call, ENOMEM);
    355355                return;
    356356        }
     
    358358        size_t act_length;
    359359        int event_nr;
    360         rc = hid_iface->get_event(fun, data, len, &act_length, &event_nr, flags);
     360        rc = hid_iface->get_event(fun, event, len, &act_length, &event_nr, flags);
    361361        if (rc != EOK) {
    362                 free(data);
    363                 async_answer_0(data_chandle, rc);
    364                 async_answer_0(chandle, rc);
     362                free(event);
     363                async_answer_0(&data, rc);
     364                async_answer_0(call, rc);
    365365                return;
    366366        }
     
    371371        }
    372372
    373         async_data_read_finalize(data_chandle, data, act_length);
    374 
    375         free(data);
    376 
    377         async_answer_1(chandle, EOK, event_nr);
     373        async_data_read_finalize(&data, event, act_length);
     374
     375        free(event);
     376
     377        async_answer_1(call, EOK, event_nr);
    378378}
    379379
    380380void remote_usbhid_get_report_descriptor_length(ddf_fun_t *fun, void *iface,
    381     cap_call_handle_t chandle, ipc_call_t *call)
     381    ipc_call_t *call)
    382382{
    383383        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    384384
    385385        if (!hid_iface->get_report_descriptor_length) {
    386                 async_answer_0(chandle, ENOTSUP);
     386                async_answer_0(call, ENOTSUP);
    387387                return;
    388388        }
    389389
    390390        size_t len = hid_iface->get_report_descriptor_length(fun);
    391         async_answer_1(chandle, EOK, (sysarg_t) len);
     391        async_answer_1(call, EOK, (sysarg_t) len);
    392392}
    393393
    394394void remote_usbhid_get_report_descriptor(ddf_fun_t *fun, void *iface,
    395     cap_call_handle_t chandle, ipc_call_t *call)
     395    ipc_call_t *call)
    396396{
    397397        usbhid_iface_t *hid_iface = (usbhid_iface_t *) iface;
    398398
    399399        if (!hid_iface->get_report_descriptor) {
    400                 async_answer_0(chandle, ENOTSUP);
    401                 return;
    402         }
    403 
     400                async_answer_0(call, ENOTSUP);
     401                return;
     402        }
     403
     404        ipc_call_t data;
    404405        size_t len;
    405         cap_call_handle_t data_chandle;
    406         if (!async_data_read_receive(&data_chandle, &len)) {
    407                 async_answer_0(chandle, EINVAL);
     406        if (!async_data_read_receive(&data, &len)) {
     407                async_answer_0(call, EINVAL);
    408408                return;
    409409        }
    410410
    411411        if (len == 0) {
    412                 async_answer_0(data_chandle, EINVAL);
    413                 async_answer_0(chandle, EINVAL);
     412                async_answer_0(&data, EINVAL);
     413                async_answer_0(call, EINVAL);
    414414                return;
    415415        }
     
    417417        uint8_t *descriptor = malloc(len);
    418418        if (descriptor == NULL) {
    419                 async_answer_0(data_chandle, ENOMEM);
    420                 async_answer_0(chandle, ENOMEM);
     419                async_answer_0(&data, ENOMEM);
     420                async_answer_0(call, ENOMEM);
    421421                return;
    422422        }
     
    430430        if (rc != EOK) {
    431431                free(descriptor);
    432                 async_answer_0(data_chandle, rc);
    433                 async_answer_0(chandle, rc);
    434                 return;
    435         }
    436 
    437         async_data_read_finalize(data_chandle, descriptor, act_len);
    438         async_answer_0(chandle, EOK);
     432                async_answer_0(&data, rc);
     433                async_answer_0(call, rc);
     434                return;
     435        }
     436
     437        async_data_read_finalize(&data, descriptor, act_len);
     438        async_answer_0(call, EOK);
    439439
    440440        free(descriptor);
    441441}
    442 
    443 
    444442
    445443/**
Note: See TracChangeset for help on using the changeset viewer.