Module Name:    src
Committed By:   christos
Date:           Sun Dec 25 02:23:09 UTC 2011

Modified Files:
        src/sys/kern: subr_hash.c

Log Message:
PR/45736: Michael van Elst: setting kern.maxvnodes may lock up
Clamp the number of elements to the max possible if exceeded


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/kern/subr_hash.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_hash.c
diff -u src/sys/kern/subr_hash.c:1.3 src/sys/kern/subr_hash.c:1.4
--- src/sys/kern/subr_hash.c:1.3	Mon May  5 13:11:17 2008
+++ src/sys/kern/subr_hash.c	Sat Dec 24 21:23:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_hash.c,v 1.3 2008/05/05 17:11:17 ad Exp $	*/
+/*	$NetBSD: subr_hash.c,v 1.4 2011/12/25 02:23:09 christos Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.3 2008/05/05 17:11:17 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_hash.c,v 1.4 2011/12/25 02:23:09 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/kmem.h>
@@ -58,9 +58,13 @@ hashinit(u_int elements, enum hashtype h
 	TAILQ_HEAD(, generic) *hashtbl_tailq;
 	size_t esize;
 	void *p;
-
 	if (elements == 0)
 		panic("hashinit: bad cnt");
+
+#define MAXELEMENTS (1U << ((sizeof(elements) * NBBY) - 1))
+	if (elements > MAXELEMENTS)
+		elements = MAXELEMENTS;
+
 	for (hashsize = 1; hashsize < elements; hashsize <<= 1)
 		continue;
 

Reply via email to