Skip to contentSkip to conversation

selinux: ss: use match_string() helper to simplify the code

PATCH New zhong jiang 1 participant 1 message Sep 14, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selinux: ss: use match_string() helper to simplify the code

match_string() returns the index of an array for a matching string, which can be used intead of open coded implementation.

---
 security/selinux/ss/services.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
security/selinux/ss/services.c +6 -6
index 12e4143..aa9fc35 100644
@@ -1461,14 +1461,14 @@ static int security_context_to_sid_core(struct selinux_state *state,
 		return -ENOMEM;
 
 	if (!state->initialized) {
-		int i;
+		int index;
 
-		for (i = 1; i < SECINITSID_NUM; i++) {
-			if (!strcmp(initial_sid_to_string[i], scontext2)) {
-				*sid = i;
-				goto out;
-			}
+		index = match_string(initial_sid_to_string, SECINITSID_NUM, scontext2);
+		if (index >= 0) {
+			*sid = index;
+			goto out;
 		}
+
 		*sid = SECINITSID_KERNEL;
 		goto out;
 	}
Signature · 1 line
1.7.12.4