Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/riastradh-drm2]: src/sys/external/bsd/drm2/linux Tweak idr_pre_get.



details:   https://anonhg.NetBSD.org/src/rev/35bcd5c293f5
branches:  riastradh-drm2
changeset: 788326:35bcd5c293f5
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Wed Jul 24 03:16:15 2013 +0000

description:
Tweak idr_pre_get.

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

diffstat:

 sys/external/bsd/drm2/linux/linux_idr.c |  18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diffs (43 lines):

diff -r 20990228fac8 -r 35bcd5c293f5 sys/external/bsd/drm2/linux/linux_idr.c
--- a/sys/external/bsd/drm2/linux/linux_idr.c   Wed Jul 24 03:15:59 2013 +0000
+++ b/sys/external/bsd/drm2/linux/linux_idr.c   Wed Jul 24 03:16:15 2013 +0000
@@ -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);
-
-       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
+               temp = NULL;
+       }
+       rw_exit(&idr->idr_lock);
+
+       if (temp != NULL)
                kmem_free(temp, sizeof(*temp));
-       rw_exit(&idr->idr_lock);
 
        return 1;
 }



Home | Main Index | Thread Index | Old Index