Skip to contentSkip to conversation

lib/genalloc.c: fix the end addr check in addr_in_gen_pool()

PATCH In review Toshi Kikuchi 2 participants 2 messages Dec 19, 2014 – Dec 22, 2014 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/genalloc.c: fix the end addr check in addr_in_gen_pool()

Since chunk->end_addr is (chunk->start_addr + size - 1), the end address to compare should be (start + size - 1).

---
 lib/genalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/genalloc.c +1 -1
index 2e65d20..42a95e9 100644
@@ -415,7 +415,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
 			size_t size)
 {
 	bool found = false;
-	unsigned long end = start + size;
+	unsigned long end = start + size - 1;
 	struct gen_pool_chunk *chunk;
 
 	rcu_read_lock();
Signature · 1 line
2.2.0.rc0.207.ga3a616c
maintainer
#1 lore raw
Quoted 13 lines · On Thu, 18 Dec 2014 18:30:59 -0800 Toshi Kikuchi <[email protected]> wrote:

Since chunk->end_addr is (chunk->start_addr + size - 1), the end address to compare should be (start + size - 1).

---
 lib/genalloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/genalloc.c +0 -0
index 2e65d20..42a95e9 100644

lib/genalloc.c bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start, · line 421

Quoted 8 lines
lib/genalloc.c +1 -1
@@ -415,7 +415,7 @@ bool addr_in_gen_pool(struct gen_pool *pool, unsigned long start,
 			size_t size)
 {
 	bool found = false;
-	unsigned long end = start + size;
+	unsigned long end = start + size - 1;
 	struct gen_pool_chunk *chunk;
 
 	rcu_read_lock();

urgh. gen_pool_chunk.end_addr should have been made exclusive, not inclusive. Or switch to start_addr/size. The code would be considerably nicer that way.

And the struct gen_pool_chunk definition should be moved into genalloc.c. I'm not sure what drivers/acpi/apei/ghes.c is doing fiddling around with genalloc internals, but it should stop doing it.

Sigh :(