aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorRasmus Villemoes <linux@rasmusvillemoes.dk>2017-07-10 18:51:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-10 19:32:34 -0400
commitb7b2562f7252878e18de60c24f320052076f9de8 (patch)
treef5b30652d73cbfe14e010044489bc06b37d62bcf /kernel
parent9dcdcea11491f6eee65bd1b352293ca01e4b7997 (diff)
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. Link: http://lkml.kernel.org/r/1497301378-22739-1-git-send-email-linux@rasmusvillemoes.dk Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk> Cc: Matthew Wilcox <mawilcox@microsoft.com> Cc: Michal Hocko <mhocko@suse.com> Cc: Alexey Dobriyan <adobriyan@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/groups.c35
1 files changed, 11 insertions, 24 deletions
diff --git a/kernel/groups.c b/kernel/groups.c
index d09727692a2a..434f6665f187 100644
--- a/kernel/groups.c
+++ b/kernel/groups.c
@@ -5,6 +5,7 @@
5#include <linux/export.h> 5#include <linux/export.h>
6#include <linux/slab.h> 6#include <linux/slab.h>
7#include <linux/security.h> 7#include <linux/security.h>
8#include <linux/sort.h>
8#include <linux/syscalls.h> 9#include <linux/syscalls.h>
9#include <linux/user_namespace.h> 10#include <linux/user_namespace.h>
10#include <linux/vmalloc.h> 11#include <linux/vmalloc.h>
@@ -76,32 +77,18 @@ static int groups_from_user(struct group_info *group_info,
76 return 0; 77 return 0;
77} 78}
78 79
79/* a simple Shell sort */ 80static int gid_cmp(const void *_a, const void *_b)
81{
82 kgid_t a = *(kgid_t *)_a;
83 kgid_t b = *(kgid_t *)_b;
84
85 return gid_gt(a, b) - gid_lt(a, b);
86}
87
80static void groups_sort(struct group_info *group_info) 88static void groups_sort(struct group_info *group_info)
81{ 89{
82 int base, max, stride; 90 sort(group_info->gid, group_info->ngroups, sizeof(*group_info->gid),
83 int gidsetsize = group_info->ngroups; 91 gid_cmp, NULL);
84
85 for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
86 ; /* nothing */
87 stride /= 3;
88
89 while (stride) {
90 max = gidsetsize - stride;
91 for (base = 0; base < max; base++) {
92 int left = base;
93 int right = left + stride;
94 kgid_t tmp = group_info->gid[right];
95
96 while (left >= 0 && gid_gt(group_info->gid[left], tmp)) {
97 group_info->gid[right] = group_info->gid[left];
98 right = left;
99 left -= stride;
100 }
101 group_info->gid[right] = tmp;
102 }
103 stride /= 3;
104 }
105} 92}
106 93
107/* a simple bsearch */ 94/* a simple bsearch */