Module Name:    src
Committed By:   riastradh
Date:           Wed Jul 26 03:40:40 UTC 2017

Modified Files:
        src/sys/external/bsd/drm2/linux: linux_idr.c

Log Message:
Tweak slightly sketchy logic in linux_idr.

1. idr_preload can fail if you don't set __GFP_WAIT.
2. If idr_preload fails, it is wrong for idr_alloc to assert.
3. There is no way for idr_alloc to know what flags idr_preload got.

Probably won't *fix* any bugs, but if there is a bug with a missing
__GFP_WAIT, then we will learn about a trifle sooner.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/external/bsd/drm2/linux/linux_idr.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/external/bsd/drm2/linux/linux_idr.c
diff -u src/sys/external/bsd/drm2/linux/linux_idr.c:1.5 src/sys/external/bsd/drm2/linux/linux_idr.c:1.6
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.5	Thu Jan  1 01:15:43 2015
+++ src/sys/external/bsd/drm2/linux/linux_idr.c	Wed Jul 26 03:40:39 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.5 2015/01/01 01:15:43 mrg Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.6 2017/07/26 03:40:39 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.5 2015/01/01 01:15:43 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.6 2017/07/26 03:40:39 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -191,6 +191,7 @@ idr_preload(gfp_t gfp)
 		ASSERT_SLEEPABLE();
 
 	node = kmalloc(sizeof(*node), gfp);
+	KASSERT(node != NULL || !ISSET(gfp, __GFP_WAIT));
 	if (node == NULL)
 		return;
 
@@ -216,8 +217,10 @@ idr_alloc(struct idr *idr, void *data, i
 
 	/* Grab a node allocated by idr_preload.  */
 	mutex_spin_enter(&idr_cache.lock);
-	KASSERTMSG(!SIMPLEQ_EMPTY(&idr_cache.preloaded_nodes),
-	    "missing call to idr_preload");
+	if (SIMPLEQ_EMPTY(&idr_cache.preloaded_nodes)) {
+		mutex_spin_exit(&idr_cache.lock);
+		return -ENOMEM;
+	}
 	node = SIMPLEQ_FIRST(&idr_cache.preloaded_nodes);
 	SIMPLEQ_REMOVE_HEAD(&idr_cache.preloaded_nodes, in_list);
 	mutex_spin_exit(&idr_cache.lock);

Reply via email to