Skip to content

Commit 3b97283

Browse files
bcodding-rhroxanan1996
authored andcommitted
NFSv4: Fixup smatch warning for ambiguous return
BugLink: https://bugs.launchpad.net/bugs/2073603 [ Upstream commit 37ffe06537af3e3ec212e7cbe941046fce0a822f ] 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: c3ed222 ("NFSv4: Fix free of uninitialized nfs4_label on referral lookup.") Signed-off-by: Benjamin Coddington <bcodding@redhat.com> Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Portia Stephens <portia.stephens@canonical.com> Signed-off-by: Roxana Nicolescu <roxana.nicolescu@canonical.com>
1 parent fb595d7 commit 3b97283

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
@@ -2117,6 +2117,7 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
21172117
{
21182118
struct nfs_client *clp = server->nfs_client;
21192119
struct nfs4_fs_locations *locations = NULL;
2120+
struct nfs_fattr *fattr;
21202121
struct inode *inode;
21212122
struct page *page;
21222123
int status, result;
@@ -2126,19 +2127,16 @@ static int nfs4_try_migration(struct nfs_server *server, const struct cred *cred
21262127
(unsigned long long)server->fsid.minor,
21272128
clp->cl_hostname);
21282129

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

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

0 commit comments

Comments
 (0)