diff options
| author | yamt <yamt@NetBSD.org> | 2009-01-22 14:38:34 +0000 |
|---|---|---|
| committer | yamt <yamt@NetBSD.org> | 2009-01-22 14:38:34 +0000 |
| commit | cb1e92d5d5d7bda94104c85eb8917841c69232d0 (patch) | |
| tree | 5008e9b6088c8fe9bff59d03f4bfa51e106035d0 | |
| parent | fc0e181680021843d64afa044ea26f14237de389 (diff) | |
malloc -> kmem_alloc
| -rw-r--r-- | sys/kern/kern_exit.c | 5 | ||||
| -rw-r--r-- | sys/kern/kern_sig.c | 5 | ||||
| -rw-r--r-- | sys/kern/subr_disk.c | 23 | ||||
| -rw-r--r-- | sys/kern/subr_iostat.c | 10 | ||||
| -rw-r--r-- | sys/kern/sys_descrip.c | 6 | ||||
| -rw-r--r-- | sys/kern/sys_process.c | 16 | ||||
| -rw-r--r-- | sys/kern/tty.c | 5 | ||||
| -rw-r--r-- | sys/kern/tty_bsdpty.c | 5 | ||||
| -rw-r--r-- | sys/kern/tty_ptm.c | 5 | ||||
| -rw-r--r-- | sys/kern/tty_pty.c | 34 | ||||
| -rw-r--r-- | sys/kern/tty_subr.c | 26 | ||||
| -rw-r--r-- | sys/sys/tty.h | 5 |
12 files changed, 69 insertions, 76 deletions
diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index b10df0e8788..84caf5ae4e5 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exit.c,v 1.217 2009/01/11 02:45:52 christos Exp $ */ +/* $NetBSD: kern_exit.c,v 1.218 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 1998, 1999, 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.217 2009/01/11 02:45:52 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.218 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ktrace.h" #include "opt_perfctrs.h" @@ -87,7 +87,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_exit.c,v 1.217 2009/01/11 02:45:52 christos Exp #include <sys/file.h> #include <sys/vnode.h> #include <sys/syslog.h> -#include <sys/malloc.h> #include <sys/pool.h> #include <sys/uidinfo.h> #if defined(PERFCTRS) diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index 129ec056e3c..471cabb870b 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_sig.c,v 1.294 2008/12/13 20:49:49 ad Exp $ */ +/* $NetBSD: kern_sig.c,v 1.295 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2006, 2007, 2008 The NetBSD Foundation, Inc. @@ -66,7 +66,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.294 2008/12/13 20:49:49 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.295 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ptrace.h" #include "opt_compat_sunos.h" @@ -85,7 +85,6 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sig.c,v 1.294 2008/12/13 20:49:49 ad Exp $"); #include <sys/syslog.h> #include <sys/filedesc.h> #include <sys/file.h> -#include <sys/malloc.h> #include <sys/pool.h> #include <sys/ucontext.h> #include <sys/sa.h> diff --git a/sys/kern/subr_disk.c b/sys/kern/subr_disk.c index 7233521a825..c8681b11bdf 100644 --- a/sys/kern/subr_disk.c +++ b/sys/kern/subr_disk.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_disk.c,v 1.93 2008/04/28 20:24:04 martin Exp $ */ +/* $NetBSD: subr_disk.c,v 1.94 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 1996, 1997, 1999, 2000 The NetBSD Foundation, Inc. @@ -67,11 +67,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.93 2008/04/28 20:24:04 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_disk.c,v 1.94 2009/01/22 14:38:35 yamt Exp $"); #include <sys/param.h> #include <sys/kernel.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/buf.h> #include <sys/syslog.h> #include <sys/disklabel.h> @@ -202,19 +202,14 @@ disk_attach(struct disk *diskp) { /* - * Allocate and initialize the disklabel structures. Note that - * it's not safe to sleep here, since we're probably going to be - * called during autoconfiguration. + * Allocate and initialize the disklabel structures. */ - diskp->dk_label = malloc(sizeof(struct disklabel), M_DEVBUF, M_NOWAIT); - diskp->dk_cpulabel = malloc(sizeof(struct cpu_disklabel), M_DEVBUF, - M_NOWAIT); + diskp->dk_label = kmem_zalloc(sizeof(struct disklabel), KM_SLEEP); + diskp->dk_cpulabel = kmem_zalloc(sizeof(struct cpu_disklabel), + KM_SLEEP); if ((diskp->dk_label == NULL) || (diskp->dk_cpulabel == NULL)) panic("disk_attach: can't allocate storage for disklabel"); - memset(diskp->dk_label, 0, sizeof(struct disklabel)); - memset(diskp->dk_cpulabel, 0, sizeof(struct cpu_disklabel)); - /* * Set up the stats collection. */ @@ -244,8 +239,8 @@ disk_detach(struct disk *diskp) /* * Free the space used by the disklabel structures. */ - free(diskp->dk_label, M_DEVBUF); - free(diskp->dk_cpulabel, M_DEVBUF); + kmem_free(diskp->dk_label, sizeof(*diskp->dk_label)); + kmem_free(diskp->dk_cpulabel, sizeof(*diskp->dk_cpulabel)); } void diff --git a/sys/kern/subr_iostat.c b/sys/kern/subr_iostat.c index e7313c60827..245cff00efa 100644 --- a/sys/kern/subr_iostat.c +++ b/sys/kern/subr_iostat.c @@ -1,4 +1,4 @@ -/* $NetBSD: subr_iostat.c,v 1.15 2008/05/20 16:03:31 ad Exp $ */ +/* $NetBSD: subr_iostat.c,v 1.16 2009/01/22 14:38:35 yamt Exp $ */ /* NetBSD: subr_disk.c,v 1.69 2005/05/29 22:24:15 christos Exp */ /*- @@ -68,11 +68,11 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.15 2008/05/20 16:03:31 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_iostat.c,v 1.16 2009/01/22 14:38:35 yamt Exp $"); #include <sys/param.h> #include <sys/kernel.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/iostat.h> #include <sys/sysctl.h> #include <sys/rwlock.h> @@ -136,7 +136,7 @@ iostat_alloc(int32_t type, void *parent, const char *name) { struct io_stats *stats; - stats = malloc(sizeof(struct io_stats), M_DEVBUF, M_WAITOK|M_ZERO); + stats = kmem_zalloc(sizeof(*stats), KM_SLEEP); if (stats == NULL) panic("iostat_alloc: cannot allocate memory for stats buffer"); @@ -176,7 +176,7 @@ iostat_free(struct io_stats *stats) TAILQ_REMOVE(&iostatlist, stats, io_link); iostat_count--; rw_exit(&iostatlist_lock); - free(stats, M_DEVBUF); + kmem_free(stats, sizeof(*stats)); } /* diff --git a/sys/kern/sys_descrip.c b/sys/kern/sys_descrip.c index dc821d52a96..eb0de7e05f2 100644 --- a/sys/kern/sys_descrip.c +++ b/sys/kern/sys_descrip.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_descrip.c,v 1.9 2009/01/11 02:45:52 christos Exp $ */ +/* $NetBSD: sys_descrip.c,v 1.10 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -67,7 +67,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.9 2009/01/11 02:45:52 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.10 2009/01/22 14:38:35 yamt Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -82,7 +82,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.9 2009/01/11 02:45:52 christos Exp #include <sys/stat.h> #include <sys/ioctl.h> #include <sys/fcntl.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/pool.h> #include <sys/syslog.h> #include <sys/unistd.h> diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index f04c78945bc..dd7b9bfd92d 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -1,4 +1,4 @@ -/* $NetBSD: sys_process.c,v 1.144 2008/11/19 18:36:07 ad Exp $ */ +/* $NetBSD: sys_process.c,v 1.145 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -115,7 +115,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.144 2008/11/19 18:36:07 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.145 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ptrace.h" #include "opt_ktrace.h" @@ -128,7 +128,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_process.c,v 1.144 2008/11/19 18:36:07 ad Exp $") #include <sys/uio.h> #include <sys/user.h> #include <sys/ras.h> -#include <sys/malloc.h> +#include <sys/kmem.h> #include <sys/kauth.h> #include <sys/mount.h> #include <sys/syscallargs.h> @@ -162,6 +162,7 @@ sys_ptrace(struct lwp *l, const struct sys_ptrace_args *uap, register_t *retval) int signo; ksiginfo_t ksi; char *path; + int len; error = 0; req = SCARG(uap, req); @@ -474,14 +475,15 @@ sys_ptrace(struct lwp *l, const struct sys_ptrace_args *uap, register_t *retval) case PT_DUMPCORE: if ((path = SCARG(uap, addr)) != NULL) { char *dst; - int len = SCARG(uap, data); + len = SCARG(uap, data); + if (len < 0 || len >= MAXPATHLEN) { error = EINVAL; break; } - dst = malloc(len + 1, M_TEMP, M_WAITOK); + dst = kmem_alloc(len + 1, KM_SLEEP); if ((error = copyin(path, dst, len)) != 0) { - free(dst, M_TEMP); + kmem_free(dst, len + 1); break; } path = dst; @@ -489,7 +491,7 @@ sys_ptrace(struct lwp *l, const struct sys_ptrace_args *uap, register_t *retval) } error = (*coredump_vec)(lt, path); if (path) - free(path, M_TEMP); + kmem_free(path, len + 1); break; #ifdef PT_STEP diff --git a/sys/kern/tty.c b/sys/kern/tty.c index b4a0f7dca6b..7ced772e9ac 100644 --- a/sys/kern/tty.c +++ b/sys/kern/tty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty.c,v 1.228 2008/11/19 18:36:07 ad Exp $ */ +/* $NetBSD: tty.c,v 1.229 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.228 2008/11/19 18:36:07 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.229 2009/01/22 14:38:35 yamt Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -79,7 +79,6 @@ __KERNEL_RCSID(0, "$NetBSD: tty.c,v 1.228 2008/11/19 18:36:07 ad Exp $"); #include <sys/kernel.h> #include <sys/vnode.h> #include <sys/syslog.h> -#include <sys/malloc.h> #include <sys/kmem.h> #include <sys/signalvar.h> #include <sys/resourcevar.h> diff --git a/sys/kern/tty_bsdpty.c b/sys/kern/tty_bsdpty.c index 670cb52e5a6..88e2da4014f 100644 --- a/sys/kern/tty_bsdpty.c +++ b/sys/kern/tty_bsdpty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_bsdpty.c,v 1.14 2008/04/28 20:24:05 martin Exp $ */ +/* $NetBSD: tty_bsdpty.c,v 1.15 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.14 2008/04/28 20:24:05 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.15 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ptm.h" @@ -49,7 +49,6 @@ __KERNEL_RCSID(0, "$NetBSD: tty_bsdpty.c,v 1.14 2008/04/28 20:24:05 martin Exp $ #include <sys/filedesc.h> #include <sys/conf.h> #include <sys/poll.h> -#include <sys/malloc.h> #include <sys/pty.h> #include <sys/kauth.h> diff --git a/sys/kern/tty_ptm.c b/sys/kern/tty_ptm.c index ffdd514d9b7..e5d26a0ab05 100644 --- a/sys/kern/tty_ptm.c +++ b/sys/kern/tty_ptm.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_ptm.c,v 1.25 2008/04/28 20:24:05 martin Exp $ */ +/* $NetBSD: tty_ptm.c,v 1.26 2009/01/22 14:38:35 yamt Exp $ */ /*- * Copyright (c) 2004 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.25 2008/04/28 20:24:05 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.26 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ptm.h" @@ -48,7 +48,6 @@ __KERNEL_RCSID(0, "$NetBSD: tty_ptm.c,v 1.25 2008/04/28 20:24:05 martin Exp $"); #include <sys/filedesc.h> #include <sys/conf.h> #include <sys/poll.h> -#include <sys/malloc.h> #include <sys/pty.h> #include <sys/kauth.h> diff --git a/sys/kern/tty_pty.c b/sys/kern/tty_pty.c index 7ca57d69c07..87f48ec8e0d 100644 --- a/sys/kern/tty_pty.c +++ b/sys/kern/tty_pty.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_pty.c,v 1.114 2008/11/15 05:58:33 mrg Exp $ */ +/* $NetBSD: tty_pty.c,v 1.115 2009/01/22 14:38:35 yamt Exp $ */ /* * Copyright (c) 1982, 1986, 1989, 1993 @@ -37,7 +37,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.114 2008/11/15 05:58:33 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.115 2009/01/22 14:38:35 yamt Exp $"); #include "opt_ptm.h" @@ -57,7 +57,6 @@ __KERNEL_RCSID(0, "$NetBSD: tty_pty.c,v 1.114 2008/11/15 05:58:33 mrg Exp $"); #include <sys/filedesc.h> #include <sys/conf.h> #include <sys/poll.h> -#include <sys/malloc.h> #include <sys/pty.h> #include <sys/kauth.h> @@ -151,15 +150,22 @@ pty_isfree(int minor, int lock) * Allocate and zero array of nelem elements. */ static struct pt_softc ** -ptyarralloc(nelem) - int nelem; +ptyarralloc(int nelem) { struct pt_softc **pt; nelem += 10; - pt = malloc(nelem * sizeof *pt, M_DEVBUF, M_WAITOK | M_ZERO); + pt = kmem_zalloc(nelem * sizeof(*pt), KM_SLEEP); return pt; } +static void +ptyarrfree(struct pt_softc **pt, int nelem) +{ + + nelem += 10; + kmem_free(pt, nelem * sizeof(*pt)); +} + /* * Check if the minor is correct and ensure necessary structures * are properly allocated. @@ -172,6 +178,7 @@ pty_check(int ptn) if (ptn >= npty) { struct pt_softc **newpt, **oldpt; int newnpty; + int oldnpty; /* check if the requested pty can be granted */ if (ptn >= maxptys) { @@ -197,12 +204,12 @@ pty_check(int ptn) if (newnpty >= maxptys) { /* limit cut away beneath us... */ - newnpty = maxptys; - if (ptn >= newnpty) { + if (ptn >= maxptys) { mutex_exit(&pt_softc_mutex); - free(newpt, M_DEVBUF); + ptyarrfree(newpt, newnpty); goto limit_reached; } + newnpty = maxptys; } /* @@ -213,15 +220,17 @@ pty_check(int ptn) if (newnpty > npty) { memcpy(newpt, pt_softc, npty*sizeof(struct pt_softc *)); oldpt = pt_softc; + oldnpty = npty; pt_softc = newpt; npty = newnpty; } else { /* was enlarged when waited for lock, free new space */ oldpt = newpt; + oldnpty = newnpty; } mutex_exit(&pt_softc_mutex); - free(oldpt, M_DEVBUF); + ptyarrfree(oldpt, oldnpty); } /* @@ -230,8 +239,7 @@ pty_check(int ptn) * in case it has been lengthened above. */ if (!pt_softc[ptn]) { - pti = malloc(sizeof(struct pt_softc), - M_DEVBUF, M_WAITOK | M_ZERO); + pti = kmem_zalloc(sizeof(*pti), KM_SLEEP); selinit(&pti->pt_selr); selinit(&pti->pt_selw); @@ -248,7 +256,7 @@ pty_check(int ptn) ttyfree(pti->pt_tty); seldestroy(&pti->pt_selr); seldestroy(&pti->pt_selw); - free(pti, M_DEVBUF); + kmem_free(pti, sizeof(*pti)); return (0); } tty_attach(pti->pt_tty); diff --git a/sys/kern/tty_subr.c b/sys/kern/tty_subr.c index e20eac5d80f..cf2ca598b22 100644 --- a/sys/kern/tty_subr.c +++ b/sys/kern/tty_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: tty_subr.c,v 1.34 2008/07/16 18:27:49 drochner Exp $ */ +/* $NetBSD: tty_subr.c,v 1.35 2009/01/22 14:38:35 yamt Exp $ */ /* * Copyright (c) 1993, 1994 Theo de Raadt @@ -29,16 +29,14 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.34 2008/07/16 18:27:49 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.35 2009/01/22 14:38:35 yamt Exp $"); #include <sys/param.h> #include <sys/systm.h> #include <sys/buf.h> #include <sys/ioctl.h> #include <sys/tty.h> -#include <sys/malloc.h> - -MALLOC_DEFINE(M_TTYS, "ttys", "allocated tty structures"); +#include <sys/kmem.h> /* * At compile time, choose: @@ -73,22 +71,20 @@ int clalloc(struct clist *clp, int size, int quot) { - clp->c_cs = malloc(size, M_TTYS, M_WAITOK); + clp->c_cs = kmem_zalloc(size, KM_SLEEP); if (!clp->c_cs) return (-1); - memset(clp->c_cs, 0, size); if(quot) { - clp->c_cq = malloc(QMEM(size), M_TTYS, M_WAITOK); + clp->c_cq = kmem_zalloc(QMEM(size), KM_SLEEP); if (!clp->c_cq) { - free(clp->c_cs, M_TTYS); + kmem_free(clp->c_cs, size); return (-1); } - memset(clp->c_cq, 0, QMEM(size)); } else - clp->c_cq = (u_char *)0; + clp->c_cq = NULL; - clp->c_cf = clp->c_cl = (u_char *)0; + clp->c_cf = clp->c_cl = NULL; clp->c_ce = clp->c_cs + size; clp->c_cn = size; clp->c_cc = 0; @@ -100,10 +96,10 @@ void clfree(struct clist *clp) { if(clp->c_cs) - free(clp->c_cs, M_TTYS); + kmem_free(clp->c_cs, clp->c_cn); if(clp->c_cq) - free(clp->c_cq, M_TTYS); - clp->c_cs = clp->c_cq = (u_char *)0; + kmem_free(clp->c_cq, QMEM(clp->c_cn)); + clp->c_cs = clp->c_cq = NULL; } /* diff --git a/sys/sys/tty.h b/sys/sys/tty.h index 4d530d80863..1cc3bff85b9 100644 --- a/sys/sys/tty.h +++ b/sys/sys/tty.h @@ -1,4 +1,4 @@ -/* $NetBSD: tty.h,v 1.84 2008/11/19 18:36:10 ad Exp $ */ +/* $NetBSD: tty.h,v 1.85 2009/01/22 14:38:34 yamt Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -233,12 +233,9 @@ struct speedtab { TAILQ_HEAD(ttylist_head, tty); /* the ttylist is a TAILQ */ #ifdef _KERNEL -#include <sys/mallocvar.h> extern kmutex_t tty_lock; -MALLOC_DECLARE(M_TTYS); - extern int tty_count; /* number of ttys in global ttylist */ extern struct ttychars ttydefaults; |
