Wed Jul 24 03:16:16 2013 UTC ()
Tweak idr_pre_get.

. No need to test kmem_alloc(n, KM_SLEEP) for NULL.
. Avoid kmem_free with lock held, out of paranoia.


(riastradh)
diff -r1.1.2.5 -r1.1.2.6 src/sys/external/bsd/drm2/linux/linux_idr.c

cvs diff -r1.1.2.5 -r1.1.2.6 src/sys/external/bsd/drm2/linux/linux_idr.c (expand / switch to context diff)
--- src/sys/external/bsd/drm2/linux/linux_idr.c 2013/07/24 02:51:35 1.1.2.5
+++ src/sys/external/bsd/drm2/linux/linux_idr.c 2013/07/24 03:16:15 1.1.2.6
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_idr.c,v 1.1.2.5 2013/07/24 02:51:35 riastradh Exp $	*/
+/*	$NetBSD: linux_idr.c,v 1.1.2.6 2013/07/24 03:16:15 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.1.2.5 2013/07/24 02:51:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_idr.c,v 1.1.2.6 2013/07/24 03:16:15 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -173,17 +173,17 @@
 int
 idr_pre_get(struct idr *idr, int flags __unused /* XXX */)
 {
-	struct idr_node *const temp = kmem_alloc(sizeof(*temp), KM_SLEEP);
+	struct idr_node *temp = kmem_alloc(sizeof(*temp), KM_SLEEP);
 
-	if (temp == NULL)
-		return 0;
-
 	rw_enter(&idr->idr_lock, RW_WRITER);
-	if (idr->idr_temp == NULL)
+	if (idr->idr_temp == NULL) {
 		idr->idr_temp = temp;
-	else
-		kmem_free(temp, sizeof(*temp));
+		temp = NULL;
+	}
 	rw_exit(&idr->idr_lock);
+
+	if (temp != NULL)
+		kmem_free(temp, sizeof(*temp));
 
 	return 1;
 }