Module Name: src
Committed By: riastradh
Date: Wed Jul 24 03:16:16 UTC 2013
Modified Files:
src/sys/external/bsd/drm2/linux [riastradh-drm2]: linux_idr.c
Log Message:
Tweak idr_pre_get.
. No need to test kmem_alloc(n, KM_SLEEP) for NULL.
. Avoid kmem_free with lock held, out of paranoia.
To generate a diff of this commit:
cvs rdiff -u -r1.1.2.5 -r1.1.2.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.1.2.5 src/sys/external/bsd/drm2/linux/linux_idr.c:1.1.2.6
--- src/sys/external/bsd/drm2/linux/linux_idr.c:1.1.2.5 Wed Jul 24 02:51:35 2013
+++ src/sys/external/bsd/drm2/linux/linux_idr.c Wed Jul 24 03:16:15 2013
@@ -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,18 +173,18 @@ idr_remove_all(struct idr *idr)
int
idr_pre_get(struct idr *idr, int flags __unused /* XXX */)
{
- struct idr_node *const temp = kmem_alloc(sizeof(*temp), KM_SLEEP);
-
- if (temp == NULL)
- return 0;
+ struct idr_node *temp = kmem_alloc(sizeof(*temp), KM_SLEEP);
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;
}