Skip to contentSkip to conversation

kernel/groups.c: use sort library function

PATCH New [email protected] 1 participant 1 message Jul 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 81/115 kernel/groups.c: use sort library function

From: Rasmus Villemoes <[email protected]>
Subject: kernel/groups.c: use sort library function

setgroups is not exactly a hot path, so we might as well use the library function instead of open-coding the sorting. Saves ~150 bytes.

---

 kernel/groups.c |   35 +++++++++++------------------------
 1 file changed, 11 insertions(+), 24 deletions(-)
kernel/groups.c renamed from kernel/groups.c~kernel-groupsc-use-sort-library-function +4 -14
diff -puN kernel/groups.c~kernel-groupsc-use-sort-library-function kernel/groups.c
@@ -5,6 +5,7 @@
 #include <linux/export.h>
 #include <linux/slab.h>
 #include <linux/security.h>
+#include <linux/sort.h>
 #include <linux/syscalls.h>
 #include <linux/user_namespace.h>
 #include <linux/vmalloc.h>
@@ -76,32 +77,18 @@ static int groups_from_user(struct group
 	return 0;
 }
 
-/* a simple Shell sort */
-static void groups_sort(struct group_info *group_info)
+static int gid_cmp(const void *_a, const void *_b)
 {
-	int base, max, stride;
-	int gidsetsize = group_info->ngroups;
+	kgid_t a = *(kgid_t *)_a;
+	kgid_t b = *(kgid_t *)_b;
 
-	for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
-		; /* nothing */
-	stride /= 3;
-
-	while (stride) {
-		max = gidsetsize - stride;
-		for (base = 0; base < max; base++) {
-			int left = base;
-			int right = left + stride;
-			kgid_t tmp = group_info->gid[right];