Ignore:
Timestamp:
2018-05-11T20:22:42Z (6 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/udebug/udebug_ops.c

    rae89656 r7473807  
    370370
    371371        /* Allocate a buffer to hold thread IDs */
    372         sysarg_t *id_buffer = malloc(buf_size + 1, 0);
     372        sysarg_t *id_buffer = malloc(buf_size + 1, FRAME_ATOMIC);
     373        if (!id_buffer)
     374                return ENOMEM;
    373375
    374376        mutex_lock(&TASK->udebug.lock);
     
    432434        size_t name_size = str_size(TASK->name) + 1;
    433435
    434         *data = malloc(name_size, 0);
     436        *data = malloc(name_size, FRAME_ATOMIC);
     437        if (!*data)
     438                return ENOMEM;
    435439        *data_size = name_size;
    436440
     
    472476
    473477        /* Prepare a buffer to hold the arguments. */
    474         sysarg_t *arg_buffer = malloc(6 * sizeof(sysarg_t), 0);
     478        sysarg_t *arg_buffer = malloc(6 * sizeof(sysarg_t), FRAME_ATOMIC);
     479        if (!arg_buffer) {
     480                _thread_op_end(thread);
     481                return ENOMEM;
     482        }
    475483
    476484        /* Copy to a local buffer before releasing the lock. */
     
    514522
    515523        /* Prepare a buffer to hold the data. */
    516         istate_t *state_buf = malloc(sizeof(istate_t), 0);
     524        istate_t *state_buf = malloc(sizeof(istate_t), FRAME_ATOMIC);
     525        if (!state_buf) {
     526                _thread_op_end(thread);
     527                return ENOMEM;
     528        }
    517529
    518530        /* Copy to the allocated buffer */
     
    546558        }
    547559
    548         void *data_buffer = malloc(n, 0);
     560        void *data_buffer = malloc(n, FRAME_ATOMIC);
     561        if (!data_buffer) {
     562                mutex_unlock(&TASK->udebug.lock);
     563                return ENOMEM;
     564        }
    549565
    550566        /*
Note: See TracChangeset for help on using the changeset viewer.