From 2e8a5bee6869b36db2cf73bc39123dbaf1bed731 Mon Sep 17 00:00:00 2001 From: yamt Date: Mon, 7 Jan 2008 11:41:29 +0000 Subject: [PATCH] lwp_ctl_alloc: fix error handling. --- sys/kern/kern_lwp.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c index 826f00a258e2..6e14e6f38ce0 100644 --- a/sys/kern/kern_lwp.c +++ b/sys/kern/kern_lwp.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_lwp.c,v 1.88 2008/01/02 11:48:50 ad Exp $ */ +/* $NetBSD: kern_lwp.c,v 1.89 2008/01/07 11:41:29 yamt Exp $ */ /*- * Copyright (c) 2001, 2006, 2007 The NetBSD Foundation, Inc. @@ -205,7 +205,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.88 2008/01/02 11:48:50 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.89 2008/01/07 11:41:29 yamt Exp $"); #include "opt_ddb.h" #include "opt_multiprocessor.h" @@ -1515,15 +1515,21 @@ lwp_ctl_alloc(vaddr_t *uaddr) uao, lp->lp_cur, PAGE_SIZE, UVM_MAPFLAG(UVM_PROT_RW, UVM_PROT_RW, UVM_INH_NONE, UVM_ADV_RANDOM, 0)); - if (error == 0) - error = uvm_map_pageable(kernel_map, lcp->lcp_kaddr, - lcp->lcp_kaddr + PAGE_SIZE, FALSE, 0); if (error != 0) { mutex_exit(&lp->lp_lock); kmem_free(lcp, LWPCTL_LCPAGE_SZ); (*uao->pgops->pgo_detach)(uao); return error; } + error = uvm_map_pageable(kernel_map, lcp->lcp_kaddr, + lcp->lcp_kaddr + PAGE_SIZE, FALSE, 0); + if (error != 0) { + mutex_exit(&lp->lp_lock); + uvm_unmap(kernel_map, lcp->lcp_kaddr, + lcp->lcp_kaddr + PAGE_SIZE); + kmem_free(lcp, LWPCTL_LCPAGE_SZ); + return error; + } /* Prepare the page descriptor and link into the list. */ lcp->lcp_uaddr = lp->lp_uva + lp->lp_cur; lp->lp_cur += PAGE_SIZE;