From a0ff3f19af0f709135da2e728002593d1ab626ef Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 12 Mar 2024 22:03:36 +0100 Subject: [PATCH] libbtrfs: use unsigned types for bit shifts Bit shifts should be done on unsigned type as a matter of good practice to avoid any problems with bit overflowing to the sign bit. Signed-off-by: David Sterba --- libbtrfs/crc32c.c | 2 +- libbtrfs/ctree.h | 24 ++++++++++++------------ libbtrfs/kerncompat.h | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libbtrfs/crc32c.c b/libbtrfs/crc32c.c index 963d427c..4391e46f 100644 --- a/libbtrfs/crc32c.c +++ b/libbtrfs/crc32c.c @@ -102,7 +102,7 @@ static void crc32c_intel_probe(void) eax = 1; do_cpuid(&eax, &ebx, &ecx, &edx); - crc32c_intel_available = (ecx & (1 << 20)) != 0; + crc32c_intel_available = (ecx & (1U << 20)) != 0; crc32c_probed = 1; } } diff --git a/libbtrfs/ctree.h b/libbtrfs/ctree.h index ea2a680e..0e9c5bcd 100644 --- a/libbtrfs/ctree.h +++ b/libbtrfs/ctree.h @@ -1581,18 +1581,18 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) /* * Inode flags */ -#define BTRFS_INODE_NODATASUM (1 << 0) -#define BTRFS_INODE_NODATACOW (1 << 1) -#define BTRFS_INODE_READONLY (1 << 2) -#define BTRFS_INODE_NOCOMPRESS (1 << 3) -#define BTRFS_INODE_PREALLOC (1 << 4) -#define BTRFS_INODE_SYNC (1 << 5) -#define BTRFS_INODE_IMMUTABLE (1 << 6) -#define BTRFS_INODE_APPEND (1 << 7) -#define BTRFS_INODE_NODUMP (1 << 8) -#define BTRFS_INODE_NOATIME (1 << 9) -#define BTRFS_INODE_DIRSYNC (1 << 10) -#define BTRFS_INODE_COMPRESS (1 << 11) +#define BTRFS_INODE_NODATASUM (1U << 0) +#define BTRFS_INODE_NODATACOW (1U << 1) +#define BTRFS_INODE_READONLY (1U << 2) +#define BTRFS_INODE_NOCOMPRESS (1U << 3) +#define BTRFS_INODE_PREALLOC (1U << 4) +#define BTRFS_INODE_SYNC (1U << 5) +#define BTRFS_INODE_IMMUTABLE (1U << 6) +#define BTRFS_INODE_APPEND (1U << 7) +#define BTRFS_INODE_NODUMP (1U << 8) +#define BTRFS_INODE_NOATIME (1U << 9) +#define BTRFS_INODE_DIRSYNC (1U << 10) +#define BTRFS_INODE_COMPRESS (1U << 11) void read_extent_buffer(const struct extent_buffer *eb, void *dst, unsigned long start, unsigned long len); diff --git a/libbtrfs/kerncompat.h b/libbtrfs/kerncompat.h index a8ba07f0..3f384d8a 100644 --- a/libbtrfs/kerncompat.h +++ b/libbtrfs/kerncompat.h @@ -72,7 +72,7 @@ #define BITS_PER_BYTE 8 #define BITS_PER_LONG (__SIZEOF_LONG__ * BITS_PER_BYTE) #define __GFP_BITS_SHIFT 20 -#define __GFP_BITS_MASK ((int)((1 << __GFP_BITS_SHIFT) - 1)) +#define __GFP_BITS_MASK ((int)((1U << __GFP_BITS_SHIFT) - 1)) #define GFP_KERNEL 0 #define GFP_NOFS 0 #define __read_mostly