Skip to contentSkip to conversation

remove NGROUPS hard limit (resend)

PATCH In review Timothy Hockin 2 participants 2 messages Nov 5, 2002 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 remove NGROUPS hard limit (resend)

# This is a BitKeeper generated patch for the following project:
# Project Name: Linux kernel tree
# This patch format is intended for GNU patch command version 2.5 or higher. # This patch includes the following deltas:
# ChangeSet 1.929 -> 1.930
# include/linux/kernel.h 1.24 -> 1.25

#	        lib/Makefile	1.15    -> 1.16   
#	               (new)	        -> 1.1     lib/bsearch.c  
#	               (new)	        -> 1.1     lib/qsort.c    

#
# The following is the BitKeeper ChangeSet Log
# --------------------------------------------
# 02/11/05 [email protected] 1.930
# Add generic qsort() and bsearch(): qsort() from BSD, bsearch() from glibc # --------------------------------------------
#

include/linux/kernel.h +5 -0
diff -Nru a/include/linux/kernel.h b/include/linux/kernel.h
@@ -215,4 +215,9 @@
 #define __FUNCTION__ (__func__)
 #endif
 
+void qsort(void *base, size_t nmemb, size_t size,
+	int (*compar)(const void *, const void *));
+void *bsearch(const void *key, const void *base, size_t nmemb, size_t size,
+	int (*compar)(const void *, const void *));
+
 #endif
lib/Makefile +2 -2
diff -Nru a/lib/Makefile b/lib/Makefile
@@ -9,11 +9,11 @@
 L_TARGET := lib.a
 
 export-objs := cmdline.o dec_and_lock.o rwsem-spinlock.o rwsem.o \
-	       crc32.o rbtree.o radix-tree.o kobject.o
+	       crc32.o rbtree.o radix-tree.o kobject.o qsort.o bsearch.o
 
 obj-y := errno.o ctype.o string.o vsprintf.o brlock.o cmdline.o \
 	 bust_spinlocks.o rbtree.o radix-tree.o dump_stack.o \
-	 kobject.o
+	 kobject.o qsort.o bsearch.o
 
 obj-$(CONFIG_RWSEM_GENERIC_SPINLOCK) += rwsem-spinlock.o
 obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
lib/bsearch.c new file +49 -0

49 lines not on this page · raw message

lib/qsort.c new file +177 -0

177 lines not on this page · raw message

#1 lore raw

lib/qsort.c line 102

Quoted 4 lines
lib/qsort.c new file +4 -0
+void
+qsort(void *a, size_t n, size_t es, cmp_t *cmp)
+{
+	char *pa, *pb, *pc, *pd, *pl, *pm, *pn;

A recursive algorithm fed user controlled input that dictates how much it recurses, in a kernel with a stack limit. Oh and since qsort is O(N^2) worst case and the user controls the input thats another concern.

lib/qsort.c line 170

Quoted 4 lines
lib/qsort.c new file +4 -0
+	if ((r = pb - pa) > es)
+		qsort(a, r / es, es, cmp);
+	if ((r = pd - pc) > es) {
+		/* Iterate rather than recurse to save stack space */

I find it hard to believe that a simple bucket sort wouldnt perform as well in real life and with a defined time/space, or even something like shell metzner if you want trivial with good typical behaviour.

Alternatively you could just do a merge pass when a new set of groups is added.