kernel/groups.c: use sort library function
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.
Signed-off-by Rasmus Villemoes <[email protected]>
Cc Matthew Wilcox <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Alexey Dobriyan <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
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
@@ -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 groupreturn 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];