Linux-BTRFS Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] btrfs: relocation: fix unused variable
@ 2019-01-29 13:01 Anders Roxell
  2019-01-29 15:21 ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: Anders Roxell @ 2019-01-29 13:01 UTC (permalink / raw)
  To: clm, josef, dsterba; +Cc: linux-btrfs, linux-kernel, Anders Roxell

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.

Fixes: 7b837199c581 ("btrfs: relocation: Delay reloc tree deletion after merge_reloc_roots()")
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 fs/btrfs/ctree.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index de23a7ea396d..ad7d079f2cae 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -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
-- 
2.19.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: relocation: fix unused variable
  2019-01-29 13:01 [PATCH] btrfs: relocation: fix unused variable Anders Roxell
@ 2019-01-29 15:21 ` David Sterba
  2019-01-29 15:42   ` David Sterba
  0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2019-01-29 15:21 UTC (permalink / raw)
  To: Anders Roxell; +Cc: clm, josef, dsterba, linux-btrfs, linux-kernel

On Tue, Jan 29, 2019 at 02:01:46PM +0100, Anders Roxell wrote:
> 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.

I've fixed the warning by avoiding the local variable but I like your
fix in general, thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] btrfs: relocation: fix unused variable
  2019-01-29 15:21 ` David Sterba
@ 2019-01-29 15:42   ` David Sterba
  0 siblings, 0 replies; 3+ messages in thread
From: David Sterba @ 2019-01-29 15:42 UTC (permalink / raw)
  To: dsterba, Anders Roxell, clm, josef, dsterba, linux-btrfs, linux-kernel

On Tue, Jan 29, 2019 at 04:21:27PM +0100, David Sterba wrote:
> On Tue, Jan 29, 2019 at 02:01:46PM +0100, Anders Roxell wrote:
> > 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.
> 
> 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."

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-29 13:01 [PATCH] btrfs: relocation: fix unused variable Anders Roxell
2019-01-29 15:21 ` David Sterba
2019-01-29 15:42   ` David Sterba

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org linux-btrfs@archiver.kernel.org
	public-inbox-index linux-btrfs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox