@@ -2256,22 +2256,15 @@ static struct reserve_mem_table reserved_mem_table[RESERVE_MEM_MAX_ENTRIES];
static int reserved_mem_count;
/* Add wildcard region with a lookup name */
-static int __init reserved_mem_add(phys_addr_t start, phys_addr_t size,
+static void __init reserved_mem_add(phys_addr_t start, phys_addr_t size,
const char *name)
{
struct reserve_mem_table *map;
- if (!name || !name[0] || strlen(name) >= RESERVE_MEM_NAME_SIZE)
- return -EINVAL;
-
- if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES)
- return -1;
-
map = &reserved_mem_table[reserved_mem_count++];
map->start = start;
map->size = size;
strscpy(map->name, name);
- return 0;
}
/**
@@ -2280,6 +2273,8 @@ static int __init reserved_mem_add(phys_addr_t start, phys_addr_t size,
* @start: If found, holds the start address
* @size: If found, holds the size of the address.
*
+ * @start and @size are only updated if @name is found.
+ *
* Returns: 1 if found or 0 if not found.
*/
int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size)
@@ -2309,11 +2304,15 @@ static int __init reserve_mem(char *p)
phys_addr_t start, size, align;
char *name;
char *oldp;
- int err;
+ int len;
if (!p)
return -EINVAL;
+ /* Check if there's room for more reserved memory */
+ if (reserved_mem_count >= RESERVE_MEM_MAX_ENTRIES)
+ return -EBUSY;
+
oldp = p;
size = memparse(p, &p);
if (!size || p == oldp)
@@ -2330,11 +2329,14 @@ static int __init reserve_mem(char *p)
* memblock_phys_alloc() doesn't like a zero size align,
* but it is OK for this command to have it.
*/
- if (align <= SMP_CACHE_BYTES)
+ if (align < SMP_CACHE_BYTES)
align = SMP_CACHE_BYTES;
name = p + 1;
- if (!strlen(name))
+ len = strlen(name);
+
+ /* name needs to have length but not too big */
+ if (!len || len >= RESERVE_MEM_NAME_SIZE)
return -EINVAL;
/* Make sure that name has text */
@@ -2345,15 +2347,15 @@ static int __init reserve_mem(char *p)
if (!*p)
return -EINVAL;
+ /* Make sure the name is not already used (size is only updated if found) */
+ if (reserve_mem_find_by_name(name, &start, &size))
+ return -EBUSY;
+
start = memblock_phys_alloc(size, align);
if (!start)
return -ENOMEM;
- err = reserved_mem_add(start, size, name);
- if (err) {
- memblock_phys_free(start, size);
- return err;
- }
+ reserved_mem_add(start, size, name);
return 0;
}