]> www.infradead.org Git - users/hch/block.git/commitdiff
nfs: fix undefined behavior in nfs_block_bits()
authorSergey Shtylyov <s.shtylyov@omp.ru>
Fri, 10 May 2024 20:24:04 +0000 (23:24 +0300)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Tue, 21 May 2024 12:34:15 +0000 (08:34 -0400)
Shifting *signed int* typed constant 1 left by 31 bits causes undefined
behavior. Specify the correct *unsigned long* type by using 1UL instead.

Found by Linux Verification Center (linuxtesting.org) with the Svace static
analysis tool.

Cc: stable@vger.kernel.org
Signed-off-by: Sergey Shtylyov <s.shtylyov@omp.ru>
Reviewed-by: Benjamin Coddington <bcodding@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/internal.h

index dc0693b3d2144fca01af0893e1058a6885f1e825..9f0f4534744ba4d10050d13559a115b7ccd617cc 100644 (file)
@@ -717,9 +717,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
        if ((bsize & (bsize - 1)) || nrbitsp) {
                unsigned char   nrbits;
 
-               for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
+               for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
                        ;
-               bsize = 1 << nrbits;
+               bsize = 1UL << nrbits;
                if (nrbitsp)
                        *nrbitsp = nrbits;
        }