Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 277170
b: refs/heads/master
c: eb18f1b
h: refs/heads/master
v: v3
  • Loading branch information
Tejun Heo committed Dec 8, 2011
1 parent 09dd146 commit 37e0eda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 719361809fde9dbe9ccc4cf71f9fa9add5fa8bf9
refs/heads/master: eb18f1b5bfb99b1d7d2f5d792e6ee5c9b7d89330
15 changes: 12 additions & 3 deletions trunk/mm/memblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ static inline const char *memblock_type_name(struct memblock_type *type)
return "unknown";
}

/* adjust *@size so that (@base + *@size) doesn't overflow, return new size */
static inline phys_addr_t memblock_cap_size(phys_addr_t base, phys_addr_t *size)
{
return *size = min(*size, (phys_addr_t)ULLONG_MAX - base);
}

/*
* Address comparison utilities
*/
Expand Down Expand Up @@ -328,7 +334,8 @@ static int __init_memblock memblock_add_region(struct memblock_type *type,
phys_addr_t base, phys_addr_t size)
{
bool insert = false;
phys_addr_t obase = base, end = base + size;
phys_addr_t obase = base;
phys_addr_t end = base + memblock_cap_size(base, &size);
int i, nr_new;

/* special case for empty array */
Expand Down Expand Up @@ -420,7 +427,7 @@ static int __init_memblock memblock_isolate_range(struct memblock_type *type,
phys_addr_t base, phys_addr_t size,
int *start_rgn, int *end_rgn)
{
phys_addr_t end = base + size;
phys_addr_t end = base + memblock_cap_size(base, &size);
int i;

*start_rgn = *end_rgn = 0;
Expand Down Expand Up @@ -868,16 +875,18 @@ int __init_memblock memblock_is_memory(phys_addr_t addr)
int __init_memblock memblock_is_region_memory(phys_addr_t base, phys_addr_t size)
{
int idx = memblock_search(&memblock.memory, base);
phys_addr_t end = base + memblock_cap_size(base, &size);

if (idx == -1)
return 0;
return memblock.memory.regions[idx].base <= base &&
(memblock.memory.regions[idx].base +
memblock.memory.regions[idx].size) >= (base + size);
memblock.memory.regions[idx].size) >= end;
}

int __init_memblock memblock_is_region_reserved(phys_addr_t base, phys_addr_t size)
{
memblock_cap_size(base, &size);
return memblock_overlaps_region(&memblock.reserved, base, size) >= 0;
}

Expand Down

0 comments on commit 37e0eda

Please sign in to comment.