/*
- * arch/ppc/syslib/rheap.c
- *
* A Remote Heap. Remote means that we don't touch the memory that the
* heap points to. Normal heap implementations use the memory they manage
* to place their list. We cannot do that because the memory we manage may
/* Grow the after block backwards */
if (before == NULL && after != NULL) {
- (int8_t *) after->start -= size;
+ after->start = (int8_t *)after->start - size;
after->size += size;
return;
}
/* Alignment must be a power of two */
if ((alignment & (alignment - 1)) != 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (info == NULL)
- return NULL;
+ return ERR_PTR(-ENOMEM);
info->alignment = alignment;
/* Validate size */
if (size <= 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
/* The region must be aligned */
s = (unsigned long)start;
e = e & ~m;
if (assure_empty(info, 1) < 0)
- return NULL;
+ return ERR_PTR(-ENOMEM);
blk = NULL;
list_for_each(l, &info->free_list) {
}
if (blk == NULL)
- return NULL;
+ return ERR_PTR(-ENOMEM);
/* Perfect fit */
if (bs == s && be == e) {
/* blk still in free list, with updated start and/or size */
if (bs == s || be == e) {
if (bs == s)
- (int8_t *) blk->start += size;
+ blk->start = (int8_t *)blk->start + size;
blk->size -= size;
} else {
/* Validate size */
if (size <= 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
/* Align to configured alignment */
size = (size + (info->alignment - 1)) & ~(info->alignment - 1);
if (assure_empty(info, 1) < 0)
- return NULL;
+ return ERR_PTR(-ENOMEM);
blk = NULL;
list_for_each(l, &info->free_list) {
}
if (blk == NULL)
- return NULL;
+ return ERR_PTR(-ENOMEM);
/* Just fits */
if (blk->size == size) {
newblk->owner = owner;
/* blk still in free list, with updated start, size */
- (int8_t *) blk->start += size;
+ blk->start = (int8_t *)blk->start + size;
blk->size -= size;
start = newblk->start;
/* Validate size */
if (size <= 0)
- return NULL;
+ return ERR_PTR(-EINVAL);
/* The region must be aligned */
s = (unsigned long)start;
e = e & ~m;
if (assure_empty(info, 2) < 0)
- return NULL;
+ return ERR_PTR(-ENOMEM);
blk = NULL;
list_for_each(l, &info->free_list) {
}
if (blk == NULL)
- return NULL;
+ return ERR_PTR(-ENOMEM);
/* Perfect fit */
if (bs == s && be == e) {
/* blk still in free list, with updated start and/or size */
if (bs == s || be == e) {
if (bs == s)
- (int8_t *) blk->start += size;
+ blk->start = (int8_t *)blk->start + size;
blk->size -= size;
} else {
return -EINVAL;
blk->owner = owner;
+ size = blk->size;
return size;
}