malloc(9) -> kmem(9)

This commit is contained in:
thorpej 2020-11-21 17:09:34 +00:00
parent d206c3458b
commit 61a804956d
9 changed files with 53 additions and 59 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ewskbd.c,v 1.10 2012/10/13 06:08:30 tsutsui Exp $ */
/* $NetBSD: ewskbd.c,v 1.11 2020/11/21 17:09:34 thorpej Exp $ */
/*-
* Copyright (c) 2005 Izumi Tsutsui. All rights reserved.
@ -59,10 +59,10 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ewskbd.c,v 1.10 2012/10/13 06:08:30 tsutsui Exp $");
__KERNEL_RCSID(0, "$NetBSD: ewskbd.c,v 1.11 2020/11/21 17:09:34 thorpej Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
@ -220,8 +220,8 @@ ewskbd_zsc_attach(device_t parent, device_t self, void *aux)
} else {
wskaa.console = 0;
sc->sc_dc = malloc(sizeof(struct ewskbd_devconfig), M_DEVBUF,
M_WAITOK | M_ZERO);
sc->sc_dc = kmem_zalloc(sizeof(struct ewskbd_devconfig),
KM_SLEEP);
if (sc->sc_dc == NULL) {
printf(": can't allocate memory\n");
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus_dma.c,v 1.15 2015/06/23 21:00:23 matt Exp $ */
/* $NetBSD: bus_dma.c,v 1.16 2020/11/21 17:09:34 thorpej Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -31,13 +31,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.15 2015/06/23 21:00:23 matt Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.16 2020/11/21 17:09:34 thorpej Exp $");
#define _EWS4800MIPS_BUS_DMA_PRIVATE
/* #define BUS_DMA_DEBUG */
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/bus.h>
#include <sys/mbuf.h>
#include <sys/proc.h>
@ -71,6 +71,14 @@ struct ews4800mips_bus_dma_tag ews4800mips_default_bus_dma_tag = {
_bus_dmamem_mmap,
};
static size_t
_bus_dmamap_mapsize(int const nsegments)
{
KASSERT(nsegments > 0);
return sizeof(struct ews4800mips_bus_dmamap) +
(sizeof(bus_dma_segment_t) * (nsegments - 1));
}
/*
* Common function for DMA map creation. May be called by bus-specific
* DMA map creation functions.
@ -81,7 +89,6 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
{
struct ews4800mips_bus_dmamap *map;
void *mapstore;
size_t mapsize;
/*
* Allcoate and initialize the DMA map. The end of the map
@ -95,13 +102,10 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
* The bus_dmamap_t includes one bus_dma_segment_t, hence
* the (nsegments - 1).
*/
mapsize = sizeof(struct ews4800mips_bus_dmamap) +
(sizeof(bus_dma_segment_t) * (nsegments - 1));
if ((mapstore = malloc(mapsize, M_DMAMAP,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
if ((mapstore = kmem_zalloc(_bus_dmamap_mapsize(nsegments),
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
return ENOMEM;
memset(mapstore, 0, mapsize);
map = (struct ews4800mips_bus_dmamap *)mapstore;
map->_dm_size = size;
map->_dm_segcnt = nsegments;
@ -125,7 +129,7 @@ void
_bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
{
free(map, M_DMAMAP);
kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: fb_sbdio.c,v 1.17 2019/11/10 21:16:27 chs Exp $ */
/* $NetBSD: fb_sbdio.c,v 1.18 2020/11/21 17:09:34 thorpej Exp $ */
/*-
* Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
@ -32,11 +32,11 @@
#define WIRED_FB_TLB
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fb_sbdio.c,v 1.17 2019/11/10 21:16:27 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: fb_sbdio.c,v 1.18 2020/11/21 17:09:34 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <dev/cons.h>
#include <uvm/uvm_extern.h> /* pmap function to remap FB */
@ -145,9 +145,8 @@ fb_sbdio_attach(device_t parent, device_t self, void *aux)
sc->sc_ga = &fb_console_ga;
sc->sc_nscreens = 1;
} else {
ri = malloc(sizeof(struct rasops_info), M_DEVBUF,
M_WAITOK | M_ZERO);
ga = malloc(sizeof(struct ga), M_DEVBUF, M_WAITOK | M_ZERO);
ri = kmem_zalloc(sizeof(struct rasops_info), KM_SLEEP);
ga = kmem_zalloc(sizeof(struct ga), KM_SLEEP);
ga->reg_paddr = sa->sa_addr2;
ga->flags = sa->sa_flags;
fb_pmap_enter(sa->sa_addr1, sa->sa_addr2,

View File

@ -1,4 +1,4 @@
/* $NetBSD: int.c,v 1.31 2020/05/29 12:30:40 rin Exp $ */
/* $NetBSD: int.c,v 1.32 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2009 Stephen M. Rumble
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: int.c,v 1.31 2020/05/29 12:30:40 rin Exp $");
__KERNEL_RCSID(0, "$NetBSD: int.c,v 1.32 2020/11/21 17:18:31 thorpej Exp $");
#define __INTR_PRIVATE
#include "opt_cputype.h"
@ -44,7 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: int.c,v 1.31 2020/05/29 12:30:40 rin Exp $");
#include <sys/timetc.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <dev/ic/i8253reg.h>
#include <machine/sysconf.h>
@ -368,7 +368,7 @@ int1_intr_establish(int level, int ipl, int (*handler) (void *), void *arg)
} else {
struct sgimips_intrhand *n, *ih;
ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
ih = kmem_alloc(sizeof *ih, KM_SLEEP);
ih->ih_fun = handler;
ih->ih_arg = arg;
ih->ih_next = NULL;
@ -407,7 +407,7 @@ int2_intr_establish(int level, int ipl, int (*handler) (void *), void *arg)
} else {
struct sgimips_intrhand *n, *ih;
ih = malloc(sizeof *ih, M_DEVBUF, M_WAITOK);
ih = kmem_alloc(sizeof *ih, KM_SLEEP);
ih->ih_fun = handler;
ih->ih_arg = arg;
ih->ih_next = NULL;

View File

@ -1,4 +1,4 @@
/* $NetBSD: zs_kbd.c,v 1.10 2012/10/29 12:51:38 chs Exp $ */
/* $NetBSD: zs_kbd.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2004 Steve Rumble
@ -33,10 +33,10 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: zs_kbd.c,v 1.10 2012/10/29 12:51:38 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: zs_kbd.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $");
#include <sys/param.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
@ -213,10 +213,8 @@ zskbd_attach(device_t parent, device_t self, void *aux)
} else {
wskaa.console = 0;
sc->sc_dc = malloc(sizeof(struct zskbd_devconfig), M_DEVBUF,
M_WAITOK);
if (sc->sc_dc == NULL)
panic("zskbd out of memory");
sc->sc_dc = kmem_alloc(sizeof(struct zskbd_devconfig),
KM_SLEEP);
sc->sc_dc->enabled = 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: grtwo.c,v 1.15 2018/09/03 16:29:27 riastradh Exp $ */
/* $NetBSD: grtwo.c,v 1.16 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2004 Christopher SEKIYA
@ -35,12 +35,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: grtwo.c,v 1.15 2018/09/03 16:29:27 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: grtwo.c,v 1.16 2020/11/21 17:18:31 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <machine/sysconf.h>
@ -507,10 +507,8 @@ grtwo_attach(device_t parent, device_t self, void *aux)
sc->sc_dc = &grtwo_console_dc;
} else {
wa.console = 0;
sc->sc_dc = malloc(sizeof(struct grtwo_devconfig),
M_DEVBUF, M_WAITOK | M_ZERO);
if (sc->sc_dc == NULL)
panic("grtwo_attach: out of memory");
sc->sc_dc = kmem_zalloc(sizeof(struct grtwo_devconfig),
KM_SLEEP);
grtwo_attach_common(sc->sc_dc, ga);
}

View File

@ -1,4 +1,4 @@
/* $Id: light.c,v 1.7 2012/10/27 17:18:09 chs Exp $ */
/* $Id: light.c,v 1.8 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2006 Stephen M. Rumble
@ -43,12 +43,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: light.c,v 1.7 2012/10/27 17:18:09 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: light.c,v 1.8 2020/11/21 17:18:31 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <machine/sysconf.h>
@ -320,10 +320,8 @@ light_attach(device_t parent, device_t self, void *aux)
sc->sc_dc = &light_console_dc;
} else {
wa.console = 0;
sc->sc_dc = malloc(sizeof(struct light_devconfig), M_DEVBUF,
M_WAITOK | M_ZERO);
if (sc->sc_dc == NULL)
panic("light_attach: out of memory");
sc->sc_dc = kmem_zalloc(sizeof(struct light_devconfig),
KM_SLEEP);
light_attach_common(sc->sc_dc, ga);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: newport.c,v 1.20 2019/05/10 23:21:42 macallan Exp $ */
/* $NetBSD: newport.c,v 1.21 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2003 Ilpo Ruotsalainen
@ -31,12 +31,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: newport.c,v 1.20 2019/05/10 23:21:42 macallan Exp $");
__KERNEL_RCSID(0, "$NetBSD: newport.c,v 1.21 2020/11/21 17:18:31 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <machine/sysconf.h>
@ -613,10 +613,8 @@ newport_attach(device_t parent, device_t self, void *aux)
sc->sc_dc = &newport_console_dc;
} else {
wa.console = 0;
sc->sc_dc = malloc(sizeof(struct newport_devconfig),
M_DEVBUF, M_WAITOK | M_ZERO);
if (sc->sc_dc == NULL)
panic("newport_attach: out of memory");
sc->sc_dc = kmem_zalloc(sizeof(struct newport_devconfig),
KM_SLEEP);
newport_attach_common(sc->sc_dc, ga);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: pckbc_hpc.c,v 1.10 2015/02/18 16:47:58 macallan Exp $ */
/* $NetBSD: pckbc_hpc.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $ */
/*
* Copyright (c) 2003 Christopher SEKIYA
@ -33,14 +33,14 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: pckbc_hpc.c,v 1.10 2015/02/18 16:47:58 macallan Exp $");
__KERNEL_RCSID(0, "$NetBSD: pckbc_hpc.c,v 1.11 2020/11/21 17:18:31 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/proc.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/errno.h>
#include <sys/queue.h>
#include <sys/bus.h>
@ -109,8 +109,7 @@ pckbc_hpc_attach(device_t parent, device_t self, void *aux)
haa->ha_devoff + KBCMDP, 1, &ioh_c))
panic("pckbc_hpc_attach: couldn't map");
t = malloc(sizeof(struct pckbc_internal), M_DEVBUF,
M_WAITOK | M_ZERO);
t = kmem_zalloc(sizeof(struct pckbc_internal), KM_SLEEP);
t->t_iot = hpc_memt;
t->t_ioh_d = ioh_d;
t->t_ioh_c = ioh_c;