From: Weston Andros Adamson <dros@netapp.com>
To: <Trond.Myklebust@netapp.com>
Cc: <linux-nfs@vger.kernel.org>, Weston Andros Adamson <dros@netapp.com>
Subject: [PATCH 5/5] NFSv4: clean up nfs4_state reference counting
Date: Mon, 21 Oct 2013 13:10:14 -0400 [thread overview]
Message-ID: <1382375414-5854-6-git-send-email-dros@netapp.com> (raw)
In-Reply-To: <1382375414-5854-1-git-send-email-dros@netapp.com>
Use atomic_inc_not_zero() to avoid referencing a state that is currently
being freed.
Signed-off-by: Weston Andros Adamson <dros@netapp.com>
---
fs/nfs/nfs4proc.c | 8 ++++++--
fs/nfs/nfs4state.c | 3 ++-
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index a3b78df..005543d 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -1275,7 +1275,8 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
out:
return ERR_PTR(ret);
out_return_state:
- atomic_inc(&state->count);
+ if (!atomic_inc_not_zero(&state->count))
+ return ERR_PTR(-EINVAL);
return state;
}
@@ -1429,7 +1430,10 @@ static struct nfs4_opendata *nfs4_open_recoverdata_alloc(struct nfs_open_context
if (opendata == NULL)
return ERR_PTR(-ENOMEM);
opendata->state = state;
- atomic_inc(&state->count);
+ if (!atomic_inc_not_zero(&state->count)) {
+ nfs4_opendata_put(opendata);
+ return ERR_PTR(-EINVAL);
+ }
return opendata;
}
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index cc14cbb..1c71907 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -1416,7 +1416,8 @@ restart:
continue;
if (state->state == 0)
continue;
- atomic_inc(&state->count);
+ if (!atomic_inc_not_zero(&state->count))
+ continue;
spin_unlock(&sp->so_lock);
status = ops->recover_open(sp, state);
if (status >= 0) {
--
1.7.12.4 (Apple Git-37)
next prev parent reply other threads:[~2013-10-21 17:10 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-21 17:10 [PATCH 0/5] Clean up open CLAIM_PREVIOUS code path Weston Andros Adamson
2013-10-21 17:10 ` [PATCH 1/5] NFSv4: fix NULL dereference in open recover Weston Andros Adamson
2013-10-25 6:08 ` William Dauchy
2013-10-21 17:10 ` [PATCH 2/5] NFSv4: don't fail on missing fattr " Weston Andros Adamson
2013-10-21 17:10 ` [PATCH 3/5] NFSv4: clean up state ref counting " Weston Andros Adamson
2013-10-28 21:06 ` Myklebust, Trond
2013-10-29 12:32 ` Weston Andros Adamson
2013-10-29 12:33 ` Weston Andros Adamson
2013-10-29 12:41 ` Myklebust, Trond
2013-10-29 13:12 ` Weston Andros Adamson
2013-10-21 17:10 ` [PATCH 4/5] NFSv4: don't reprocess cached open CLAIM_PREVIOUS Weston Andros Adamson
2013-10-28 21:08 ` Myklebust, Trond
2013-10-28 23:00 ` Weston Andros Adamson
2013-10-21 17:10 ` Weston Andros Adamson [this message]
2013-10-28 18:45 ` [PATCH 5/5] NFSv4: clean up nfs4_state reference counting Myklebust, Trond
2013-10-28 18:53 ` Weston Andros Adamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1382375414-5854-6-git-send-email-dros@netapp.com \
--to=dros@netapp.com \
--cc=Trond.Myklebust@netapp.com \
--cc=linux-nfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).