Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/playstation2 malloc(9) -> kmem(9)
details: https://anonhg.NetBSD.org/src/rev/684ec8297fe5
branches: trunk
changeset: 957200:684ec8297fe5
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat Nov 21 17:46:08 2020 +0000
description:
malloc(9) -> kmem(9)
XXX Audit use of KM_NOSLEEP here.
diffstat:
sys/arch/playstation2/dev/if_smap.c | 12 ++++++------
sys/arch/playstation2/dev/ohci_sbus.c | 11 ++++++-----
sys/arch/playstation2/playstation2/bus_dma.c | 24 ++++++++++++++----------
sys/arch/playstation2/playstation2/bus_space.c | 14 ++++++--------
4 files changed, 32 insertions(+), 29 deletions(-)
diffs (205 lines):
diff -r 11041274d03c -r 684ec8297fe5 sys/arch/playstation2/dev/if_smap.c
--- a/sys/arch/playstation2/dev/if_smap.c Sat Nov 21 17:44:40 2020 +0000
+++ b/sys/arch/playstation2/dev/if_smap.c Sat Nov 21 17:46:08 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_smap.c,v 1.32 2020/01/29 05:32:04 thorpej Exp $ */
+/* $NetBSD: if_smap.c,v 1.33 2020/11/21 17:46:08 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_smap.c,v 1.32 2020/01/29 05:32:04 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_smap.c,v 1.33 2020/11/21 17:46:08 thorpej Exp $");
#include "debug_playstation2.h"
@@ -42,6 +42,7 @@
#include <sys/ioctl.h>
#include <sys/rndsource.h>
#include <sys/socket.h>
+#include <sys/kmem.h>
#include <playstation2/ee/eevar.h>
@@ -192,10 +193,9 @@
smap_desc_init(sc);
/* allocate temporary buffer */
- txbuf = malloc(ETHER_MAX_LEN - ETHER_CRC_LEN + SMAP_FIFO_ALIGN + 16,
- M_DEVBUF, M_WAITOK);
- rxbuf = malloc(ETHER_MAX_LEN + SMAP_FIFO_ALIGN + 16,
- M_DEVBUF, M_WAITOK);
+ txbuf = kmem_alloc(ETHER_MAX_LEN - ETHER_CRC_LEN + SMAP_FIFO_ALIGN + 16,
+ KM_SLEEP);
+ rxbuf = kmem_alloc(ETHER_MAX_LEN + SMAP_FIFO_ALIGN + 16, KM_SLEEP);
sc->tx_buf = (u_int32_t *)ROUND16((vaddr_t)txbuf);
sc->rx_buf = (u_int32_t *)ROUND16((vaddr_t)rxbuf);
diff -r 11041274d03c -r 684ec8297fe5 sys/arch/playstation2/dev/ohci_sbus.c
--- a/sys/arch/playstation2/dev/ohci_sbus.c Sat Nov 21 17:44:40 2020 +0000
+++ b/sys/arch/playstation2/dev/ohci_sbus.c Sat Nov 21 17:46:08 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci_sbus.c,v 1.13 2016/07/18 22:17:09 maya Exp $ */
+/* $NetBSD: ohci_sbus.c,v 1.14 2020/11/21 17:46:08 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,9 +30,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci_sbus.c,v 1.13 2016/07/18 22:17:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci_sbus.c,v 1.14 2020/11/21 17:46:08 thorpej Exp $");
#include <sys/param.h>
+#include <sys/kmem.h>
/* bus_dma */
#include <sys/mbuf.h>
@@ -171,7 +172,7 @@
int error;
KDASSERT(sc);
- ds = malloc(sizeof(struct ohci_dma_segment), M_DEVBUF, M_NOWAIT);
+ ds = kmem_intr_alloc(sizeof(struct ohci_dma_segment), KM_NOSLEEP);
if (ds == NULL)
return 1;
/*
@@ -181,7 +182,7 @@
error = iopdma_allocate_buffer(iopdma_seg, size);
if (error) {
- free(ds, M_DEVBUF);
+ kmem_intr_free(ds, sizeof(*ds));
return 1;
}
@@ -209,7 +210,7 @@
iopdma_free_buffer(&ds->ds_iopdma_seg);
LIST_REMOVE(ds, ds_link);
- free(ds, M_DEVBUF);
+ kmem_intr_free(ds, sizeof(*ds));
return;
}
}
diff -r 11041274d03c -r 684ec8297fe5 sys/arch/playstation2/playstation2/bus_dma.c
--- a/sys/arch/playstation2/playstation2/bus_dma.c Sat Nov 21 17:44:40 2020 +0000
+++ b/sys/arch/playstation2/playstation2/bus_dma.c Sat Nov 21 17:46:08 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_dma.c,v 1.22 2014/03/31 11:42:17 martin Exp $ */
+/* $NetBSD: bus_dma.c,v 1.23 2020/11/21 17:46:09 thorpej Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -31,10 +31,10 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.22 2014/03/31 11:42:17 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.23 2020/11/21 17:46:09 thorpej Exp $");
#include <sys/param.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
#include <sys/mbuf.h>
#include <sys/proc.h>
@@ -69,6 +69,14 @@
_bus_dmamem_mmap,
};
+static size_t
+_bus_dmamap_mapsize(int const nsegments)
+{
+ KASSERT(nsegments > 0);
+ return sizeof(struct playstation2_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.
@@ -79,7 +87,6 @@
{
struct playstation2_bus_dmamap *map;
void *mapstore;
- size_t mapsize;
/*
* Allocate and initialize the DMA map. The end of the map
@@ -93,13 +100,10 @@
* The bus_dmamap_t includes one bus_dma_segment_t, hence
* the (nsegments - 1).
*/
- mapsize = sizeof(struct playstation2_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 playstation2_bus_dmamap *)mapstore;
map->_dm_size = size;
map->_dm_segcnt = nsegments;
@@ -122,7 +126,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));
}
diff -r 11041274d03c -r 684ec8297fe5 sys/arch/playstation2/playstation2/bus_space.c
--- a/sys/arch/playstation2/playstation2/bus_space.c Sat Nov 21 17:44:40 2020 +0000
+++ b/sys/arch/playstation2/playstation2/bus_space.c Sat Nov 21 17:46:08 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bus_space.c,v 1.10 2014/07/04 07:51:14 martin Exp $ */
+/* $NetBSD: bus_space.c,v 1.11 2020/11/21 17:46:09 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -27,11 +27,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.10 2014/07/04 07:51:14 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.11 2020/11/21 17:46:09 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/malloc.h>
+#include <sys/kmem.h>
#include <sys/extent.h>
#define _PLAYSTATION2_BUS_SPACE_PRIVATE
@@ -151,12 +151,10 @@
{
struct playstation2_bus_space *pbs = (void *)__UNCONST(t);
- if (pbs == 0)
- pbs = malloc(sizeof(*pbs), M_DEVBUF, M_NOWAIT);
+ if (pbs == NULL)
+ pbs = kmem_zalloc(sizeof(*pbs), KM_NOSLEEP);
KDASSERT(pbs);
- memset(pbs, 0, sizeof(*pbs));
-
/* set default method */
*pbs = _default_bus_space;
pbs->pbs_cookie = pbs;
@@ -185,7 +183,7 @@
if (ex != 0)
extent_destroy(ex);
- free(pbs, M_DEVBUF);
+ kmem_free(pbs, sizeof(*pbs));
}
void
Home |
Main Index |
Thread Index |
Old Index