Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 3c0a2e0

Browse files
Sergey ShtylyovTrond Myklebust
authored andcommitted
nfs: fix undefined behavior in nfs_block_bits()
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>
1 parent a01b077 commit 3c0a2e0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

fs/nfs/internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,9 +717,9 @@ unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
717717
if ((bsize & (bsize - 1)) || nrbitsp) {
718718
unsigned char nrbits;
719719

720-
for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
720+
for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
721721
;
722-
bsize = 1 << nrbits;
722+
bsize = 1UL << nrbits;
723723
if (nrbitsp)
724724
*nrbitsp = nrbits;
725725
}

0 commit comments

Comments
 (0)