Skip to contentSkip to conversation

dm block manager: use do/while(0) for empty macros

PATCH In review Arnd Bergmann 2 participants 2 messages Oct 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm block manager: use do/while(0) for empty macros

make W=1 reports a new warning for the dm-block-manager:

drivers/md/persistent-data/dm-block-manager.c: In function ‘dm_bm_unlock’:
drivers/md/persistent-data/dm-block-manager.c:598:3: error: suggest braces around empty body in an ‘else’ statement [-Werror=empty-body]

This is completely harmless, but generally speaking it's a good idea to address this warning as it can often detect nasty bugs, and replacing empty macros with "do { } while (0)" is generally considered good style to make code more robust anyway.

Fixes f94bdb2e26b6 ("dm block manager: make block locking optional")
---
 drivers/md/persistent-data/dm-block-manager.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/persistent-data/dm-block-manager.c +4 -4
index b619c383d88d..a6dde7cab458 100644
@@ -306,13 +306,13 @@ static void report_recursive_bug(dm_block_t b, int r)
 
 #else  /* !CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING */
 
-#define bl_init(x)
+#define bl_init(x) do { } while (0)
 #define bl_down_read(x) 0
 #define bl_down_read_nonblock(x) 0
-#define bl_up_read(x)
+#define bl_up_read(x) do { } while (0)
 #define bl_down_write(x) 0
-#define bl_up_write(x)
-#define report_recursive_bug(x, y)
+#define bl_up_write(x) do { } while (0)
+#define report_recursive_bug(x, y) do { } while (0)
 
 #endif /* CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING */
 
Signature · 1 line
2.9.0
#1 lore raw
Quoted 5 lines · Arnd Bergmann

make W=1 reports a new warning for the dm-block-manager:

drivers/md/persistent-data/dm-block-manager.c: In function ‘dm_bm_unlock’:
drivers/md/persistent-data/dm-block-manager.c:598:3: error: suggest braces around empty body in an ‘else’ statement [-Werror=empty-body]

Quoted 7 lines

This is completely harmless, but generally speaking it's a good idea to address this warning as it can often detect nasty bugs, and replacing empty macros with "do { } while (0)" is generally considered good style to make code more robust anyway.

Fixes f94bdb2e26b6 ("dm block manager: make block locking optional")

Thanks Arnd, I'll fold this in. I suspected this was the right thing to do. Strange that my build didn't say anything through, I used:
make C=1 CF=-D__CHECK_ENDIAN__ M=drivers/md

I'll be sure to use make W=1 in the future.

Quoted 33 lines
---
 drivers/md/persistent-data/dm-block-manager.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/md/persistent-data/dm-block-manager.c +4 -4
index b619c383d88d..a6dde7cab458 100644
@@ -306,13 +306,13 @@ static void report_recursive_bug(dm_block_t b, int r)
 
 #else  /* !CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING */
 
-#define bl_init(x)
+#define bl_init(x) do { } while (0)
 #define bl_down_read(x) 0
 #define bl_down_read_nonblock(x) 0
-#define bl_up_read(x)
+#define bl_up_read(x) do { } while (0)
 #define bl_down_write(x) 0
-#define bl_up_write(x)
-#define report_recursive_bug(x, y)
+#define bl_up_write(x) do { } while (0)
+#define report_recursive_bug(x, y) do { } while (0)
 
 #endif /* CONFIG_DM_DEBUG_BLOCK_MANAGER_LOCKING */
 
Signature · 6 lines
2.9.0

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel