From: Alex Vainman Date: Mon, 1 Feb 2010 05:58:00 +0000 (+0200) Subject: Increment node refcount in ibv_madvise_range() only if madvise() succeeds X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=44628a06209a0f1cfc80bca67111648399954806;p=~shefty%2Flibibverbs.git 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 --- 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); }