nfs: fix undefined behavior in nfs_block_bits()

commit 3c0a2e0b0a upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Sergey Shtylyov 2024-05-10 23:24:04 +03:00 committed by Greg Kroah-Hartman
parent 7c72af16ab
commit 2997e2fb1c

View file

@ -609,9 +609,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;
}