Skip to contentSkip to conversation

staging: lustre: shut up clang warnings on CLASSERT()

PATCH In review Arnd Bergmann 3 participants 6 messages Feb 1, 2017 – Feb 2, 2017 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: lustre: shut up clang warnings on CLASSERT()

lustre uses a fake switch() statement as a compile-time assert, but unfortunately each use of that causes a warning when building with clang:

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c:2907:2: warning: no case matching constant switch condition '42' drivers/staging/lustre/lnet/klnds/socklnd/../../../include/linux/libcfs/libcfs_private.h:294:36: note: expanded from macro 'CLASSERT'
#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)

Adding a 'default:' label in there shuts up the warning.

---
 drivers/staging/lustre/include/linux/libcfs/libcfs_private.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
index aab15d8112a4..2d5435029185 100644
@@ -291,7 +291,7 @@ do {							    \
  *       value  after  conversion...
  *
  */
-#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
+#define CLASSERT(cond) do {switch (42) {case (cond): case 0: default: break; } } while (0)
 
 /* max value for numeric network address */
 #define MAX_NUMERIC_VALUE 0xffffffff
Signature · 1 line
2.9.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Arnd Bergmann

lustre uses a fake switch() statement as a compile-time assert, but unfortunately each use of that causes a warning when building with clang:

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c:2907:2: warning: no case matching constant switch condition '42' drivers/staging/lustre/lnet/klnds/socklnd/../../../include/linux/libcfs/libcfs_private.h:294:36: note: expanded from macro 'CLASSERT' #define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)

Adding a 'default:' label in there shuts up the warning.

Quoted 20 lines

---
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
index aab15d8112a4..2d5435029185 100644
@@ -291,7 +291,7 @@ do {							    \
 *       value  after  conversion...
 *
 */
-#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
+#define CLASSERT(cond) do {switch (42) {case (cond): case 0: default: break; } } while (0)
 
 /* max value for numeric network address */
 #define MAX_NUMERIC_VALUE 0xffffffff
Signature · 1 line
2.9.0

Cheers, Andreas
--
Andreas Dilger
Lustre Principal Architect
Intel Corporation

#2 lore raw
Quoted 19 lines · Andreas
Quoted 11 lines · Arnd Bergmann

lustre uses a fake switch() statement as a compile-time assert, but unfortunately each use of that causes a warning when building with clang:

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c:2907:2: warning: no case matching constant switch condition '42' drivers/staging/lustre/lnet/klnds/socklnd/../../../include/linux/libcfs/libcfs_private.h:294:36: note: expanded from macro 'CLASSERT' #define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)

Adding a 'default:' label in there shuts up the warning.

Quoted 4 lines

---
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h do { \ · line 294

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
index aab15d8112a4..2d5435029185 100644
@@ -291,7 +291,7 @@ do {							    \
 *       value  after  conversion...
 *
 */
-#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
+#define CLASSERT(cond) do {switch (42) {case (cond): case 0: default: break; } } while (0)

Ugh, why not just use the in-kernel ASSERT macro instead?

thanks,

greg k-h

#3 lore raw

On Thu, Feb 2, 2017 at 10:54 AM, Greg Kroah-Hartman <[email protected]> wrote:
b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h

Quoted 11 lines
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h do { \ · line 294

Quoted 9 lines

index aab15d8112a4..2d5435029185 100644

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
@@ -291,7 +291,7 @@ do {                                                        \
 *       value  after  conversion...
 *
 */
-#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
+#define CLASSERT(cond) do {switch (42) {case (cond): case 0: default: break; } } while (0)

Ugh, why not just use the in-kernel ASSERT macro instead?

We don't have one ;-)

I've done a semi-automated patch to replace CLASSERT() with the respective BUILD_BUG_ON() now, but that patch is quite large.

Arnd

#4 lore raw
Quoted 15 lines · Arnd Bergmann

On Thu, Feb 2, 2017 at 10:54 AM, Greg Kroah-Hartman <[email protected]> wrote:
b/drivers/staging/lustre/include/linux/libcfs/libcfs_private.h

Quoted 11 lines
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h do { \ · line 294

Quoted 9 lines

index aab15d8112a4..2d5435029185 100644

drivers/staging/lustre/include/linux/libcfs/libcfs_private.h +1 -1
@@ -291,7 +291,7 @@ do {                                                        \
 *       value  after  conversion...
 *
 */
-#define CLASSERT(cond) do {switch (42) {case (cond): case 0: break; } } while (0)
+#define CLASSERT(cond) do {switch (42) {case (cond): case 0: default: break; } } while (0)

Ugh, why not just use the in-kernel ASSERT macro instead?

Quoted 1 line

We don't have one ;-)

Oh nice!

Quoted 2 lines

I've done a semi-automated patch to replace CLASSERT() with the respective BUILD_BUG_ON() now, but that patch is quite large.

Should be easy to script, I missed that this was a build-time check. Heck, I'll take a script to do this, or I can just do it in my end.

thanks,

greg k-h

#5 lore raw
Quoted 6 lines · Greg Kroah-Hartman
Quoted 2 lines · Arnd Bergmann

I've done a semi-automated patch to replace CLASSERT() with the respective BUILD_BUG_ON() now, but that patch is quite large.

Should be easy to script, I missed that this was a build-time check. Heck, I'll take a script to do this, or I can just do it in my end

My patch has been through a couple of randconfig and allmodconfig builds now, should be good. If it's wrong, it will at least blow up at compile time.

Arnd