aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Vainman <alexonlists@gmail.com>2010-02-01 07:58:00 +0200
committerRoland Dreier <rolandd@cisco.com>2010-03-19 11:04:10 -0700
commit44628a06209a0f1cfc80bca67111648399954806 (patch)
treef271e1774f173aa72b283e31cfbb404d2d87d6b8
parentc2fa381cf71148f01b4958f3e46650f55effa763 (diff)
downloadlibibverbs-44628a06209a0f1cfc80bca67111648399954806.tar.gz
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 <alexv@voltaire.com> Signed-off-by: Roland Dreier <rolandd@cisco.com>
-rw-r--r--src/memory.c7
1 files 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);
}