Module Name:    src
Committed By:   thorpej
Date:           Sat Nov 21 17:46:09 UTC 2020

Modified Files:
        src/sys/arch/playstation2/dev: if_smap.c ohci_sbus.c
        src/sys/arch/playstation2/playstation2: bus_dma.c bus_space.c

Log Message:
malloc(9) -> kmem(9)

XXX Audit use of KM_NOSLEEP here.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/playstation2/dev/if_smap.c
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/playstation2/dev/ohci_sbus.c
cvs rdiff -u -r1.22 -r1.23 src/sys/arch/playstation2/playstation2/bus_dma.c
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/playstation2/playstation2/bus_space.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/playstation2/dev/if_smap.c
diff -u src/sys/arch/playstation2/dev/if_smap.c:1.32 src/sys/arch/playstation2/dev/if_smap.c:1.33
--- src/sys/arch/playstation2/dev/if_smap.c:1.32	Wed Jan 29 05:32:04 2020
+++ src/sys/arch/playstation2/dev/if_smap.c	Sat Nov 21 17:46:08 2020
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: if_smap.c,v 
 #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_attach(struct device *parent, struc
 	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);
 

Index: src/sys/arch/playstation2/dev/ohci_sbus.c
diff -u src/sys/arch/playstation2/dev/ohci_sbus.c:1.13 src/sys/arch/playstation2/dev/ohci_sbus.c:1.14
--- src/sys/arch/playstation2/dev/ohci_sbus.c:1.13	Mon Jul 18 22:17:09 2016
+++ src/sys/arch/playstation2/dev/ohci_sbus.c	Sat Nov 21 17:46:08 2020
@@ -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 @@ _ohci_sbus_mem_alloc(bus_dma_tag_t t, bu
 	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 @@ _ohci_sbus_mem_alloc(bus_dma_tag_t t, bu
 	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 @@ _ohci_sbus_mem_free(bus_dma_tag_t t, bus
 			iopdma_free_buffer(&ds->ds_iopdma_seg);
 
 			LIST_REMOVE(ds, ds_link);
-			free(ds, M_DEVBUF);
+			kmem_intr_free(ds, sizeof(*ds));
 			return;
 		}
 	}

Index: src/sys/arch/playstation2/playstation2/bus_dma.c
diff -u src/sys/arch/playstation2/playstation2/bus_dma.c:1.22 src/sys/arch/playstation2/playstation2/bus_dma.c:1.23
--- src/sys/arch/playstation2/playstation2/bus_dma.c:1.22	Mon Mar 31 11:42:17 2014
+++ src/sys/arch/playstation2/playstation2/bus_dma.c	Sat Nov 21 17:46:09 2020
@@ -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 @@ struct playstation2_bus_dma_tag playstat
 	_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 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_
 {
 	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 @@ _bus_dmamap_create(bus_dma_tag_t t, bus_
 	 * 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 @@ 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));
 }
 
 

Index: src/sys/arch/playstation2/playstation2/bus_space.c
diff -u src/sys/arch/playstation2/playstation2/bus_space.c:1.10 src/sys/arch/playstation2/playstation2/bus_space.c:1.11
--- src/sys/arch/playstation2/playstation2/bus_space.c:1.10	Fri Jul  4 07:51:14 2014
+++ src/sys/arch/playstation2/playstation2/bus_space.c	Sat Nov 21 17:46:09 2020
@@ -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 @@ bus_space_create(bus_space_tag_t t, cons
 {
 	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 @@ bus_space_destroy(bus_space_tag_t t)
 	if (ex != 0)
 		extent_destroy(ex);
 
-	free(pbs, M_DEVBUF);
+	kmem_free(pbs, sizeof(*pbs));
 }
 
 void

Reply via email to