malloc(9) -> kmem(9)

This commit is contained in:
thorpej 2020-11-21 00:27:52 +00:00
parent 91454f41a4
commit fd5889cbee
11 changed files with 64 additions and 68 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: sc_mbmem.c,v 1.14 2009/11/21 04:16:52 rmind Exp $ */
/* $NetBSD: sc_mbmem.c,v 1.15 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -59,13 +59,13 @@
****************************************************************/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sc_mbmem.c,v 1.14 2009/11/21 04:16:52 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: sc_mbmem.c,v 1.15 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <sys/buf.h>
#include <sys/proc.h>
@ -164,9 +164,7 @@ sunsc_mbmem_attach(device_t parent, device_t self, void *args)
/* Allocate DMA handles. */
i = SUNSCPAL_OPENINGS * sizeof(struct sunscpal_dma_handle);
sc->sc_dma_handles = malloc(i, M_DEVBUF, M_WAITOK);
if (sc->sc_dma_handles == NULL)
panic("sc: DMA handles malloc failed");
sc->sc_dma_handles = kmem_alloc(i, KM_SLEEP);
for (i = 0; i < SUNSCPAL_OPENINGS; i++)
if (bus_dmamap_create(sc->sunscpal_dmat, SUNSCPAL_MAX_DMA_LEN,
1, SUNSCPAL_MAX_DMA_LEN,

View File

@ -1,4 +1,4 @@
/* $NetBSD: cg4.c,v 1.41 2014/07/25 08:10:35 dholland Exp $ */
/* $NetBSD: cg4.c,v 1.42 2020/11/21 00:27:52 thorpej Exp $ */
/*
* Copyright (c) 1992, 1993
@ -55,14 +55,14 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cg4.c,v 1.41 2014/07/25 08:10:35 dholland Exp $");
__KERNEL_RCSID(0, "$NetBSD: cg4.c,v 1.42 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/ioctl.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/mman.h>
#include <sys/proc.h>
#include <sys/tty.h>
@ -573,7 +573,7 @@ cg4b_init(struct cg4_softc *sc)
int i;
/* Need a buffer for colormap format translation. */
btcm = malloc(sizeof(*btcm), M_DEVBUF, M_WAITOK);
btcm = kmem_alloc(sizeof(*btcm), KM_SLEEP);
sc->sc_btcm = btcm;
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: eeprom.c,v 1.33 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: eeprom.c,v 1.34 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -38,14 +38,14 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: eeprom.c,v 1.33 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: eeprom.c,v 1.34 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/buf.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/proc.h>
#include <sys/kernel.h>
@ -105,7 +105,7 @@ eeprom_attach(device_t parent, device_t self, void *args)
panic("%s: can't map va", __func__);
/* Keep a "soft" copy of the EEPROM to make access simpler. */
eeprom_copy = malloc(ee_size, M_DEVBUF, M_WAITOK);
eeprom_copy = kmem_alloc(ee_size, KM_SLEEP);
/*
* On the 3/80, do not touch the last 40 bytes!

View File

@ -1,4 +1,4 @@
/* $NetBSD: fd.c,v 1.83 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: fd.c,v 1.84 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@ -72,7 +72,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.83 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.84 2020/11/21 00:27:52 thorpej Exp $");
#include "opt_ddb.h"
@ -88,7 +88,7 @@ __KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.83 2019/11/10 21:16:33 chs Exp $");
#include <sys/fdio.h>
#include <sys/buf.h>
#include <sys/bufq.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/proc.h>
#include <sys/uio.h>
#include <sys/stat.h>
@ -1733,8 +1733,7 @@ fdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
return EINVAL;
}
fd_formb = malloc(sizeof(struct ne7_fd_formb),
M_TEMP, M_WAITOK);
fd_formb = kmem_alloc(sizeof(*fd_formb), KM_SLEEP);
fd_formb->head = form_cmd->head;
fd_formb->cyl = form_cmd->cylinder;
fd_formb->transfer_rate = fd->sc_type->rate;
@ -1758,7 +1757,7 @@ fdioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
}
error = fdformat(dev, fd_formb, l->l_proc);
free(fd_formb, M_TEMP);
kmem_free(fd_formb, sizeof(*fd_formb));
return error;
case FDIOCGETOPTS: /* get drive options */
@ -1985,7 +1984,7 @@ fd_read_md_image(size_t *sizep, void **addrp)
dev = makedev(cdevsw_lookup_major(&fd_cdevsw), 0); /* XXX */
addr = malloc(FDMICROROOTSIZE, M_DEVBUF, M_WAITOK);
addr = kmem_alloc(FDMICROROOTSIZE, KM_SLEEP);
*addrp = addr;
if (fdopen(dev, 0, S_IFCHR, NULL))

View File

@ -1,4 +1,4 @@
/* $NetBSD: si.c,v 1.63 2009/11/21 04:16:52 rmind Exp $ */
/* $NetBSD: si.c,v 1.64 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -70,13 +70,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si.c,v 1.63 2009/11/21 04:16:52 rmind Exp $");
__KERNEL_RCSID(0, "$NetBSD: si.c,v 1.64 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <sys/buf.h>
#include <sys/proc.h>
@ -164,10 +164,7 @@ si_attach(struct si_softc *sc)
* Allocate DMA handles.
*/
i = SCI_OPENINGS * sizeof(struct si_dma_handle);
sc->sc_dma = (struct si_dma_handle *)
malloc(i, M_DEVBUF, M_WAITOK);
if (sc->sc_dma == NULL)
panic("si: dvma_malloc failed");
sc->sc_dma = kmem_alloc(i, KM_SLEEP);
for (i = 0; i < SCI_OPENINGS; i++)
sc->sc_dma[i].dh_flags = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: si_sebuf.c,v 1.29 2013/11/07 17:50:18 christos Exp $ */
/* $NetBSD: si_sebuf.c,v 1.30 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -37,13 +37,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: si_sebuf.c,v 1.29 2013/11/07 17:50:18 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: si_sebuf.c,v 1.30 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/errno.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <sys/buf.h>
#include <sys/proc.h>
@ -250,9 +250,7 @@ se_attach(device_t parent, device_t self, void *args)
* Allocate DMA handles.
*/
i = SCI_OPENINGS * sizeof(struct se_dma_handle);
sc->sc_dma = malloc(i, M_DEVBUF, M_WAITOK);
if (sc->sc_dma == NULL)
panic("se: dma_malloc failed");
sc->sc_dma = kmem_alloc(i, KM_SLEEP);
for (i = 0; i < SCI_OPENINGS; i++)
sc->sc_dma[i].dh_flags = 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: xd.c,v 1.74 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: xd.c,v 1.75 2020/11/21 00:27:52 thorpej Exp $ */
/*
* Copyright (c) 1995 Charles D. Cranor
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.74 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.75 2020/11/21 00:27:52 thorpej Exp $");
#undef XDC_DEBUG /* full debug */
#define XDC_DIAG /* extra sanity checks */
@ -64,7 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: xd.c,v 1.74 2019/11/10 21:16:33 chs Exp $");
#include <sys/buf.h>
#include <sys/bufq.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <sys/disklabel.h>
#include <sys/disk.h>
@ -446,8 +446,8 @@ xdcattach(device_t parent, device_t self, void *aux)
memset(xdc->iopbase, 0, XDC_MAXIOPB * sizeof(struct xd_iopb));
xdc->dvmaiopb = (struct xd_iopb *)dvma_kvtopa(xdc->iopbase,
xdc->bustype);
xdc->reqs = malloc(XDC_MAXIOPB * sizeof(struct xd_iorq),
M_DEVBUF, M_WAITOK | M_ZERO);
xdc->reqs = kmem_zalloc(XDC_MAXIOPB * sizeof(struct xd_iorq),
KM_SLEEP);
/* init free list, iorq to iopb pointers, and non-zero fields in the
* iopb which never change. */

View File

@ -1,4 +1,4 @@
/* $NetBSD: xy.c,v 1.79 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: xy.c,v 1.80 2020/11/21 00:27:52 thorpej Exp $ */
/*
* Copyright (c) 1995 Charles D. Cranor
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.79 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.80 2020/11/21 00:27:52 thorpej Exp $");
#undef XYC_DEBUG /* full debug */
#undef XYC_DIAG /* extra sanity checks */
@ -64,7 +64,7 @@ __KERNEL_RCSID(0, "$NetBSD: xy.c,v 1.79 2019/11/10 21:16:33 chs Exp $");
#include <sys/buf.h>
#include <sys/bufq.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/device.h>
#include <sys/disklabel.h>
#include <sys/disk.h>
@ -390,8 +390,8 @@ xycattach(device_t parent, device_t self, void *aux)
xyc->iopbase = tmp;
xyc->dvmaiopb =
(struct xy_iopb *)dvma_kvtopa(xyc->iopbase, xyc->bustype);
xyc->reqs = malloc(XYC_MAXIOPB * sizeof(struct xy_iorq),
M_DEVBUF, M_WAITOK | M_ZERO);
xyc->reqs = kmem_zalloc(XYC_MAXIOPB * sizeof(struct xy_iorq),
KM_SLEEP);
/*
* init iorq to iopb pointers, and non-zero fields in the

View File

@ -1,4 +1,4 @@
/* $NetBSD: bus.c,v 1.23 2016/07/07 06:55:39 msaitoh Exp $ */
/* $NetBSD: bus.c,v 1.24 2020/11/21 00:27:52 thorpej Exp $ */
/*
* Copyright (c) 1982, 1986, 1990, 1993
@ -153,13 +153,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.23 2016/07/07 06:55:39 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.24 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/mbuf.h>
#include <uvm/uvm.h> /* XXX: not _extern ... need vm_map_create */
@ -174,6 +174,14 @@ __KERNEL_RCSID(0, "$NetBSD: bus.c,v 1.23 2016/07/07 06:55:39 msaitoh Exp $");
#include <sun68k/sun68k/control.h>
static size_t
_bus_dmamap_mapsize(int const nsegments)
{
KASSERT(nsegments > 0);
return sizeof(struct sun68k_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.
@ -184,7 +192,6 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
{
struct sun68k_bus_dmamap *map;
void *mapstore;
size_t mapsize;
/*
* Allocate and initialize the DMA map. The end of the map
@ -198,13 +205,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 sun68k_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 sun68k_bus_dmamap *)mapstore;
map->_dm_size = size;
map->_dm_segcnt = nsegments;
@ -234,7 +238,7 @@ _bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t map)
if (map->dm_mapsize != 0)
bus_dmamap_unload(t, map);
free(map, M_DMAMAP);
kmem_free(map, _bus_dmamap_mapsize(map->_dm_segcnt));
}
/*
@ -257,8 +261,8 @@ extern paddr_t avail_end;
low = avail_start;
high = avail_end;
if ((mlist = malloc(sizeof(*mlist), M_DEVBUF,
(flags & BUS_DMA_NOWAIT) ? M_NOWAIT : M_WAITOK)) == NULL)
if ((mlist = kmem_alloc(sizeof(*mlist),
(flags & BUS_DMA_NOWAIT) ? KM_NOSLEEP : KM_SLEEP)) == NULL)
return (ENOMEM);
/*
@ -267,7 +271,7 @@ extern paddr_t avail_end;
error = uvm_pglistalloc(size, low, high, 0, 0,
mlist, nsegs, (flags & BUS_DMA_NOWAIT) == 0);
if (error) {
free(mlist, M_DEVBUF);
kmem_free(mlist, sizeof(*mlist));
return (error);
}
@ -300,6 +304,7 @@ extern paddr_t avail_end;
void
_bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
{
struct pglist *mlist = segs[0]._ds_mlist;
if (nsegs != 1)
panic("bus_dmamem_free: nsegs = %d", nsegs);
@ -307,8 +312,8 @@ _bus_dmamem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs)
/*
* Return the list of physical pages back to the VM system.
*/
uvm_pglistfree(segs[0]._ds_mlist);
free(segs[0]._ds_mlist, M_DEVBUF);
uvm_pglistfree(mlist);
kmem_free(mlist, sizeof(*mlist));
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: isr.c,v 1.25 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: isr.c,v 1.26 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -34,12 +34,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: isr.c,v 1.25 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: isr.c,v 1.26 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/vmmeter.h>
#include <sys/cpu.h>
#include <sys/intr.h>
@ -147,7 +147,7 @@ isr_add_autovect(isr_func_t handler, void *arg, int level)
if ((level < 0) || (level >= NUM_LEVELS))
panic("isr_add: bad level=%d", level);
new_isr = malloc(sizeof(struct isr), M_DEVBUF, M_WAITOK);
new_isr = kmem_alloc(sizeof(struct isr), KM_SLEEP);
new_isr->isr_intr = handler;
new_isr->isr_arg = arg;
new_isr->isr_ipl = level;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vme_sun68k.c,v 1.16 2019/11/10 21:16:33 chs Exp $ */
/* $NetBSD: vme_sun68k.c,v 1.17 2020/11/21 00:27:52 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998, 2001 The NetBSD Foundation, Inc.
@ -30,13 +30,13 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vme_sun68k.c,v 1.16 2019/11/10 21:16:33 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: vme_sun68k.c,v 1.17 2020/11/21 00:27:52 thorpej Exp $");
#include <sys/param.h>
#include <sys/extent.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/malloc.h>
#include <sys/kmem.h>
#include <sys/errno.h>
#include <sys/proc.h>
@ -268,8 +268,7 @@ sun68k_vme_intr_map(void *cookie, int level, int vec, vme_intr_handle_t *ihp)
{
struct sun68k_vme_intr_handle *svih;
svih = malloc(sizeof(struct sun68k_vme_intr_handle),
M_DEVBUF, M_WAITOK);
svih = kmem_alloc(sizeof(struct sun68k_vme_intr_handle), KM_SLEEP);
svih->pri = level;
svih->vec = vec;
*ihp = svih;