Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Assert that pool_get failure happens only with PR_N...



details:   https://anonhg.NetBSD.org/src/rev/b34fcf33f133
branches:  trunk
changeset: 827643:b34fcf33f133
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Nov 06 18:41:22 2017 +0000

description:
Assert that pool_get failure happens only with PR_NOWAIT.

This would have caught the mistake I made last week leading to null
pointer dereferences all over the place, a mistake which I evidently
poorly scheduled alongside maxv's change to the panic message on x86
for null pointer dereferences.

diffstat:

 sys/kern/subr_pool.c |  15 ++++++++++++---
 1 files changed, 12 insertions(+), 3 deletions(-)

diffs (58 lines):

diff -r 68a636dcdbdb -r b34fcf33f133 sys/kern/subr_pool.c
--- a/sys/kern/subr_pool.c      Mon Nov 06 17:56:25 2017 +0000
+++ b/sys/kern/subr_pool.c      Mon Nov 06 18:41:22 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_pool.c,v 1.210 2017/11/05 07:49:45 mlelstv Exp $  */
+/*     $NetBSD: subr_pool.c,v 1.211 2017/11/06 18:41:22 riastradh Exp $        */
 
 /*-
  * Copyright (c) 1997, 1999, 2000, 2002, 2007, 2008, 2010, 2014, 2015
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.210 2017/11/05 07:49:45 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pool.c,v 1.211 2017/11/06 18:41:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -805,6 +805,7 @@
                pp->pr_nfail++;
 
                mutex_exit(&pp->pr_lock);
+               KASSERT((flags & (PR_WAITOK|PR_NOWAIT)) == PR_NOWAIT);
                return (NULL);
        }
 
@@ -848,6 +849,7 @@
 
                        pp->pr_nfail++;
                        mutex_exit(&pp->pr_lock);
+                       KASSERT((flags & (PR_WAITOK|PR_NOWAIT)) == PR_NOWAIT);
                        return (NULL);
                }
 
@@ -2181,8 +2183,10 @@
 
        object = pool_get(&pc->pc_pool, flags);
        *objectp = object;
-       if (__predict_false(object == NULL))
+       if (__predict_false(object == NULL)) {
+               KASSERT((flags & (PR_WAITOK|PR_NOWAIT)) == PR_NOWAIT);
                return false;
+       }
 
        if (__predict_false((*pc->pc_ctor)(pc->pc_arg, object, flags) != 0)) {
                pool_put(&pc->pc_pool, object);
@@ -2273,6 +2277,11 @@
                        break;
        }
 
+       /*
+        * We would like to KASSERT(object || (flags & PR_NOWAIT)), but
+        * pool_cache_get can fail even in the PR_WAITOK case, if the
+        * constructor fails.
+        */
        return object;
 }
 



Home | Main Index | Thread Index | Old Index