Skip to content

Commit 37ffe06

Browse files
bcodding-rhTrond Myklebust
authored andcommitted
NFSv4: Fixup smatch warning for ambiguous return
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 <[email protected]> Fixes: c3ed222 ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.") Signed-off-by: Benjamin Coddington <[email protected]> Reviewed-by: Dan Carpenter <[email protected]> Reviewed-by: Chuck Lever <[email protected]> Signed-off-by: Trond Myklebust <[email protected]>
1 parent bf95f82 commit 37ffe06

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

fs/nfs/nfs4state.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,7 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
21162116
{
21172117
struct nfs_client *clp = server->nfs_client;
21182118
struct nfs4_fs_locations *locations = NULL;
2119+
struct nfs_fattr *fattr;
21192120
struct inode *inode;
21202121
struct page *page;
21212122
int status, result;
@@ -2125,19 +2126,16 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
21252126
(unsigned long long)server->fsid.minor,
21262127
clp->cl_hostname);
21272128

2128-
result = 0;
21292129
page = alloc_page(GFP_KERNEL);
21302130
locations = kmalloc(sizeof(struct nfs4_fs_locations), GFP_KERNEL);
2131-
if (page == NULL || locations == NULL) {
2132-
dprintk("<-- %s: no memory\n", __func__);
2133-
goto out;
2134-
}
2135-
locations->fattr = nfs_alloc_fattr();
2136-
if (locations->fattr == NULL) {
2131+
fattr = nfs_alloc_fattr();
2132+
if (page == NULL || locations == NULL || fattr == NULL) {
21372133
dprintk("<-- %s: no memory\n", __func__);
2134+
result = 0;
21382135
goto out;
21392136
}
21402137

2138+
locations->fattr = fattr;
21412139
inode = d_inode(server->super->s_root);
21422140
result = nfs4_proc_get_locations(server, NFS_FH(inode), locations,
21432141
page, cred);

0 commit comments

Comments
 (0)