* [PATCH] NFSv4: Fixup smatch warning for ambiguous return
@ 2024-04-17 18:49 Benjamin Coddington
2024-04-17 18:54 ` Dan Carpenter
2024-04-17 18:56 ` Chuck Lever
0 siblings, 2 replies; 3+ messages in thread
From: Benjamin Coddington @ 2024-04-17 18:49 UTC (permalink / raw)
To: Trond Myklebust, Anna Schumaker, Chuck Lever; +Cc: linux-nfs, Dan Carpenter
Dan Carpenter reports smatch warning for nfs4_try_migration() when a memory
allocation failure results in a zero return value. In this case, a
transient allocation failure error will likely be retried the next time the
server responds with NFS4ERR_MOVED.
We can fixup the smatch warning with a small refactor: attempt all three
allocations before testing and returning on a failure.
Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Fixes: c3ed222745d9 ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.")
Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
---
Chuck, does this look sane? I don't have a simple way to test this at the
moment. Also, I think the only result of returning -ENOMEM here instead
would be that we skip continuing to try to migrate for other filesystems on
this client, and we'd get a log message and trace output of the failure.
fs/nfs/nfs4state.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 662e86ea3a2d..5b452411e8fd 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -2116,6 +2116,7 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
{
struct nfs_client *clp = server->nfs_client;
struct nfs4_fs_locations *locations = NULL;
+ struct nfs_fattr *fattr;
struct inode *inode;
struct page *page;
int status, result;
@@ -2125,19 +2126,16 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
(unsigned long long)server->fsid.minor,
clp->cl_hostname);
- result = 0;
page = alloc_page(GFP_KERNEL);
locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
- if (page == NULL || locations == NULL) {
- dprintk("<-- %s: no memory\n", __func__);
- goto out;
- }
- locations->fattr = nfs_alloc_fattr();
- if (locations->fattr == NULL) {
+ fattr = nfs_alloc_fattr();
+ if (page == NULL || locations == NULL || fattr == NULL) {
dprintk("<-- %s: no memory\n", __func__);
+ result = 0;
goto out;
}
+ locations->fattr = fattr;
inode = d_inode(server->super->s_root);
result = nfs4_proc_get_locations(server, NFS_FH(inode), locations,
page, cred);
--
2.44.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] NFSv4: Fixup smatch warning for ambiguous return
2024-04-17 18:49 [PATCH] NFSv4: Fixup smatch warning for ambiguous return Benjamin Coddington
@ 2024-04-17 18:54 ` Dan Carpenter
2024-04-17 18:56 ` Chuck Lever
1 sibling, 0 replies; 3+ messages in thread
From: Dan Carpenter @ 2024-04-17 18:54 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Trond Myklebust, Anna Schumaker, Chuck Lever, linux-nfs
On Wed, Apr 17, 2024 at 02:49:29PM -0400, Benjamin Coddington wrote:
> Dan Carpenter reports smatch warning for nfs4_try_migration() when a memory
> allocation failure results in a zero return value. In this case, a
> transient allocation failure error will likely be retried the next time the
> server responds with NFS4ERR_MOVED.
>
> We can fixup the smatch warning with a small refactor: attempt all three
> allocations before testing and returning on a failure.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: c3ed222745d9 ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.")
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> ---
This preserves the existing behavior and makes the code more readable.
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
regards,
dan carpenter
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] NFSv4: Fixup smatch warning for ambiguous return
2024-04-17 18:49 [PATCH] NFSv4: Fixup smatch warning for ambiguous return Benjamin Coddington
2024-04-17 18:54 ` Dan Carpenter
@ 2024-04-17 18:56 ` Chuck Lever
1 sibling, 0 replies; 3+ messages in thread
From: Chuck Lever @ 2024-04-17 18:56 UTC (permalink / raw)
To: Benjamin Coddington
Cc: Trond Myklebust, Anna Schumaker, linux-nfs, Dan Carpenter
On Wed, Apr 17, 2024 at 02:49:29PM -0400, Benjamin Coddington wrote:
> Dan Carpenter reports smatch warning for nfs4_try_migration() when a memory
> allocation failure results in a zero return value. In this case, a
> transient allocation failure error will likely be retried the next time the
> server responds with NFS4ERR_MOVED.
>
> We can fixup the smatch warning with a small refactor: attempt all three
> allocations before testing and returning on a failure.
>
> Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
> Fixes: c3ed222745d9 ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.")
> Signed-off-by: Benjamin Coddington <bcodding@redhat.com>
> ---
> Chuck, does this look sane? I don't have a simple way to test this at the
> moment. Also, I think the only result of returning -ENOMEM here instead
> would be that we skip continuing to try to migrate for other filesystems on
> this client, and we'd get a log message and trace output of the failure.
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
> fs/nfs/nfs4state.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
> index 662e86ea3a2d..5b452411e8fd 100644
> --- a/fs/nfs/nfs4state.c
> +++ b/fs/nfs/nfs4state.c
> @@ -2116,6 +2116,7 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
> {
> struct nfs_client *clp = server->nfs_client;
> struct nfs4_fs_locations *locations = NULL;
> + struct nfs_fattr *fattr;
> struct inode *inode;
> struct page *page;
> int status, result;
> @@ -2125,19 +2126,16 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
> (unsigned long long)server->fsid.minor,
> clp->cl_hostname);
>
> - result = 0;
> page = alloc_page(GFP_KERNEL);
> locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
> - if (page == NULL || locations == NULL) {
> - dprintk("<-- %s: no memory\n", __func__);
> - goto out;
> - }
> - locations->fattr = nfs_alloc_fattr();
> - if (locations->fattr == NULL) {
> + fattr = nfs_alloc_fattr();
> + if (page == NULL || locations == NULL || fattr == NULL) {
> dprintk("<-- %s: no memory\n", __func__);
> + result = 0;
> goto out;
> }
>
> + locations->fattr = fattr;
> inode = d_inode(server->super->s_root);
> result = nfs4_proc_get_locations(server, NFS_FH(inode), locations,
> page, cred);
> --
> 2.44.0
>
--
Chuck Lever
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-17 19:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17 18:49 [PATCH] NFSv4: Fixup smatch warning for ambiguous return Benjamin Coddington
2024-04-17 18:54 ` Dan Carpenter
2024-04-17 18:56 ` Chuck Lever
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.