Changeset 8fb674b in mainline


Ignore:
Timestamp:
2020-12-31T21:27:13Z (3 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Parents:
6a208fc
git-author:
Matthieu Riolo <matthieu.riolo@…> (2020-06-27 19:08:36)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2020-12-31 21:27:13)
Message:

correcting usage of async_data_read_receive() in srv/input

Location:
uspace
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/input.c

    r6a208fc r8fb674b  
    213213errno_t input_layout_get(async_sess_t *sess, char **layout)
    214214{
    215         errno_t rc;
    216         ipc_call_t call;
     215        *layout = NULL;
     216
    217217        async_exch_t *exch = async_exchange_begin(sess);
    218         aid_t mid = async_send_0(exch, INPUT_GET_LAYOUT, &call);
    219         async_wait_for(mid, &rc);
    220 
    221         if (rc != EOK) {
    222                 goto error;
     218
     219        ipc_call_t answer;
     220        aid_t req = async_send_0(exch, INPUT_GET_LAYOUT, &answer);
     221
     222        char layout_buf[INPUT_LAYOUT_NAME_MAXLEN + 1];
     223        ipc_call_t dreply;
     224        aid_t dreq = async_data_read(exch, layout_buf, INPUT_LAYOUT_NAME_MAXLEN,
     225            &dreply);
     226
     227        errno_t dretval;
     228        async_wait_for(dreq, &dretval);
     229
     230        async_exchange_end(exch);
     231
     232        if (dretval != EOK) {
     233                async_forget(req);
     234                return dretval;
    223235        }
    224236
    225         size_t length = ipc_get_arg1(&call);
    226 
    227         *layout = malloc(length * sizeof(char *));
    228         if (layout == NULL) {
    229                 rc = ENOMEM;
    230                 free(*layout);
    231                 goto error;
    232         }
    233 
    234         rc = async_data_read_start(exch, *layout, length);
    235 
    236         if (rc != EOK)
    237                 free(*layout);
    238 
    239 error:
    240         async_exchange_end(exch);
    241         return rc;
     237        errno_t retval;
     238        async_wait_for(req, &retval);
     239
     240        if (retval != EOK)
     241                return retval;
     242
     243        size_t length = ipc_get_arg2(&dreply);
     244        assert(length <= INPUT_LAYOUT_NAME_MAXLEN);
     245        layout_buf[length] = '\0';
     246
     247        *layout = str_dup(layout_buf);
     248        if (*layout == NULL)
     249                return ENOMEM;
     250
     251        return EOK;
    242252}
    243253
  • uspace/lib/c/include/ipc/input.h

    r6a208fc r8fb674b  
    3838#include <ipc/common.h>
    3939
     40static size_t const INPUT_LAYOUT_NAME_MAXLEN = 255;
     41
    4042typedef enum {
    4143        INPUT_ACTIVATE = IPC_FIRST_USER_METHOD,
  • uspace/srv/hid/input/input.c

    r6a208fc r8fb674b  
    5050#include <ipc/input.h>
    5151#include <loc.h>
     52#include <macros.h>
    5253#include <ns.h>
    5354#include <stdbool.h>
     
    157158        const char *layout_name = layout_active->name;
    158159        size_t length = str_size(layout_name) + 1;
    159         ipc_call_t id;
    160 
    161         async_answer_1(call, EOK, length);
    162         if (async_data_read_receive(&id, NULL)) {
    163                 async_data_read_finalize(&id, layout_name, length);
    164         }
     160        ipc_call_t rec_call;
     161
     162        size_t max_size;
     163        if (!async_data_read_receive(&rec_call, &max_size)) {
     164                async_answer_0(&rec_call, EREFUSED);
     165                async_answer_0(call, EREFUSED);
     166                return;
     167        }
     168
     169        errno_t rc = async_data_read_finalize(&rec_call, layout_name,
     170            min(length, max_size));
     171        async_answer_0(call, rc);
    165172}
    166173
Note: See TracChangeset for help on using the changeset viewer.