Skip to content

Commit d078cbf

Browse files
Guoqing Jiangchucklever
authored andcommitted
nfsd: call cache_put if xdr_reserve_space returns NULL
If not enough buffer space available, but idmap_lookup has triggered lookup_fn which calls cache_get and returns successfully. Then we missed to call cache_put here which pairs with cache_get. Fixes: ddd1ea5 ("nfsd4: use xdr_reserve_space in attribute encoding") Signed-off-by: Guoqing Jiang <[email protected]> Reviwed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent ba017fd commit d078cbf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

fs/nfsd/nfs4idmap.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ static __be32 idmap_id_to_name(struct xdr_stream *xdr,
581581
.id = id,
582582
.type = type,
583583
};
584+
__be32 status = nfs_ok;
584585
__be32 *p;
585586
int ret;
586587
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
@@ -593,12 +594,16 @@ static __be32 idmap_id_to_name(struct xdr_stream *xdr,
593594
return nfserrno(ret);
594595
ret = strlen(item->name);
595596
WARN_ON_ONCE(ret > IDMAP_NAMESZ);
597+
596598
p = xdr_reserve_space(xdr, ret + 4);
597-
if (!p)
598-
return nfserr_resource;
599-
p = xdr_encode_opaque(p, item->name, ret);
599+
if (unlikely(!p)) {
600+
status = nfserr_resource;
601+
goto out_put;
602+
}
603+
xdr_encode_opaque(p, item->name, ret);
604+
out_put:
600605
cache_put(&item->h, nn->idtoname_cache);
601-
return 0;
606+
return status;
602607
}
603608

604609
static bool

0 commit comments

Comments
 (0)