Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/emips/emips malloc(9) -> kmem(9)



details:   https://anonhg.NetBSD.org/src/rev/408438dadfdb
branches:  trunk
changeset: 946240:408438dadfdb
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Nov 21 19:24:17 2020 +0000

description:
malloc(9) -> kmem(9)

diffstat:

 sys/arch/emips/emips/bus_dma.c |  23 ++++++++++++++---------
 1 files changed, 14 insertions(+), 9 deletions(-)

diffs (74 lines):

diff -r ddc6ae7ed7bb -r 408438dadfdb sys/arch/emips/emips/bus_dma.c
--- a/sys/arch/emips/emips/bus_dma.c    Sat Nov 21 19:21:49 2020 +0000
+++ b/sys/arch/emips/emips/bus_dma.c    Sat Nov 21 19:24:17 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_dma.c,v 1.4 2015/06/11 08:22:08 matt Exp $ */
+/*     $NetBSD: bus_dma.c,v 1.5 2020/11/21 19:24:17 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.4 2015/06/11 08:22:08 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.5 2020/11/21 19:24:17 thorpej Exp $");
 
 #include "opt_cputype.h"
 
@@ -39,6 +39,7 @@
 #include <sys/systm.h>
 #include <sys/mbuf.h>
 #include <sys/proc.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -87,6 +88,14 @@
 #endif
 }
 
+static size_t 
+_bus_dmamap_mapsize(int const nsegments)
+{       
+       KASSERT(nsegments > 0);
+       return sizeof(struct emips_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.
@@ -97,7 +106,6 @@
 {
        struct emips_bus_dmamap *map;
        void *mapstore;
-       size_t mapsize;
 
        /*
         * Allocate and initialize the DMA map.  The end of the map
@@ -111,13 +119,10 @@
         * The bus_dmamap_t includes one bus_dma_segment_t, hence
         * the (nsegments - 1).
         */
-       mapsize = sizeof(struct emips_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 emips_bus_dmamap *)mapstore;
        map->_dm_size = size;
        map->_dm_segcnt = nsegments;
@@ -141,7 +146,7 @@
 _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));
 }
 
 /*



Home | Main Index | Thread Index | Old Index