Move default action from after switch to within

Move from this type of constructions:

switch (val) {
case 1:
	something;
	break;
}
default-action;

into following:

switch (val) {
case 1:
	something;
	break;
default:
	default-action;
	break
}

for cases where the switch statement is not expected to contain a full
set of enum values and as such, does not lose value from not having the
default target.

This makes the intent of default behavior clearer for static analyzers like
gcc with -Wswitch-default.

Signed-off-by: Chaoli Zhou <quic_zchaoli@quicinc.com>
This commit is contained in:
Chaoli Zhou 2022-10-11 18:57:44 +08:00 committed by Jouni Malinen
parent 7614fcebe0
commit f8a05de669
11 changed files with 49 additions and 36 deletions

View file

@ -29,9 +29,9 @@ static const char * mlme_auth_alg_str(int alg)
return "SHARED_KEY"; return "SHARED_KEY";
case WLAN_AUTH_FT: case WLAN_AUTH_FT:
return "FT"; return "FT";
default:
return "unknown";
} }
return "unknown";
} }
#endif /* CONFIG_NO_HOSTAPD_LOGGER */ #endif /* CONFIG_NO_HOSTAPD_LOGGER */

View file

@ -206,9 +206,9 @@ static const char * timeout_next_str(int val)
return "REMOVE"; return "REMOVE";
case STA_DISASSOC_FROM_CLI: case STA_DISASSOC_FROM_CLI:
return "DISASSOC_FROM_CLI"; return "DISASSOC_FROM_CLI";
default:
return "?";
} }
return "?";
} }

View file

@ -530,9 +530,9 @@ static int fils_process_hlp_ip(struct hostapd_data *hapd,
switch (iph->ip_p) { switch (iph->ip_p) {
case 17: case 17:
return fils_process_hlp_udp(hapd, sta, dst, pos, len); return fils_process_hlp_udp(hapd, sta, dst, pos, len);
default:
return 0;
} }
return 0;
} }
@ -567,9 +567,9 @@ static int fils_process_hlp_req(struct hostapd_data *hapd,
case ETH_P_IP: case ETH_P_IP:
return fils_process_hlp_ip(hapd, sta, pos, pkt + 2, return fils_process_hlp_ip(hapd, sta, pos, pkt + 2,
end - pkt - 2); end - pkt - 2);
default:
return 0;
} }
return 0;
} }

View file

@ -1263,8 +1263,9 @@ static int ieee80211_chan_to_freq_us(u8 op_class, u8 chan)
if (chan < 25 || chan > 29) if (chan < 25 || chan > 29)
return -1; return -1;
return 56160 + 2160 * (chan - 24); return 56160 + 2160 * (chan - 24);
default:
return -1;
} }
return -1;
} }
@ -1313,8 +1314,9 @@ static int ieee80211_chan_to_freq_eu(u8 op_class, u8 chan)
if (chan != 25) if (chan != 25)
return -1; return -1;
return 56160 + 2160 * (chan - 24); return 56160 + 2160 * (chan - 24);
default:
return -1;
} }
return -1;
} }
@ -1369,8 +1371,9 @@ static int ieee80211_chan_to_freq_jp(u8 op_class, u8 chan)
if (chan != 25) if (chan != 25)
return -1; return -1;
return 56160 + 2160 * (chan - 24); return 56160 + 2160 * (chan - 24);
default:
return -1;
} }
return -1;
} }
@ -1395,8 +1398,9 @@ static int ieee80211_chan_to_freq_cn(u8 op_class, u8 chan)
if (chan < 149 || chan > 165) if (chan < 149 || chan > 165)
return -1; return -1;
return 5000 + 5 * chan; return 5000 + 5 * chan;
default:
return -1;
} }
return -1;
} }
@ -1482,8 +1486,9 @@ static int ieee80211_chan_to_freq_global(u8 op_class, u8 chan)
if (chan < 25 || chan > 29) if (chan < 25 || chan > 29)
return -1; return -1;
return 56160 + 2160 * (chan - 24); return 56160 + 2160 * (chan - 24);
default:
return -1;
} }
return -1;
} }
/** /**
@ -2613,9 +2618,9 @@ int op_class_to_bandwidth(u8 op_class)
return 6480; return 6480;
case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */ case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */
return 8640; return 8640;
default:
return 20;
} }
return 20;
} }
@ -2677,8 +2682,9 @@ enum oper_chan_width op_class_to_ch_width(u8 op_class)
return CONF_OPER_CHWIDTH_6480MHZ; return CONF_OPER_CHWIDTH_6480MHZ;
case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */ case 183: /* 60 GHz band, EDMG CB4, channel 25..29 */
return CONF_OPER_CHWIDTH_8640MHZ; return CONF_OPER_CHWIDTH_8640MHZ;
default:
return CONF_OPER_CHWIDTH_USE_HT;
} }
return CONF_OPER_CHWIDTH_USE_HT;
} }

View file

@ -603,9 +603,9 @@ static int sswu_curve_param(int group, int *z)
case 30: case 30:
*z = 7; *z = 7;
return 0; return 0;
default:
return -1;
} }
return -1;
} }

View file

@ -2736,9 +2736,9 @@ int wpa_cipher_key_len(int cipher)
return 16; return 16;
case WPA_CIPHER_TKIP: case WPA_CIPHER_TKIP:
return 32; return 32;
default:
return 0;
} }
return 0;
} }
@ -2751,9 +2751,9 @@ int wpa_cipher_rsc_len(int cipher)
case WPA_CIPHER_GCMP: case WPA_CIPHER_GCMP:
case WPA_CIPHER_TKIP: case WPA_CIPHER_TKIP:
return 6; return 6;
default:
return 0;
} }
return 0;
} }
@ -2778,8 +2778,9 @@ enum wpa_alg wpa_cipher_to_alg(int cipher)
return WPA_ALG_BIP_GMAC_256; return WPA_ALG_BIP_GMAC_256;
case WPA_CIPHER_BIP_CMAC_256: case WPA_CIPHER_BIP_CMAC_256:
return WPA_ALG_BIP_CMAC_256; return WPA_ALG_BIP_CMAC_256;
default:
return WPA_ALG_NONE;
} }
return WPA_ALG_NONE;
} }

View file

@ -454,9 +454,9 @@ static const EVP_CIPHER * aes_get_evp_cipher(size_t keylen)
return EVP_aes_192_ecb(); return EVP_aes_192_ecb();
case 32: case 32:
return EVP_aes_256_ecb(); return EVP_aes_256_ecb();
default:
return NULL;
} }
return NULL;
} }
@ -4090,10 +4090,12 @@ int crypto_ec_key_group(struct crypto_ec_key *key)
case NID_brainpoolP512r1: case NID_brainpoolP512r1:
return 30; return 30;
#endif /* NID_brainpoolP512r1 */ #endif /* NID_brainpoolP512r1 */
default:
wpa_printf(MSG_ERROR,
"OpenSSL: Unsupported curve (nid=%d) in EC key",
nid);
return -1;
} }
wpa_printf(MSG_ERROR, "OpenSSL: Unsupported curve (nid=%d) in EC key",
nid);
return -1;
} }

View file

@ -5551,8 +5551,9 @@ static const char * openssl_pkey_type_str(const EVP_PKEY *pkey)
return "DH"; return "DH";
case EVP_PKEY_EC: case EVP_PKEY_EC:
return "EC"; return "EC";
default:
return "?";
} }
return "?";
} }

View file

@ -219,8 +219,9 @@ enum chan_width convert2width(int width)
return CHAN_WIDTH_160; return CHAN_WIDTH_160;
case NL80211_CHAN_WIDTH_320: case NL80211_CHAN_WIDTH_320:
return CHAN_WIDTH_320; return CHAN_WIDTH_320;
default:
return CHAN_WIDTH_UNKNOWN;
} }
return CHAN_WIDTH_UNKNOWN;
} }
@ -3189,9 +3190,9 @@ static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
return RSN_CIPHER_SUITE_WEP40; return RSN_CIPHER_SUITE_WEP40;
case WPA_CIPHER_GTK_NOT_USED: case WPA_CIPHER_GTK_NOT_USED:
return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED;
default:
return 0;
} }
return 0;
} }

View file

@ -147,8 +147,9 @@ static const char * linkmode_str(int mode)
return "kernel-control"; return "kernel-control";
case 1: case 1:
return "userspace-control"; return "userspace-control";
default:
return "?";
} }
return "?";
} }
@ -161,8 +162,9 @@ static const char * operstate_str(int state)
return "IF_OPER_DORMANT"; return "IF_OPER_DORMANT";
case IF_OPER_UP: case IF_OPER_UP:
return "IF_OPER_UP"; return "IF_OPER_UP";
default:
return "?";
} }
return "?";
} }

View file

@ -530,9 +530,9 @@ static enum wpa_driver_if_type wpas_p2p_if_type(int p2p_group_interface)
return WPA_IF_P2P_GO; return WPA_IF_P2P_GO;
case P2P_GROUP_INTERFACE_CLIENT: case P2P_GROUP_INTERFACE_CLIENT:
return WPA_IF_P2P_CLIENT; return WPA_IF_P2P_CLIENT;
default:
return WPA_IF_P2P_GROUP;
} }
return WPA_IF_P2P_GROUP;
} }