Module Name:    src
Committed By:   riastradh
Date:           Tue Oct 17 11:55:28 UTC 2023

Modified Files:
        src/sys/kern: subr_thmap.c

Log Message:
thmap(9): Test alloc failure, not THMAP_GETPTR failure.

THMAP_GETPTR may return nonnull even though alloc returned zero.

Note that this failure branch is not actually appropriate;
thmap_create should not fail.  We really need to pass KM_SLEEP
through in this call site even though there are other call sites for
which KM_NOSLEEP is appropriate.

Adapted from: https://github.com/rmind/thmap/pull/14

PR kern/57666
https://github.com/rmind/thmap/issues/13

XXX pullup-10
XXX pullup-9


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/kern/subr_thmap.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/kern/subr_thmap.c
diff -u src/sys/kern/subr_thmap.c:1.13 src/sys/kern/subr_thmap.c:1.14
--- src/sys/kern/subr_thmap.c:1.13	Tue Apr 11 13:06:21 2023
+++ src/sys/kern/subr_thmap.c	Tue Oct 17 11:55:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_thmap.c,v 1.13 2023/04/11 13:06:21 riastradh Exp $	*/
+/*	$NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2018 Mindaugas Rasiukevicius <rmind at noxt eu>
@@ -112,7 +112,7 @@
 #include "utils.h"
 #endif
 
-THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.13 2023/04/11 13:06:21 riastradh Exp $");
+THMAP_RCSID("$NetBSD: subr_thmap.c,v 1.14 2023/10/17 11:55:28 riastradh Exp $");
 
 #include <crypto/blake2/blake2s.h>
 
@@ -987,11 +987,11 @@ thmap_create(uintptr_t baseptr, const th
 	if ((thmap->flags & THMAP_SETROOT) == 0) {
 		/* Allocate the root level. */
 		root = thmap->ops->alloc(THMAP_ROOT_LEN);
-		thmap->root = THMAP_GETPTR(thmap, root);
-		if (!thmap->root) {
+		if (!root) {
 			kmem_free(thmap, sizeof(thmap_t));
 			return NULL;
 		}
+		thmap->root = THMAP_GETPTR(thmap, root);
 		memset(thmap->root, 0, THMAP_ROOT_LEN);
 	}
 

Reply via email to