From: Anna Schumaker <anna@kernel.org>
To: linux-nfs@vger.kernel.org, trond.myklebust@hammerspace.com
Cc: anna@kernel.org
Subject: [PATCH 4/5] NFS: Clean up find_nfs_version()
Date: Tue, 1 Oct 2024 16:33:43 -0400 [thread overview]
Message-ID: <20241001203344.327044-5-anna@kernel.org> (raw)
In-Reply-To: <20241001203344.327044-1-anna@kernel.org>
From: Anna Schumaker <anna.schumaker@oracle.com>
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>
---
fs/nfs/client.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index 63620766f2a1..4fe5a635f329 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -87,9 +87,6 @@ static struct nfs_subversion *__find_nfs_version(unsigned int version)
read_lock(&nfs_version_lock);
nfs = nfs_version_mods[version];
read_unlock(&nfs_version_lock);
-
- if (nfs == NULL)
- return ERR_PTR(-EPROTONOSUPPORT);
return nfs;
}
@@ -97,13 +94,15 @@ struct nfs_subversion *find_nfs_version(unsigned int version)
{
struct nfs_subversion *nfs = __find_nfs_version(version);
- if (IS_ERR(nfs)) {
- request_module("nfsv%d", version);
+ if (!nfs && request_module("nfsv%d", version) == 0)
nfs = __find_nfs_version(version);
- }
- if (!IS_ERR(nfs) && !try_module_get(nfs->owner))
+ if (!nfs)
+ return ERR_PTR(-EPROTONOSUPPORT);
+
+ if (!try_module_get(nfs->owner))
return ERR_PTR(-EAGAIN);
+
return nfs;
}
--
2.46.2
next prev parent reply other threads:[~2024-10-01 20:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 20:33 [PATCH 0/5] NFS: Clean up NFS version module loading Anna Schumaker
2024-10-01 20:33 ` [PATCH 1/5] NFS: Clean up locking the nfs_versions list Anna Schumaker
2024-10-01 20:33 ` [PATCH 2/5] NFS: Convert the NFS module list into an array Anna Schumaker
2024-10-01 20:33 ` [PATCH 3/5] NFS: Rename get_nfs_version() -> find_nfs_version() Anna Schumaker
2024-10-01 20:33 ` Anna Schumaker [this message]
2024-10-01 20:33 ` [PATCH 5/5] NFS: Implement get_nfs_version() Anna Schumaker
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=20241001203344.327044-5-anna@kernel.org \
--to=anna@kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=trond.myklebust@hammerspace.com \
/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