[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1322508685-32532-10-git-send-email-tj@kernel.org>
Date: Mon, 28 Nov 2011 11:31:11 -0800
From: Tejun Heo <tj@...nel.org>
To: benh@...nel.crashing.org, yinghai@...nel.org, hpa@...or.com,
tony.luck@...el.com, ralf@...ux-mips.org, schwidefsky@...ibm.com,
liqin.chen@...plusct.com, lethal@...ux-sh.org, davem@...emloft.net,
linux-kernel@...r.kernel.org, linux-arch@...r.kernel.org,
mingo@...hat.com, jonas@...thpole.se, lennox.wu@...il.com
Cc: Tejun Heo <tj@...nel.org>
Subject: [PATCH 09/23] memblock: Make memblock functions handle overflowing range @size
Allow memblock users to specify range where @base + @size overflows
and automatically cap it at maximum. This makes the interface more
robust and specifying till-the-end-of-memory easier.
Signed-off-by: Tejun Heo <tj@...nel.org>
Cc: Benjamin Herrenschmidt <benh@...nel.crashing.org>
Cc: Yinghai Lu <yinghai@...nel.org>
---
mm/memblock.c | 15 ++++++++++++---
1 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/mm/memblock.c b/mm/memblock.c
index fffe68b..945dc31 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -49,6 +49,12 @@ static inline const char *memblock_type_name(struct memblock_type *type)
return "unknown";
}
+/* adjust *@...e so that (@base + *@...e) 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
*/
@@ -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 */
@@ -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;
@@ -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;
}
--
1.7.3.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists