Skip to content

Commit 61e19fc

Browse files
foxidokunkdave
authored andcommitted
btrfs: don't generate any code from ASSERT() in release builds
The current definition of ASSERT(cond) as (void)(cond) is redundant, since these checks have no side effects and don't affect code logic. However, some checks contain READ_ONCE() or other compiler-unfriendly constructs. For example, ASSERT(list_empty) in btrfs_add_dealloc_inode() was compiled to a redundant mov instruction due to this issue. Define ASSERT as BUILD_BUG_ON_INVALID for !CONFIG_BTRFS_ASSERT builds which uses sizeof(cond) trick. Also mark full_page_sectors_uptodate() as __maybe_unused to suppress "unneeded declaration" warning (it's needed in compile time) Signed-off-by: Gladyshev Ilya <foxido@foxido.dev> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 191273d commit 61e19fc

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

fs/btrfs/messages.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ do { \
168168
#endif
169169

170170
#else
171-
#define ASSERT(cond, args...) (void)(cond)
171+
/* Compile check the @cond expression but don't generate any code. */
172+
#define ASSERT(cond, args...) BUILD_BUG_ON_INVALID(cond)
172173
#endif
173174

174175
#ifdef CONFIG_BTRFS_DEBUG

fs/btrfs/raid56.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ static int rbio_bucket(struct btrfs_raid_bio *rbio)
299299
return hash_64(num >> 16, BTRFS_STRIPE_HASH_TABLE_BITS);
300300
}
301301

302-
static bool full_page_sectors_uptodate(struct btrfs_raid_bio *rbio,
303-
unsigned int page_nr)
302+
static __maybe_unused bool full_page_sectors_uptodate(struct btrfs_raid_bio *rbio,
303+
unsigned int page_nr)
304304
{
305305
const u32 sectorsize = rbio->bioc->fs_info->sectorsize;
306306
const u32 sectors_per_page = PAGE_SIZE / sectorsize;

0 commit comments

Comments
 (0)