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

NFS: Clean up find_nfs_version()

It's good practice to check the return value of request_module() to see
if the module has been found. It's also a little easier to follow the
code if __find_nfs_version() doesn't attempt to convert NULL pointers
into -EPROTONOSUPPORT.

Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>

authored by

Anna Schumaker and committed by
Trond Myklebust
3c91e4b7 df50b5ee

+6 -7
+6 -7
fs/nfs/client.c
··· 87 87 read_lock(&nfs_version_lock); 88 88 nfs = nfs_version_mods[version]; 89 89 read_unlock(&nfs_version_lock); 90 - 91 - if (nfs == NULL) 92 - return ERR_PTR(-EPROTONOSUPPORT); 93 90 return nfs; 94 91 } 95 92 ··· 94 97 { 95 98 struct nfs_subversion *nfs = __find_nfs_version(version); 96 99 97 - if (IS_ERR(nfs)) { 98 - request_module("nfsv%d", version); 100 + if (!nfs && request_module("nfsv%d", version) == 0) 99 101 nfs = __find_nfs_version(version); 100 - } 101 102 102 - if (!IS_ERR(nfs) && !try_module_get(nfs->owner)) 103 + if (!nfs) 104 + return ERR_PTR(-EPROTONOSUPPORT); 105 + 106 + if (!try_module_get(nfs->owner)) 103 107 return ERR_PTR(-EAGAIN); 108 + 104 109 return nfs; 105 110 } 106 111