btrfs: relocation: fix unused variable
PATCH 1/1 btrfs: relocation: fix unused variable
When CONFIG_BRTFS_ASSERT isn't enabled, variable root_objectid isn't used.
fs/btrfs/relocation.c: In function ‘insert_dirty_subv’:fs/btrfs/relocation.c:2138:6: warning: unused variable ‘root_objectid’ [-Wunused-variable]
u64 root_objectid = root->root_key.objectid;
^~~~~~~~~~~~~Reworked by adding a runtime check in the assfail function instead of the '#ifdef CONFIG_BTRFS_ASSERT #else ...", so the compiler sees the condition being passed into an inline function after preprocessing.
--- fs/btrfs/ctree.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/btrfs/ctree.h +5 -8
@@ -3521,21 +3521,18 @@ do { \rcu_read_unlock (); \ }while (0 ) -#ifdef CONFIG_BTRFS_ASSERT -__cold static inline void assfail(const char *expr, const char *file, int line) { -pr_err ("assertion failed: %s, file: %s, line: %d\n" , - expr, file, line); -BUG (); +if (IS_ENABLED (CONFIG_BTRFS_ASSERT )) { +pr_err ("assertion failed: %s, file: %s, line: %d\n" , + expr, file, line); +BUG (); + } }#define ASSERT (expr) \ (likely(expr) ? (void)0 : assfail(#expr, __FILE__, __LINE__)) -#else -#define ASSERT (expr) ((void)0) -#endif /* * Use that for functions that are conditionally exported for sanity tests but
Signature · 1 line
2.19.2
Quoted 10 lines · Anders Roxell
When
CONFIG_BRTFS_ASSERTisn't enabled, variableroot_objectidisn't used.
fs/btrfs/relocation.c: In function ‘insert_dirty_subv’:fs/btrfs/relocation.c:2138:6: warning: unused variable ‘root_objectid’ [-Wunused-variable]u64 root_objectid = root->root_key.objectid; ^~~~~~~~~~~~~Reworked by adding a runtime check in the assfail function instead of the '#ifdef
CONFIG_BTRFS_ASSERT#else ...", so the compiler sees the condition being passed into an inline function after preprocessing.
I've fixed the warning by avoiding the local variable but I like your fix in general, thanks.
Quoted 8 lines · David Sterba
Quoted 7 lines · Anders Roxell
When
CONFIG_BRTFS_ASSERTisn't enabled, variableroot_objectidisn't used.
fs/btrfs/relocation.c: In function ‘insert_dirty_subv’:fs/btrfs/relocation.c:2138:6: warning: unused variable ‘root_objectid’ [-Wunused-variable]u64 root_objectid = root->root_key.objectid; ^~~~~~~~~~~~~
Quoted 6 lines
Quoted 3 lines
Reworked by adding a runtime check in the assfail function instead of the '#ifdef
CONFIG_BTRFS_ASSERT#else ...", so the compiler sees the condition being passed into an inline function after preprocessing.I've fixed the warning by avoiding the local variable but I like your fix in general, thanks.
Committed with this changelog:
"btrfs: let the assertion expression compile in all configs
A compiler warning (in a patch in development) pointed to a variable that was used only inside and ASSERT:
u64 root_objectid = root->root_key.objectid; ASSERT(root_objectid == ...);
fs/btrfs/relocation.c: In function ‘insert_dirty_subv’:
fs/btrfs/relocation.c:2138:6: warning: unused variable ‘root_objectid’ [-Wunused-variable]
u64 root_objectid = root->root_key.objectid; ^~~~~~~~~~~~~
When CONFIG_BRTFS_ASSERT isn't enabled, variable root_objectid isn't used.
Rework the assertion helper by adding a runtime check instead of the '#ifdef CONFIG_BTRFS_ASSERT #else ...", so the compiler sees the condition being passed into an inline function after preprocessing."