Changeset 7473807 in mainline for kernel/generic/src/ipc


Ignore:
Timestamp:
2018-05-11T20:22:42Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d2c5159
Parents:
ae89656
Message:

Use atomic malloc allocations

We can safely use atomic allocations in places that use the non-failing
version of malloc(), but test the return value anyway. And also in some
places that can afford to return failure but did not because of comfort.

Location:
kernel/generic/src/ipc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/ipc/irq.c

    rae89656 r7473807  
    8282{
    8383        /* Copy the physical base addresses aside. */
    84         uintptr_t *pbase = malloc(rangecount * sizeof(uintptr_t), 0);
     84        uintptr_t *pbase = malloc(rangecount * sizeof(uintptr_t), FRAME_ATOMIC);
     85        if (!pbase)
     86                return ENOMEM;
    8587        for (size_t i = 0; i < rangecount; i++)
    8688                pbase[i] = ranges[i].base;
     
    225227        irq_cmd_t *cmds = NULL;
    226228
    227         irq_code_t *code = malloc(sizeof(*code), 0);
     229        irq_code_t *code = malloc(sizeof(*code), FRAME_ATOMIC);
     230        if (!code)
     231                return NULL;
    228232        errno_t rc = copy_from_uspace(code, ucode, sizeof(*code));
    229233        if (rc != EOK)
     
    234238                goto error;
    235239
    236         ranges = malloc(sizeof(code->ranges[0]) * code->rangecount, 0);
     240        ranges = malloc(sizeof(code->ranges[0]) * code->rangecount,
     241            FRAME_ATOMIC);
     242        if (!ranges)
     243                goto error;
    237244        rc = copy_from_uspace(ranges, code->ranges,
    238245            sizeof(code->ranges[0]) * code->rangecount);
     
    240247                goto error;
    241248
    242         cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, 0);
     249        cmds = malloc(sizeof(code->cmds[0]) * code->cmdcount, FRAME_ATOMIC);
     250        if (!cmds)
     251                goto error;
    243252        rc = copy_from_uspace(cmds, code->cmds,
    244253            sizeof(code->cmds[0]) * code->cmdcount);
  • kernel/generic/src/ipc/ops/dataread.c

    rae89656 r7473807  
    7575                        IPC_SET_ARG1(answer->data, dst);
    7676
    77                         answer->buffer = malloc(size, 0);
     77                        answer->buffer = malloc(size, FRAME_ATOMIC);
     78                        if (!answer->buffer) {
     79                                IPC_SET_RETVAL(answer->data, ENOMEM);
     80                                return EOK;
     81                        }
    7882                        errno_t rc = copy_from_uspace(answer->buffer,
    7983                            (void *) src, size);
     
    8488                                 * ipc_call_free().
    8589                                 */
     90                                return EOK;
    8691                        }
    8792                } else if (!size) {
  • kernel/generic/src/ipc/ops/datawrite.c

    rae89656 r7473807  
    5656        }
    5757
    58         call->buffer = (uint8_t *) malloc(size, 0);
     58        call->buffer = (uint8_t *) malloc(size, FRAME_ATOMIC);
     59        if (!call->buffer)
     60                return ENOMEM;
    5961        errno_t rc = copy_from_uspace(call->buffer, (void *) src, size);
    6062        if (rc != EOK) {
Note: See TracChangeset for help on using the changeset viewer.