btrfs: use unsigned types for constants defined as bit shifts
[ Upstream commit 05a6ec865d091fe8244657df8063f74e704d1711 ] The unsigned type is a recommended practice (CWE-190, CWE-194) for bit shifts to avoid problems with potential unwanted sign extensions. Although there are no such cases in btrfs codebase, follow the recommendation. Reviewed-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com> Stable-dep-of: 1f2889f5594a ("btrfs: fix qgroup reservation leak on failure to allocate ordered extent") Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1fe766ddb9
commit
4cce1b05eb
@@ -427,8 +427,8 @@ struct btrfs_backref_node *btrfs_backref_alloc_node(
|
||||
struct btrfs_backref_edge *btrfs_backref_alloc_edge(
|
||||
struct btrfs_backref_cache *cache);
|
||||
|
||||
#define LINK_LOWER (1 << 0)
|
||||
#define LINK_UPPER (1 << 1)
|
||||
#define LINK_LOWER (1U << 0)
|
||||
#define LINK_UPPER (1U << 1)
|
||||
|
||||
void btrfs_backref_link_edge(struct btrfs_backref_edge *edge,
|
||||
struct btrfs_backref_node *lower,
|
||||
|
||||
@@ -151,8 +151,8 @@ static struct extent_map *btrfs_create_dio_extent(struct btrfs_inode *inode,
|
||||
}
|
||||
|
||||
ordered = btrfs_alloc_ordered_extent(inode, start, file_extent,
|
||||
(1 << type) |
|
||||
(1 << BTRFS_ORDERED_DIRECT));
|
||||
(1U << type) |
|
||||
(1U << BTRFS_ORDERED_DIRECT));
|
||||
if (IS_ERR(ordered)) {
|
||||
if (em) {
|
||||
free_extent_map(em);
|
||||
|
||||
@@ -79,7 +79,7 @@ enum {
|
||||
* single word in a bitmap may straddle two pages in the extent buffer.
|
||||
*/
|
||||
#define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE)
|
||||
#define BYTE_MASK ((1 << BITS_PER_BYTE) - 1)
|
||||
#define BYTE_MASK ((1U << BITS_PER_BYTE) - 1)
|
||||
#define BITMAP_FIRST_BYTE_MASK(start) \
|
||||
((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK)
|
||||
#define BITMAP_LAST_BYTE_MASK(nbits) \
|
||||
|
||||
@@ -1249,7 +1249,7 @@ static void submit_one_async_extent(struct async_chunk *async_chunk,
|
||||
free_extent_map(em);
|
||||
|
||||
ordered = btrfs_alloc_ordered_extent(inode, start, &file_extent,
|
||||
1 << BTRFS_ORDERED_COMPRESSED);
|
||||
1U << BTRFS_ORDERED_COMPRESSED);
|
||||
if (IS_ERR(ordered)) {
|
||||
btrfs_drop_extent_map_range(inode, start, end, false);
|
||||
ret = PTR_ERR(ordered);
|
||||
@@ -1484,7 +1484,7 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
|
||||
free_extent_map(em);
|
||||
|
||||
ordered = btrfs_alloc_ordered_extent(inode, start, &file_extent,
|
||||
1 << BTRFS_ORDERED_REGULAR);
|
||||
1U << BTRFS_ORDERED_REGULAR);
|
||||
if (IS_ERR(ordered)) {
|
||||
unlock_extent(&inode->io_tree, start,
|
||||
start + ram_size - 1, &cached);
|
||||
@@ -2081,8 +2081,8 @@ static int nocow_one_range(struct btrfs_inode *inode, struct folio *locked_folio
|
||||
|
||||
ordered = btrfs_alloc_ordered_extent(inode, file_pos, &nocow_args->file_extent,
|
||||
is_prealloc
|
||||
? (1 << BTRFS_ORDERED_PREALLOC)
|
||||
: (1 << BTRFS_ORDERED_NOCOW));
|
||||
? (1U << BTRFS_ORDERED_PREALLOC)
|
||||
: (1U << BTRFS_ORDERED_NOCOW));
|
||||
if (IS_ERR(ordered)) {
|
||||
if (is_prealloc)
|
||||
btrfs_drop_extent_map_range(inode, file_pos, end, false);
|
||||
@@ -9683,8 +9683,8 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
|
||||
free_extent_map(em);
|
||||
|
||||
ordered = btrfs_alloc_ordered_extent(inode, start, &file_extent,
|
||||
(1 << BTRFS_ORDERED_ENCODED) |
|
||||
(1 << BTRFS_ORDERED_COMPRESSED));
|
||||
(1U << BTRFS_ORDERED_ENCODED) |
|
||||
(1U << BTRFS_ORDERED_COMPRESSED));
|
||||
if (IS_ERR(ordered)) {
|
||||
btrfs_drop_extent_map_range(inode, start, end, false);
|
||||
ret = PTR_ERR(ordered);
|
||||
|
||||
@@ -155,7 +155,7 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
|
||||
u64 qgroup_rsv = 0;
|
||||
|
||||
if (flags &
|
||||
((1 << BTRFS_ORDERED_NOCOW) | (1 << BTRFS_ORDERED_PREALLOC))) {
|
||||
((1U << BTRFS_ORDERED_NOCOW) | (1U << BTRFS_ORDERED_PREALLOC))) {
|
||||
/* For nocow write, we can release the qgroup rsv right now */
|
||||
ret = btrfs_qgroup_free_data(inode, NULL, file_offset, num_bytes, &qgroup_rsv);
|
||||
if (ret < 0)
|
||||
@@ -253,7 +253,7 @@ static void insert_ordered_extent(struct btrfs_ordered_extent *entry)
|
||||
* @disk_bytenr: Offset of extent on disk.
|
||||
* @disk_num_bytes: Size of extent on disk.
|
||||
* @offset: Offset into unencoded data where file data starts.
|
||||
* @flags: Flags specifying type of extent (1 << BTRFS_ORDERED_*).
|
||||
* @flags: Flags specifying type of extent (1U << BTRFS_ORDERED_*).
|
||||
* @compress_type: Compression algorithm used for data.
|
||||
*
|
||||
* Most of these parameters correspond to &struct btrfs_file_extent_item. The
|
||||
|
||||
@@ -200,8 +200,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
|
||||
struct btrfs_stripe_hash_table *x;
|
||||
struct btrfs_stripe_hash *cur;
|
||||
struct btrfs_stripe_hash *h;
|
||||
int num_entries = 1 << BTRFS_STRIPE_HASH_TABLE_BITS;
|
||||
int i;
|
||||
unsigned int num_entries = 1U << BTRFS_STRIPE_HASH_TABLE_BITS;
|
||||
|
||||
if (info->stripe_hash_table)
|
||||
return 0;
|
||||
@@ -222,7 +221,7 @@ int btrfs_alloc_stripe_hash_table(struct btrfs_fs_info *info)
|
||||
|
||||
h = table->table;
|
||||
|
||||
for (i = 0; i < num_entries; i++) {
|
||||
for (unsigned int i = 0; i < num_entries; i++) {
|
||||
cur = h + i;
|
||||
INIT_LIST_HEAD(&cur->hash_list);
|
||||
spin_lock_init(&cur->lock);
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "../disk-io.h"
|
||||
#include "../btrfs_inode.h"
|
||||
|
||||
#define PROCESS_UNLOCK (1 << 0)
|
||||
#define PROCESS_RELEASE (1 << 1)
|
||||
#define PROCESS_TEST_LOCKED (1 << 2)
|
||||
#define PROCESS_UNLOCK (1U << 0)
|
||||
#define PROCESS_RELEASE (1U << 1)
|
||||
#define PROCESS_TEST_LOCKED (1U << 2)
|
||||
|
||||
static noinline int process_page_range(struct inode *inode, u64 start, u64 end,
|
||||
unsigned long flags)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "super.h"
|
||||
|
||||
#define ZSTD_BTRFS_MAX_WINDOWLOG 17
|
||||
#define ZSTD_BTRFS_MAX_INPUT (1 << ZSTD_BTRFS_MAX_WINDOWLOG)
|
||||
#define ZSTD_BTRFS_MAX_INPUT (1U << ZSTD_BTRFS_MAX_WINDOWLOG)
|
||||
#define ZSTD_BTRFS_DEFAULT_LEVEL 3
|
||||
#define ZSTD_BTRFS_MAX_LEVEL 15
|
||||
/* 307s to avoid pathologically clashing with transaction commit */
|
||||
|
||||
Reference in New Issue
Block a user