Skip to content

Commit

Permalink
Make nfs_file_cred more robust.
Browse files Browse the repository at this point in the history
As not all files have an associated open_context (e.g. device special
files), it is safest to test for the existence of the open context
before de-referencing it.

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
  • Loading branch information
Neil Brown authored and Trond Myklebust committed Oct 17, 2008
1 parent 18de973 commit 504e518
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions fs/nfs/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1659,8 +1659,10 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
struct nfs_open_context *ctx;

ctx = nfs_file_open_context(sattr->ia_file);
cred = ctx->cred;
state = ctx->state;
if (ctx) {
cred = ctx->cred;
state = ctx->state;
}
}

status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
Expand Down
8 changes: 6 additions & 2 deletions include/linux/nfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,12 @@ static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)

static inline struct rpc_cred *nfs_file_cred(struct file *file)
{
if (file != NULL)
return nfs_file_open_context(file)->cred;
if (file != NULL) {
struct nfs_open_context *ctx =
nfs_file_open_context(file);
if (ctx)
return ctx->cred;
}
return NULL;
}

Expand Down

0 comments on commit 504e518

Please sign in to comment.