Skip to contentSkip to conversation

ibmvnic: remove default label from to_string switch

PATCH Superseded Michal Suchanek 3 participants 6 messages May 3, 2021 – May 4, 2021

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibmvnic: remove default label from to_string switch

This way the compiler warns when a new value is added to the enum but not the string transation like:

drivers/net/ethernet/ibm/ibmvnic.c: In function 'adapter_state_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:832:2: warning: enumeration value 'VNIC_FOOBAR' not handled in switch [-Wswitch]
switch (state) {
^~~~~~
drivers/net/ethernet/ibm/ibmvnic.c: In function 'reset_reason_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:1935:2: warning: enumeration value 'VNIC_RESET_FOOBAR' not handled in switch [-Wswitch]
switch (reason) {
^~~~~~

---
 drivers/net/ethernet/ibm/ibmvnic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +2 -4
index 5788bb956d73..4d439413f6d9 100644
@@ -846,9 +846,8 @@ static const char *adapter_state_to_string(enum vnic_state state)
 		return "REMOVING";
 	case VNIC_REMOVED:
 		return "REMOVED";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 static int ibmvnic_login(struct net_device *netdev)
@@ -1946,9 +1945,8 @@ static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason)
 		return "TIMEOUT";
 	case VNIC_RESET_CHANGE_PARAM:
 		return "CHANGE_PARAM";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 /*
Signature · 1 line
2.26.2
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Michal Suchanek

This way the compiler warns when a new value is added to the enum but not the string transation like:

s/transation/translation/

This trick works.
Since the original code does not generate gcc warnings/errors, should this patch be sent to net-next as an improvement?

Quoted 10 lines

drivers/net/ethernet/ibm/ibmvnic.c: In function 'adapter_state_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:832:2: warning: enumeration value 'VNIC_FOOBAR' not handled in switch [-Wswitch]
switch (state) {
^~~~~~
drivers/net/ethernet/ibm/ibmvnic.c: In function 'reset_reason_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:1935:2: warning: enumeration value 'VNIC_RESET_FOOBAR' not handled in switch [-Wswitch]
switch (reason) {
^~~~~~

Quoted 2 lines

---

Quoted 32 lines
 drivers/net/ethernet/ibm/ibmvnic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +2 -5
index 5788bb956d73..4d439413f6d9 100644
@@ -846,9 +846,8 @@ static const char *adapter_state_to_string(enum vnic_state state)
                return "REMOVING";
        case VNIC_REMOVED:
                return "REMOVED";
-       default:
-               return "UNKNOWN";
        }
+       return "UNKNOWN";
 }
 
 static int ibmvnic_login(struct net_device *netdev)
@@ -1946,9 +1945,8 @@ static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason)
                return "TIMEOUT";
        case VNIC_RESET_CHANGE_PARAM:
                return "CHANGE_PARAM";
-       default:
-               return "UNKNOWN";
        }
+       return "UNKNOWN";
 }
 
 /*
--

2.26.2

maintainer
#2 lore raw

From: Lijun Pan <[email protected]>
Date: Mon, 3 May 2021 13:21:00 -0500

Quoted 10 lines · Michal Suchanek
Quoted 3 lines

This way the compiler warns when a new value is added to the enum but not the string transation like:

s/transation/translation/

This trick works.
Since the original code does not generate gcc warnings/errors, should this patch be sent to net-next as an improvement?

Yes.

#3 lore raw

PATCH v2 1/1 ibmvnic: remove default label from to_string switch

This way the compiler warns when a new value is added to the enum but not to the string translation like:

drivers/net/ethernet/ibm/ibmvnic.c: In function 'adapter_state_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:832:2: warning: enumeration value 'VNIC_FOOBAR' not handled in switch [-Wswitch]
switch (state) {
^~~~~~
drivers/net/ethernet/ibm/ibmvnic.c: In function 'reset_reason_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:1935:2: warning: enumeration value 'VNIC_RESET_FOOBAR' not handled in switch [-Wswitch]
switch (reason) {
^~~~~~

---
v2: Fix typo in commit message

---
 drivers/net/ethernet/ibm/ibmvnic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +2 -4
index 5788bb956d73..4d439413f6d9 100644
@@ -846,9 +846,8 @@ static const char *adapter_state_to_string(enum vnic_state state)
 		return "REMOVING";
 	case VNIC_REMOVED:
 		return "REMOVED";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 static int ibmvnic_login(struct net_device *netdev)
@@ -1946,9 +1945,8 @@ static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason)
 		return "TIMEOUT";
 	case VNIC_RESET_CHANGE_PARAM:
 		return "CHANGE_PARAM";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 /*
Signature · 1 line
2.26.2
#4 lore raw

PATCH RESEND v2 1/1 ibmvnic: remove default label from to_string switch

In reply to David Miller

This way the compiler warns when a new value is added to the enum but not to the string translation like:

drivers/net/ethernet/ibm/ibmvnic.c: In function 'adapter_state_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:832:2: warning: enumeration value 'VNIC_FOOBAR' not handled in switch [-Wswitch]
switch (state) {
^~~~~~
drivers/net/ethernet/ibm/ibmvnic.c: In function 'reset_reason_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:1935:2: warning: enumeration value 'VNIC_RESET_FOOBAR' not handled in switch [-Wswitch]
switch (reason) {
^~~~~~

---
v2: Fix typo in commit message

---
 drivers/net/ethernet/ibm/ibmvnic.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/ibm/ibmvnic.c +2 -4
index 5788bb956d73..4d439413f6d9 100644
@@ -846,9 +846,8 @@ static const char *adapter_state_to_string(enum vnic_state state)
 		return "REMOVING";
 	case VNIC_REMOVED:
 		return "REMOVED";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 static int ibmvnic_login(struct net_device *netdev)
@@ -1946,9 +1945,8 @@ static const char *reset_reason_to_string(enum ibmvnic_reset_reason reason)
 		return "TIMEOUT";
 	case VNIC_RESET_CHANGE_PARAM:
 		return "CHANGE_PARAM";
-	default:
-		return "UNKNOWN";
 	}
+	return "UNKNOWN";
 }
 
 /*
Signature · 1 line
2.26.2
#5 lore raw
Quoted 13 lines · Michal Suchanek

This way the compiler warns when a new value is added to the enum but not to the string translation like:

drivers/net/ethernet/ibm/ibmvnic.c: In function 'adapter_state_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:832:2: warning: enumeration value 'VNIC_FOOBAR' not handled in switch [-Wswitch]
switch (state) {
^~~~~~
drivers/net/ethernet/ibm/ibmvnic.c: In function 'reset_reason_to_string':
drivers/net/ethernet/ibm/ibmvnic.c:1935:2: warning: enumeration value 'VNIC_RESET_FOOBAR' not handled in switch [-Wswitch]
switch (reason) {
^~~~~~

Quoted 5 lines

---
v2: Fix typo in commit message
---

Hi Michal,

Thank you for reposting the patch and including the Ack-by tag. I think you need to wait till next Tuesday or so when net-next reopens, then you can repost the patch.
http://vger.kernel.org/~davem/net-next.html.

Thanks,
Lijun