diff options
author | Thomas Haller <thaller@redhat.com> | 2020-01-02 14:42:28 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-01-07 22:01:01 +0100 |
commit | 9ef8f8070b5e342f0d7475244504f5bf22790d94 (patch) | |
tree | 2c4277fc570620e5d47c53ebfe26332ebc7d4d2b | |
parent | d964decbbd925b1cc8fa2eafe03678253db33ac8 (diff) | |
download | NetworkManager-9ef8f8070b5e342f0d7475244504f5bf22790d94.tar.gz |
libnm: return early from nm_utils_security_valid()
Once we know the outcome of the check, just return it instead of
falling though to return a variable "good" which was initialized
two pages earlier.
Also, avoid the "default" switch case. This way, we get a compiler
warning about missing enum values.
-rw-r--r-- | libnm-core/nm-utils.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index bb79476fa1..dc938d353c 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -1122,7 +1122,12 @@ nm_utils_ap_mode_security_valid (NMUtilsSecurityType type, case NMU_SEC_SAE: case NMU_SEC_OWE: return TRUE; - default: + case NMU_SEC_LEAP: + case NMU_SEC_DYNAMIC_WEP: + case NMU_SEC_WPA_ENTERPRISE: + case NMU_SEC_WPA2_ENTERPRISE: + return FALSE; + case NMU_SEC_INVALID: break; } return FALSE; @@ -1161,8 +1166,6 @@ nm_utils_security_valid (NMUtilsSecurityType type, NM80211ApSecurityFlags ap_wpa, NM80211ApSecurityFlags ap_rsn) { - gboolean good = TRUE; - if (!have_ap) { if (type == NMU_SEC_NONE) return TRUE; @@ -1171,8 +1174,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, || ((type == NMU_SEC_LEAP) && !adhoc)) { if (wifi_caps & (NM_WIFI_DEVICE_CAP_CIPHER_WEP40 | NM_WIFI_DEVICE_CAP_CIPHER_WEP104)) return TRUE; - else - return FALSE; + return FALSE; } } @@ -1183,7 +1185,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, return FALSE; if (ap_wpa || ap_rsn) return FALSE; - break; + return TRUE; case NMU_SEC_LEAP: /* require PRIVACY bit for LEAP? */ if (adhoc) return FALSE; @@ -1197,7 +1199,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, if (!device_supports_ap_ciphers (wifi_caps, ap_rsn, TRUE)) return FALSE; } - break; + return TRUE; case NMU_SEC_DYNAMIC_WEP: if (adhoc) return FALSE; @@ -1211,7 +1213,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, if (!device_supports_ap_ciphers (wifi_caps, ap_wpa, FALSE)) return FALSE; } - break; + return TRUE; case NMU_SEC_WPA_PSK: if (adhoc) return FALSE; @@ -1228,7 +1230,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, } return FALSE; } - break; + return TRUE; case NMU_SEC_WPA2_PSK: if (!(wifi_caps & NM_WIFI_DEVICE_CAP_RSN)) return FALSE; @@ -1251,7 +1253,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, } return FALSE; } - break; + return TRUE; case NMU_SEC_WPA_ENTERPRISE: if (adhoc) return FALSE; @@ -1264,7 +1266,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, if (!device_supports_ap_ciphers (wifi_caps, ap_wpa, FALSE)) return FALSE; } - break; + return TRUE; case NMU_SEC_WPA2_ENTERPRISE: if (adhoc) return FALSE; @@ -1277,7 +1279,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, if (!device_supports_ap_ciphers (wifi_caps, ap_rsn, FALSE)) return FALSE; } - break; + return TRUE; case NMU_SEC_SAE: if (!(wifi_caps & NM_WIFI_DEVICE_CAP_RSN)) return FALSE; @@ -1300,7 +1302,7 @@ nm_utils_security_valid (NMUtilsSecurityType type, } return FALSE; } - break; + return TRUE; case NMU_SEC_OWE: if (adhoc) return FALSE; @@ -1310,13 +1312,12 @@ nm_utils_security_valid (NMUtilsSecurityType type, if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_OWE)) return FALSE; } - break; - default: - good = FALSE; + return TRUE; + case NMU_SEC_INVALID: break; } - return good; + return FALSE; } /** |