Skip to contentSkip to conversation

btrfs: ctree: Add do {} while (0) in btrfs_{set|clear}_and_info

PATCH In review Marcos Paulo de Souza 4 participants 5 messages Jul 6, 2020 – Jul 7, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: ctree: Add do {} while (0) in btrfs_{set|clear}_and_info

From: Marcos Paulo de Souza <[email protected]>

Without this change it's not possible to use these macros and having an if-else construction without using braces.

---
 fs/btrfs/ctree.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +4 -4
index a256961c0dbe..cef0489a1523 100644
@@ -1278,18 +1278,18 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 					 BTRFS_MOUNT_##opt)
 
 #define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
-{									\
+do {									\
 	if (!btrfs_test_opt(fs_info, opt))				\
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_set_opt(fs_info->mount_opt, opt);				\
-}
+} while (0)
 
 #define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
-{									\
+do {									\
 	if (btrfs_test_opt(fs_info, opt))				\
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_clear_opt(fs_info->mount_opt, opt);			\
-}
+} while (0)
 
 /*
  * Requests for changes that need to be done during transaction commit.
Signature · 1 line
2.26.2
#1 lore raw
Quoted 6 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Without this change it's not possible to use these macros and having an if-else construction without using braces.

This change would have been better accompanied with another one showing intended usage. If it's part of a bigger rework then postpone it and send everything altogether.

Quoted 32 lines
---
 fs/btrfs/ctree.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +4 -4
index a256961c0dbe..cef0489a1523 100644
@@ -1278,18 +1278,18 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)
 					 BTRFS_MOUNT_##opt)
 
 #define btrfs_set_and_info(fs_info, opt, fmt, args...)			\
-{									\
+do {									\
 	if (!btrfs_test_opt(fs_info, opt))				\
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_set_opt(fs_info->mount_opt, opt);				\
-}
+} while (0)
 
 #define btrfs_clear_and_info(fs_info, opt, fmt, args...)		\
-{									\
+do {									\
 	if (btrfs_test_opt(fs_info, opt))				\
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_clear_opt(fs_info->mount_opt, opt);			\
-}
+} while (0)
 
 /*
  * Requests for changes that need to be done during transaction commit.
#2 lore raw
Quoted 6 lines · Nikolay Borisov
Quoted 3 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Without this change it's not possible to use these macros and

having an

Quoted 8 lines
Quoted 3 lines

if-else construction without using braces.

This change would have been better accompanied with another one showing
intended usage. If it's part of a bigger rework then postpone it and send everything altogether.

Yes, this is part of my fscontext btrfs port. Ok, I'll send this again again along with all the port patches.

Thanks,
Marcos

Quoted 43 lines

fs/btrfs/ctree.h static inline u32

Quoted 10 lines
---
 fs/btrfs/ctree.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/ctree.h +0 -0
index a256961c0dbe..cef0489a1523 100644
@@ -1278,18 +1278,18 @@ static inline u32

BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)

fs/btrfs/ctree.h static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)

Quoted 3 lines
fs/btrfs/ctree.h +0 -0
 					 BTRFS_MOUNT_##opt)
 
 #define btrfs_set_and_info(fs_info, opt, fmt, args...)		
	\

fs/btrfs/ctree.h static inline u32 · line 1281

Quoted 1 line
fs/btrfs/ctree.h +0 -1
-{									

\

fs/btrfs/ctree.h static inline u32 · line 1281

Quoted 1 line
fs/btrfs/ctree.h +1 -0
+do {								
	\

fs/btrfs/ctree.h static inline u32 · line 1282

Quoted 1 line
fs/btrfs/ctree.h +0 -0
 	if (!btrfs_test_opt(fs_info, opt))				

\

fs/btrfs/ctree.h static inline u32 · line 1284

Quoted 2 lines
fs/btrfs/ctree.h +0 -0
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_set_opt(fs_info->mount_opt, opt);				

\

fs/btrfs/ctree.h static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)

Quoted 4 lines
fs/btrfs/ctree.h +1 -1
-}
+} while (0)
 
 #define btrfs_clear_and_info(fs_info, opt, fmt, args...)		

\

fs/btrfs/ctree.h static inline u32 · line 1288

Quoted 1 line
fs/btrfs/ctree.h +0 -1
-{									

\

fs/btrfs/ctree.h static inline u32 · line 1288

Quoted 1 line
fs/btrfs/ctree.h +1 -0
+do {								
	\

fs/btrfs/ctree.h static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info)

Quoted 8 lines
fs/btrfs/ctree.h +1 -1
 	if (btrfs_test_opt(fs_info, opt))				\
 		btrfs_info(fs_info, fmt, ##args);			\
 	btrfs_clear_opt(fs_info->mount_opt, opt);			\
-}
+} while (0)
 
 /*
  * Requests for changes that need to be done during transaction

commit.

Quoted 1 line
#3 lore raw
In reply to Nikolay Borisov
Quoted 5 lines · Nikolay Borisov
Quoted 2 lines · Marcos Paulo de Souza

From: Marcos Paulo de Souza <[email protected]>

Quoted 8 lines
Quoted 4 lines

Without this change it's not possible to use these macros and having an if-else construction without using braces.

This change would have been better accompanied with another one showing intended usage. If it's part of a bigger rework then postpone it and send everything altogether.

I think the change is good as is, multi-statement macros should always be enclosed in do {} while(0);