Changeset 7473807 in mainline for kernel/generic/src/mm/as.c


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/mm/as.c

    rae89656 r7473807  
    620620        }
    621621
    622         as_area_t *area = (as_area_t *) malloc(sizeof(as_area_t), 0);
     622        as_area_t *area = (as_area_t *) malloc(sizeof(as_area_t), FRAME_ATOMIC);
     623        if (!area) {
     624                mutex_unlock(&as->lock);
     625                return NULL;
     626        }
    623627
    624628        mutex_initialize(&area->lock, MUTEX_PASSIVE);
     
    646650         */
    647651        if (!(attrs & AS_AREA_ATTR_PARTIAL)) {
    648                 si = (share_info_t *) malloc(sizeof(share_info_t), 0);
     652                si = (share_info_t *) malloc(sizeof(share_info_t),
     653                    FRAME_ATOMIC);
     654                if (!si) {
     655                        free(area);
     656                        mutex_unlock(&as->lock);
     657                        return NULL;
     658                }
    649659                mutex_initialize(&si->lock, MUTEX_PASSIVE);
    650660                si->refcount = 1;
     
    12921302
    12931303        /* An array for storing frame numbers */
    1294         uintptr_t *old_frame = malloc(used_pages * sizeof(uintptr_t), 0);
     1304        uintptr_t *old_frame = malloc(used_pages * sizeof(uintptr_t),
     1305            FRAME_ATOMIC);
     1306        if (!old_frame) {
     1307                mutex_unlock(&area->lock);
     1308                mutex_unlock(&as->lock);
     1309                return ENOMEM;
     1310        }
    12951311
    12961312        page_table_lock(as, false);
Note: See TracChangeset for help on using the changeset viewer.