Skip to contentSkip to conversation

block: t10-pi: fix -Wswitch warning

PATCH In review Arnd Bergmann 4 participants 4 messages Sep 19, 2019 – Sep 21, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: t10-pi: fix -Wswitch warning

Changing the switch() statement to symbolic constants made the compiler (at least clang-9, did not check gcc) notice that there is one enum value that is not handled here:

block/t10-pi.c:62:11: error: enumeration value 'T10_PI_TYPE0_PROTECTION' not handled in switch [-Werror,-Wswitch]

Add another case for the missing value and do nothing there based on the assumption that the code was working correctly already.

Fixes 9b2061b1a262 ("block: use symbolic constants for t10_pi type")
---
 block/t10-pi.c | 2 ++
 1 file changed, 2 insertions(+)
block/t10-pi.c +2 -0
index 0c0120a672f9..055fac923946 100644
@@ -60,6 +60,8 @@ static blk_status_t t10_pi_verify(struct blk_integrity_iter *iter,
 		__be16 csum;
 
 		switch (type) {
+		case T10_PI_TYPE0_PROTECTION:
+			break;
 		case T10_PI_TYPE1_PROTECTION:
 		case T10_PI_TYPE2_PROTECTION:
 			if (pi->app_tag == T10_PI_APP_ESCAPE)
Signature · 1 line
2.20.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Arnd Bergmann

Changing the switch() statement to symbolic constants made the compiler (at least clang-9, did not check gcc) notice that there is one enum value that is not handled here:

Quoted 8 lines

block/t10-pi.c:62:11: error: enumeration value 'T10_PI_TYPE0_PROTECTION' not handled in switch [-Werror,-Wswitch]

Add another case for the missing value and do nothing there based on the assumption that the code was working correctly already.

Fixes 9b2061b1a262 ("block: use symbolic constants for t10_pi type")

https://groups.google.com/forum/#!topic/clang-built-linux/awgY7hmSCCM
Hard to say what's the right thing to do here, there's not a lot of other switches on this variable. That enum value barely even shows up in the kernel. Since this is no functional change:

Thanks for sending the patch.

Quoted 18 lines
---
 block/t10-pi.c | 2 ++
 1 file changed, 2 insertions(+)
block/t10-pi.c +2 -1
index 0c0120a672f9..055fac923946 100644
@@ -60,6 +60,8 @@ static blk_status_t t10_pi_verify(struct blk_integrity_iter *iter,
                __be16 csum;
 
                switch (type) {
+               case T10_PI_TYPE0_PROTECTION:
+                       break;
                case T10_PI_TYPE1_PROTECTION:
                case T10_PI_TYPE2_PROTECTION:
                        if (pi->app_tag == T10_PI_APP_ESCAPE)
--
Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by on v1 1/1
#2 lore raw
In reply to Arnd Bergmann
Quoted 31 lines · Arnd Bergmann

Changing the switch() statement to symbolic constants made the compiler (at least clang-9, did not check gcc) notice that there is one enum value that is not handled here:

block/t10-pi.c:62:11: error: enumeration value 'T10_PI_TYPE0_PROTECTION' not handled in switch [-Werror,-Wswitch]

Add another case for the missing value and do nothing there based on the assumption that the code was working correctly already.

Fixes 9b2061b1a262 ("block: use symbolic constants for t10_pi type")
---
 block/t10-pi.c | 2 ++
 1 file changed, 2 insertions(+)
block/t10-pi.c +2 -0
index 0c0120a672f9..055fac923946 100644
@@ -60,6 +60,8 @@ static blk_status_t t10_pi_verify(struct blk_integrity_iter *iter,
 		__be16 csum;
 
 		switch (type) {
+		case T10_PI_TYPE0_PROTECTION:
+			break;
 		case T10_PI_TYPE1_PROTECTION:
 		case T10_PI_TYPE2_PROTECTION:
 			if (pi->app_tag == T10_PI_APP_ESCAPE)
Signature · 1 line
2.20.0

I didn't have the break in my local patch but I think this is more correct based on the description of the enums. Like Nick pointed out, there is no functional change because this value is not used in this file.

#3 lore raw
Quoted 37 lines · Nathan Chancellor
Quoted 31 lines · Arnd Bergmann

Changing the switch() statement to symbolic constants made the compiler (at least clang-9, did not check gcc) notice that there is one enum value that is not handled here:

block/t10-pi.c:62:11: error: enumeration value 'T10_PI_TYPE0_PROTECTION' not handled in switch [-Werror,-Wswitch]

Add another case for the missing value and do nothing there based on the assumption that the code was working correctly already.

Fixes 9b2061b1a262 ("block: use symbolic constants for t10_pi type")
---
  block/t10-pi.c | 2 ++
  1 file changed, 2 insertions(+)
block/t10-pi.c +2 -0
index 0c0120a672f9..055fac923946 100644
@@ -60,6 +60,8 @@ static blk_status_t t10_pi_verify(struct blk_integrity_iter *iter,
  		__be16 csum;
 
  		switch (type) {
+		case T10_PI_TYPE0_PROTECTION:
+			break;
  		case T10_PI_TYPE1_PROTECTION:
  		case T10_PI_TYPE2_PROTECTION:
  			if (pi->app_tag == T10_PI_APP_ESCAPE)
Signature · 1 line
2.20.0

I didn't have the break in my local patch but I think this is more correct based on the description of the enums. Like Nick pointed out, there is no functional change because this value is not used in this file.

Quoted 1 line

Hi,

we had a thread with Martin regarding this issue and we decided to set a default clause and add a BUG() in case we get there.

I've sent a patch with this fix.

-Max.