Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nfsd: avoid uninitialized variable warning

clang warns that 'contextlen' may be accessed without an initialization:

fs/nfsd/nfs4xdr.c:2911:9: error: variable 'contextlen' is uninitialized when used here [-Werror,-Wuninitialized]
contextlen);
^~~~~~~~~~
fs/nfsd/nfs4xdr.c:2424:16: note: initialize the variable 'contextlen' to silence this warning
int contextlen;
^
= 0

Presumably this cannot happen, as FATTR4_WORD2_SECURITY_LABEL is
set if CONFIG_NFSD_V4_SECURITY_LABEL is enabled.
Adding another #ifdef like the other two in this function
avoids the warning.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: J. Bruce Fields <bfields@redhat.com>

authored by

Arnd Bergmann and committed by
J. Bruce Fields
0ab88ca4 f456458e

+4
+4
fs/nfsd/nfs4xdr.c
··· 2420 2420 __be32 status; 2421 2421 int err; 2422 2422 struct nfs4_acl *acl = NULL; 2423 + #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 2423 2424 void *context = NULL; 2424 2425 int contextlen; 2426 + #endif 2425 2427 bool contextsupport = false; 2426 2428 struct nfsd4_compoundres *resp = rqstp->rq_resp; 2427 2429 u32 minorversion = resp->cstate.minorversion; ··· 2908 2906 *p++ = cpu_to_be32(NFS4_CHANGE_TYPE_IS_TIME_METADATA); 2909 2907 } 2910 2908 2909 + #ifdef CONFIG_NFSD_V4_SECURITY_LABEL 2911 2910 if (bmval2 & FATTR4_WORD2_SECURITY_LABEL) { 2912 2911 status = nfsd4_encode_security_label(xdr, rqstp, context, 2913 2912 contextlen); 2914 2913 if (status) 2915 2914 goto out; 2916 2915 } 2916 + #endif 2917 2917 2918 2918 attrlen = htonl(xdr->buf->len - attrlen_offset - 4); 2919 2919 write_bytes_to_xdr_buf(xdr->buf, attrlen_offset, &attrlen, 4);