From 44628a06209a0f1cfc80bca67111648399954806 Mon Sep 17 00:00:00 2001 From: Alex Vainman Date: Mon, 1 Feb 2010 07:58:00 +0200 Subject: [PATCH] Increment node refcount in ibv_madvise_range() only if madvise() succeeds ibv_madvise_range() first updates the memory range reference count and then calls to madvise(). If madvise() fails, the reference count of the failed node is incorrect. Fix this by updating the node's reference count only after a successful call to madvise() (or if no call to madvise() was needed). Signed-off-by: Alex Vainman Signed-off-by: Roland Dreier --- src/memory.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/memory.c b/src/memory.c index 51839e2..6a3305f 100644 --- a/src/memory.c +++ b/src/memory.c @@ -521,10 +521,8 @@ static int ibv_madvise_range(void *base, size_t size, int advice) } } - node->refcnt += inc; - - if ((inc == -1 && node->refcnt == 0) || - (inc == 1 && node->refcnt == 1)) { + if ((inc == -1 && node->refcnt == 1) || + (inc == 1 && node->refcnt == 0)) { /* * If this is the first time through the loop, * and we merged this node with the previous @@ -547,6 +545,7 @@ static int ibv_madvise_range(void *base, size_t size, int advice) goto out; } + node->refcnt += inc; node = __mm_next(node); } -- 2.46.0