diff options
author | Thomas Haller <thaller@redhat.com> | 2018-06-14 11:02:24 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-06-15 09:07:19 +0200 |
commit | 6e12e18c15f8b0daa629f3b242f44e2215df0669 (patch) | |
tree | ea197856c2a360b483d5657054769cf6be2ed220 | |
parent | b31bc4fa6cc8fc4d6a7aa84058fc4c06861e6610 (diff) | |
download | NetworkManager-6e12e18c15f8b0daa629f3b242f44e2215df0669.tar.gz |
device: simplify nm_device_hash_check_invalid_keys()
Rather trivial change. Return-early, to completely handle the simpler
case (the success case) first. In the failure case, we only need
extra effort to generate a nice error message.
-rw-r--r-- | src/devices/nm-device.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 6cda25bb3e..9df4141016 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -10203,7 +10203,7 @@ _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setting_name, nm_assert (whitelist && whitelist[0]); #if NM_MORE_ASSERTS > 10 - /* Assert that the keys are unique. */ + /* Require whitelist to only contain unique keys. */ { gs_unref_hashtable GHashTable *check_dups = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, NULL); @@ -10220,14 +10220,16 @@ _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setting_name, found_whitelisted_keys++; } - if (found_whitelisted_keys != g_hash_table_size (hash)) { + if (found_whitelisted_keys == g_hash_table_size (hash)) { + /* Good, there are only whitelisted keys in the hash. */ + return TRUE; + } + + if (error) { GHashTableIter iter; const char *k = NULL; const char *first_invalid_key = NULL; - if (!error) - return FALSE; - g_hash_table_iter_init (&iter, hash); while (g_hash_table_iter_next (&iter, (gpointer *) &k, NULL)) { if (nm_utils_strv_find_first ((char **) whitelist, -1, k) < 0) { @@ -10250,10 +10252,9 @@ _nm_device_hash_check_invalid_keys (GHashTable *hash, const char *setting_name, first_invalid_key); } g_return_val_if_fail (first_invalid_key, FALSE); - return FALSE; } - return TRUE; + return FALSE; } void |