Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Make nfs_file_cred more robust.

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>

authored by

Neil Brown and committed by
Trond Myklebust
504e5189 18de9735

+10 -4
+4 -2
fs/nfs/nfs4proc.c
··· 1659 1659 struct nfs_open_context *ctx; 1660 1660 1661 1661 ctx = nfs_file_open_context(sattr->ia_file); 1662 - cred = ctx->cred; 1663 - state = ctx->state; 1662 + if (ctx) { 1663 + cred = ctx->cred; 1664 + state = ctx->state; 1665 + } 1664 1666 } 1665 1667 1666 1668 status = nfs4_do_setattr(inode, cred, fattr, sattr, state);
+6 -2
include/linux/nfs_fs.h
··· 367 367 368 368 static inline struct rpc_cred *nfs_file_cred(struct file *file) 369 369 { 370 - if (file != NULL) 371 - return nfs_file_open_context(file)->cred; 370 + if (file != NULL) { 371 + struct nfs_open_context *ctx = 372 + nfs_file_open_context(file); 373 + if (ctx) 374 + return ctx->cred; 375 + } 372 376 return NULL; 373 377 } 374 378