Use kmem(9) instead of malloc(9).
This commit is contained in:
parent
c6547b8190
commit
f8bb8301ce
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: firewire.c,v 1.30 2010/04/06 10:45:15 reinoud Exp $ */
|
||||
/* $NetBSD: firewire.c,v 1.31 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2003 Hidetoshi Shimokawa
|
||||
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: firewire.c,v 1.30 2010/04/06 10:45:15 reinoud Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: firewire.c,v 1.31 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
@ -48,7 +48,7 @@ __KERNEL_RCSID(0, "$NetBSD: firewire.c,v 1.30 2010/04/06 10:45:15 reinoud Exp $"
|
||||
#include <sys/errno.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kthread.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/systm.h>
|
||||
@ -217,28 +217,24 @@ firewireattach(device_t parent, device_t self, void *aux)
|
||||
if (fc->nisodma > FWMAXNDMA)
|
||||
fc->nisodma = FWMAXNDMA;
|
||||
|
||||
fc->crom_src_buf =
|
||||
(struct crom_src_buf *)malloc(sizeof(struct crom_src_buf),
|
||||
M_FW, M_NOWAIT | M_ZERO);
|
||||
fc->crom_src_buf = kmem_zalloc(sizeof(struct crom_src_buf), KM_NOSLEEP);
|
||||
if (fc->crom_src_buf == NULL) {
|
||||
aprint_error_dev(fc->bdev, "Malloc Failure crom src buff\n");
|
||||
aprint_error_dev(fc->bdev,
|
||||
"kmem alloc failure crom src buff\n");
|
||||
return;
|
||||
}
|
||||
fc->topology_map =
|
||||
(struct fw_topology_map *)malloc(sizeof(struct fw_topology_map),
|
||||
M_FW, M_NOWAIT | M_ZERO);
|
||||
kmem_zalloc(sizeof(struct fw_topology_map), KM_NOSLEEP);
|
||||
if (fc->topology_map == NULL) {
|
||||
aprint_error_dev(fc->dev, "Malloc Failure topology map\n");
|
||||
free(fc->crom_src_buf, M_FW);
|
||||
kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf));
|
||||
return;
|
||||
}
|
||||
fc->speed_map =
|
||||
(struct fw_speed_map *)malloc(sizeof(struct fw_speed_map),
|
||||
M_FW, M_NOWAIT | M_ZERO);
|
||||
fc->speed_map = kmem_zalloc(sizeof(struct fw_speed_map), KM_NOSLEEP);
|
||||
if (fc->speed_map == NULL) {
|
||||
aprint_error_dev(fc->dev, "Malloc Failure speed map\n");
|
||||
free(fc->crom_src_buf, M_FW);
|
||||
free(fc->topology_map, M_FW);
|
||||
kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf));
|
||||
kmem_free(fc->topology_map, sizeof(struct fw_topology_map));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -262,7 +258,7 @@ firewireattach(device_t parent, device_t self, void *aux)
|
||||
aprint_error_dev(self, "kthread_create failed\n");
|
||||
config_pending_incr();
|
||||
|
||||
devlist = malloc(sizeof(struct firewire_dev_list), M_DEVBUF, M_NOWAIT);
|
||||
devlist = kmem_alloc(sizeof(struct firewire_dev_list), KM_NOSLEEP);
|
||||
if (devlist == NULL) {
|
||||
aprint_error_dev(self, "device list allocation failed\n");
|
||||
return;
|
||||
@ -273,7 +269,7 @@ firewireattach(device_t parent, device_t self, void *aux)
|
||||
faa.fwdev = NULL;
|
||||
devlist->dev = config_found(sc->dev, &faa, firewire_print);
|
||||
if (devlist->dev == NULL)
|
||||
free(devlist, M_DEVBUF);
|
||||
kmem_free(devlist, sizeof(struct firewire_dev_list));
|
||||
else
|
||||
SLIST_INSERT_HEAD(&sc->devlist, devlist, link);
|
||||
|
||||
@ -315,7 +311,7 @@ firewiredetach(device_t self, int flags)
|
||||
if ((err = config_detach(devlist->dev, flags)) != 0)
|
||||
return err;
|
||||
SLIST_REMOVE(&sc->devlist, devlist, firewire_dev_list, link);
|
||||
free(devlist, M_DEVBUF);
|
||||
kmem_free(devlist, sizeof(struct firewire_dev_list));
|
||||
}
|
||||
|
||||
callout_stop(&fc->timeout_callout);
|
||||
@ -326,11 +322,11 @@ firewiredetach(device_t self, int flags)
|
||||
for (fwdev = STAILQ_FIRST(&fc->devices); fwdev != NULL;
|
||||
fwdev = fwdev_next) {
|
||||
fwdev_next = STAILQ_NEXT(fwdev, link);
|
||||
free(fwdev, M_FW);
|
||||
kmem_free(fwdev, sizeof(struct fw_device));
|
||||
}
|
||||
free(fc->topology_map, M_FW);
|
||||
free(fc->speed_map, M_FW);
|
||||
free(fc->crom_src_buf, M_FW);
|
||||
kmem_free(fc->topology_map, sizeof(struct fw_topology_map));
|
||||
kmem_free(fc->speed_map, sizeof(struct fw_speed_map));
|
||||
kmem_free(fc->crom_src_buf, sizeof(struct crom_src_buf));
|
||||
|
||||
cv_destroy(&fc->fc_cv);
|
||||
mutex_destroy(&fc->wait_lock);
|
||||
@ -586,7 +582,7 @@ fw_busreset(struct firewire_comm *fc, uint32_t new_status)
|
||||
* Configuration ROM.
|
||||
*/
|
||||
#define FW_MAX_GENERATION 0xF
|
||||
newrom = malloc(CROMSIZE, M_FW, M_NOWAIT | M_ZERO);
|
||||
newrom = kmem_zalloc(CROMSIZE, KM_NOSLEEP);
|
||||
src = &fc->crom_src_buf->src;
|
||||
crom_load(src, newrom, CROMSIZE);
|
||||
if (memcmp(newrom, fc->config_rom, CROMSIZE) != 0) {
|
||||
@ -594,7 +590,7 @@ fw_busreset(struct firewire_comm *fc, uint32_t new_status)
|
||||
src->businfo.generation = FW_GENERATION_CHANGEABLE;
|
||||
memcpy((void *)fc->config_rom, newrom, CROMSIZE);
|
||||
}
|
||||
free(newrom, M_FW);
|
||||
kmem_free(newrom, CROMSIZE);
|
||||
}
|
||||
|
||||
/* Call once after reboot */
|
||||
@ -810,7 +806,7 @@ fw_xfer_alloc(struct malloc_type *type)
|
||||
{
|
||||
struct fw_xfer *xfer;
|
||||
|
||||
xfer = malloc(sizeof(struct fw_xfer), type, M_NOWAIT | M_ZERO);
|
||||
xfer = kmem_zalloc(sizeof(struct fw_xfer), KM_NOSLEEP);
|
||||
if (xfer == NULL)
|
||||
return xfer;
|
||||
|
||||
@ -831,17 +827,17 @@ fw_xfer_alloc_buf(struct malloc_type *type, int send_len, int recv_len)
|
||||
xfer->send.pay_len = send_len;
|
||||
xfer->recv.pay_len = recv_len;
|
||||
if (send_len > 0) {
|
||||
xfer->send.payload = malloc(send_len, type, M_NOWAIT | M_ZERO);
|
||||
xfer->send.payload = kmem_zalloc(send_len, KM_NOSLEEP);
|
||||
if (xfer->send.payload == NULL) {
|
||||
fw_xfer_free(xfer);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (recv_len > 0) {
|
||||
xfer->recv.payload = malloc(recv_len, type, M_NOWAIT);
|
||||
xfer->recv.payload = kmem_alloc(recv_len, KM_NOSLEEP);
|
||||
if (xfer->recv.payload == NULL) {
|
||||
if (xfer->send.payload != NULL)
|
||||
free(xfer->send.payload, type);
|
||||
kmem_free(xfer->send.payload, send_len);
|
||||
fw_xfer_free(xfer);
|
||||
return NULL;
|
||||
}
|
||||
@ -912,7 +908,7 @@ fw_xfer_free(struct fw_xfer* xfer)
|
||||
}
|
||||
fw_xfer_unload(xfer);
|
||||
cv_destroy(&xfer->cv);
|
||||
free(xfer, xfer->malloc);
|
||||
kmem_free(xfer, sizeof(struct fw_xfer));
|
||||
}
|
||||
|
||||
void
|
||||
@ -924,14 +920,12 @@ fw_xfer_free_buf(struct fw_xfer* xfer)
|
||||
return;
|
||||
}
|
||||
fw_xfer_unload(xfer);
|
||||
if (xfer->send.payload != NULL) {
|
||||
free(xfer->send.payload, xfer->malloc);
|
||||
}
|
||||
if (xfer->recv.payload != NULL) {
|
||||
free(xfer->recv.payload, xfer->malloc);
|
||||
}
|
||||
if (xfer->send.payload != NULL)
|
||||
kmem_free(xfer->send.payload, xfer->send.pay_len);
|
||||
if (xfer->recv.payload != NULL)
|
||||
kmem_free(xfer->recv.payload, xfer->recv.pay_len);
|
||||
cv_destroy(&xfer->cv);
|
||||
free(xfer, xfer->malloc);
|
||||
kmem_free(xfer, sizeof(struct fw_xfer));
|
||||
}
|
||||
|
||||
void
|
||||
@ -1769,8 +1763,7 @@ fw_explore_node(struct fw_device *dfwdev)
|
||||
mutex_exit(&fc->fc_mtx);
|
||||
if (fwdev == NULL) {
|
||||
/* new device */
|
||||
fwdev =
|
||||
malloc(sizeof(struct fw_device), M_FW, M_NOWAIT | M_ZERO);
|
||||
fwdev = kmem_zalloc(sizeof(struct fw_device), KM_NOSLEEP);
|
||||
if (fwdev == NULL) {
|
||||
if (firewire_debug)
|
||||
printf("node%d: no memory\n", node);
|
||||
@ -1887,7 +1880,7 @@ fw_explore(struct firewire_comm *fc)
|
||||
char nodes[63];
|
||||
|
||||
todo = 0;
|
||||
dfwdev = malloc(sizeof(*dfwdev), M_TEMP, M_NOWAIT);
|
||||
dfwdev = kmem_alloc(sizeof(struct fw_device), KM_NOSLEEP);
|
||||
if (dfwdev == NULL)
|
||||
return;
|
||||
/* setup dummy fwdev */
|
||||
@ -1928,7 +1921,7 @@ fw_explore(struct firewire_comm *fc)
|
||||
}
|
||||
todo = todo2;
|
||||
}
|
||||
free(dfwdev, M_TEMP);
|
||||
kmem_free(dfwdev, sizeof(struct fw_device));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -1982,8 +1975,8 @@ fw_attach_dev(struct firewire_comm *fc)
|
||||
mutex_exit(&fc->fc_mtx);
|
||||
switch (fwdev->status) {
|
||||
case FWDEVNEW:
|
||||
devlist = malloc(sizeof(struct firewire_dev_list),
|
||||
M_DEVBUF, M_NOWAIT);
|
||||
devlist = kmem_alloc(sizeof(struct firewire_dev_list),
|
||||
KM_NOSLEEP);
|
||||
if (devlist == NULL) {
|
||||
aprint_error_dev(fc->bdev,
|
||||
"memory allocation failed\n");
|
||||
@ -1997,7 +1990,8 @@ fw_attach_dev(struct firewire_comm *fc)
|
||||
fwdev->sbp = config_found_sm_loc(sc->dev, "ieee1394if",
|
||||
locs, &fwa, firewire_print, config_stdsubmatch);
|
||||
if (fwdev->sbp == NULL) {
|
||||
free(devlist, M_DEVBUF);
|
||||
kmem_free(devlist,
|
||||
sizeof(struct firewire_dev_list));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2058,13 +2052,13 @@ fw_attach_dev(struct firewire_comm *fc)
|
||||
|
||||
SLIST_REMOVE(&sc->devlist, devlist, firewire_dev_list,
|
||||
link);
|
||||
free(devlist, M_DEVBUF);
|
||||
kmem_free(devlist, sizeof(struct firewire_dev_list));
|
||||
|
||||
if (config_detach(fwdev->sbp, DETACH_FORCE) != 0)
|
||||
return;
|
||||
|
||||
STAILQ_REMOVE(&fc->devices, fwdev, fw_device, link);
|
||||
free(fwdev, M_FW);
|
||||
kmem_free(fwdev, sizeof(struct fw_device));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fwdev.c,v 1.19 2010/04/29 06:53:48 kiyohara Exp $ */
|
||||
/* $NetBSD: fwdev.c,v 1.20 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2003 Hidetoshi Shimokawa
|
||||
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwdev.c,v 1.19 2010/04/29 06:53:48 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwdev.c,v 1.20 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/device.h>
|
||||
@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: fwdev.c,v 1.19 2010/04/29 06:53:48 kiyohara Exp $");
|
||||
#include <sys/bus.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/proc.h>
|
||||
@ -91,7 +91,7 @@ struct fw_drv1 {
|
||||
|
||||
static int fwdev_allocbuf(struct firewire_comm *, struct fw_xferq *,
|
||||
struct fw_bufspec *);
|
||||
static int fwdev_freebuf(struct fw_xferq *);
|
||||
static int fwdev_freebuf(struct fw_xferq *, struct fw_bufspec *);
|
||||
static int fw_read_async(struct fw_drv1 *, struct uio *, int);
|
||||
static int fw_write_async(struct fw_drv1 *, struct uio *, int);
|
||||
static void fw_hand(struct fw_xfer *);
|
||||
@ -120,7 +120,7 @@ fw_open(dev_t dev, int flags, int fmt, struct lwp *td)
|
||||
sc->si_drv1 = (void *)-1;
|
||||
mutex_exit(&sc->fc->fc_mtx);
|
||||
|
||||
sc->si_drv1 = malloc(sizeof(struct fw_drv1), M_FW, M_WAITOK | M_ZERO);
|
||||
sc->si_drv1 = kmem_zalloc(sizeof(struct fw_drv1), KM_SLEEP);
|
||||
if (sc->si_drv1 == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@ -170,7 +170,7 @@ fw_close(dev_t dev, int flags, int fmt, struct lwp *td)
|
||||
fc->irx_disable(fc, ir->dmach);
|
||||
}
|
||||
/* free extbuf */
|
||||
fwdev_freebuf(ir);
|
||||
fwdev_freebuf(ir, &d->bufreq.rx);
|
||||
/* drain receiving buffer */
|
||||
for (xfer = STAILQ_FIRST(&ir->q); xfer != NULL;
|
||||
xfer = STAILQ_FIRST(&ir->q)) {
|
||||
@ -195,12 +195,12 @@ fw_close(dev_t dev, int flags, int fmt, struct lwp *td)
|
||||
fc->itx_disable(fc, it->dmach);
|
||||
}
|
||||
/* free extbuf */
|
||||
fwdev_freebuf(it);
|
||||
fwdev_freebuf(it, &d->bufreq.tx);
|
||||
it->flag &=
|
||||
~(FWXFERQ_OPEN | FWXFERQ_MODEMASK | FWXFERQ_CHTAGMASK);
|
||||
d->it = NULL;
|
||||
}
|
||||
free(sc->si_drv1, M_FW);
|
||||
kmem_free(sc->si_drv1, sizeof(struct fw_drv1));
|
||||
sc->si_drv1 = NULL;
|
||||
|
||||
return err;
|
||||
@ -577,8 +577,8 @@ out:
|
||||
err = EINVAL;
|
||||
break;
|
||||
}
|
||||
fwb = (struct fw_bind *)malloc(sizeof(struct fw_bind),
|
||||
M_FW, M_WAITOK);
|
||||
fwb = (struct fw_bind *)kmem_alloc(sizeof(struct fw_bind),
|
||||
KM_SLEEP);
|
||||
if (fwb == NULL) {
|
||||
err = ENOMEM;
|
||||
break;
|
||||
@ -635,7 +635,7 @@ out:
|
||||
break;
|
||||
}
|
||||
/* myself */
|
||||
ptr = malloc(CROMSIZE, M_FW, M_WAITOK);
|
||||
ptr = kmem_alloc(CROMSIZE, KM_SLEEP);
|
||||
len = CROMSIZE;
|
||||
for (i = 0; i < CROMSIZE/4; i++)
|
||||
((uint32_t *)ptr)[i] = ntohl(fc->config_rom[i]);
|
||||
@ -735,8 +735,7 @@ fwdev_allocbuf(struct firewire_comm *fc, struct fw_xferq *q,
|
||||
return EBUSY;
|
||||
|
||||
q->bulkxfer =
|
||||
(struct fw_bulkxfer *)malloc(sizeof(struct fw_bulkxfer) * b->nchunk,
|
||||
M_FW, M_WAITOK);
|
||||
kmem_alloc(sizeof(struct fw_bulkxfer) * b->nchunk, KM_SLEEP);
|
||||
if (q->bulkxfer == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
@ -745,7 +744,7 @@ fwdev_allocbuf(struct firewire_comm *fc, struct fw_xferq *q,
|
||||
b->nchunk * b->npacket, BUS_DMA_WAITOK);
|
||||
|
||||
if (q->buf == NULL) {
|
||||
free(q->bulkxfer, M_FW);
|
||||
kmem_free(q->bulkxfer, sizeof(struct fw_bulkxfer) * b->nchunk);
|
||||
q->bulkxfer = NULL;
|
||||
return ENOMEM;
|
||||
}
|
||||
@ -773,14 +772,14 @@ fwdev_allocbuf(struct firewire_comm *fc, struct fw_xferq *q,
|
||||
}
|
||||
|
||||
static int
|
||||
fwdev_freebuf(struct fw_xferq *q)
|
||||
fwdev_freebuf(struct fw_xferq *q, struct fw_bufspec *b)
|
||||
{
|
||||
|
||||
if (q->flag & FWXFERQ_EXTBUF) {
|
||||
if (q->buf != NULL)
|
||||
fwdma_free_multiseg(q->buf);
|
||||
q->buf = NULL;
|
||||
free(q->bulkxfer, M_FW);
|
||||
kmem_free(q->bulkxfer, sizeof(struct fw_bulkxfer) * b->nchunk);
|
||||
q->bulkxfer = NULL;
|
||||
q->flag &= ~FWXFERQ_EXTBUF;
|
||||
q->psize = 0;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fwdma.c,v 1.14 2010/04/29 06:56:00 kiyohara Exp $ */
|
||||
/* $NetBSD: fwdma.c,v 1.15 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2003
|
||||
* Hidetoshi Shimokawa. All rights reserved.
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwdma.c,v 1.14 2010/04/29 06:56:00 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwdma.c,v 1.15 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
#if defined(__FreeBSD__)
|
||||
__FBSDID("$FreeBSD: src/sys/dev/firewire/fwdma.c,v 1.9 2007/06/06 14:31:36 simokawa Exp $");
|
||||
#endif
|
||||
@ -46,7 +46,7 @@ __FBSDID("$FreeBSD: src/sys/dev/firewire/fwdma.c,v 1.9 2007/06/06 14:31:36 simok
|
||||
#include <sys/systm.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include <machine/vmparam.h>
|
||||
@ -155,9 +155,9 @@ fwdma_malloc_multiseg(struct firewire_comm *fc, int alignment, int esize, int n,
|
||||
}
|
||||
size = sizeof(struct fwdma_alloc_multi) +
|
||||
sizeof(struct fwdma_seg) * nseg;
|
||||
am = (struct fwdma_alloc_multi *)malloc(size, M_FW, M_WAITOK | M_ZERO);
|
||||
am = kmem_zalloc(size, KM_SLEEP);
|
||||
if (am == NULL) {
|
||||
aprint_error_dev(fc->dev, "malloc failed\n");
|
||||
aprint_error_dev(fc->dev, "kmem alloc failed\n");
|
||||
return NULL;
|
||||
}
|
||||
am->ssize = ssize;
|
||||
@ -184,8 +184,11 @@ void
|
||||
fwdma_free_multiseg(struct fwdma_alloc_multi *am)
|
||||
{
|
||||
struct fwdma_seg *seg;
|
||||
int nseg;
|
||||
|
||||
nseg = am->nseg;
|
||||
for (seg = am->seg; am->nseg--; seg++)
|
||||
fwdma_free(am->dma_tag, seg->dma_map, seg->v_addr);
|
||||
free(am, M_FW);
|
||||
kmem_free(am,
|
||||
sizeof(struct fwdma_alloc_multi) + sizeof(struct fwdma_seg) * nseg);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fwmem.c,v 1.12 2010/03/29 03:05:27 kiyohara Exp $ */
|
||||
/* $NetBSD: fwmem.c,v 1.13 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2002-2003
|
||||
* Hidetoshi Shimokawa. All rights reserved.
|
||||
@ -35,7 +35,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwmem.c,v 1.12 2010/03/29 03:05:27 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwmem.c,v 1.13 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/device.h>
|
||||
@ -44,7 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: fwmem.c,v 1.12 2010/03/29 03:05:27 kiyohara Exp $");
|
||||
#include <sys/bus.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <dev/ieee1394/firewire.h>
|
||||
@ -185,9 +185,7 @@ fwmem_open(dev_t dev, int flags, int fmt, struct lwp *td)
|
||||
fms = (struct fwmem_softc *)sc->si_drv1;
|
||||
fms->refcount++;
|
||||
} else {
|
||||
sc->si_drv1 = (void *)-1;
|
||||
sc->si_drv1 = malloc(sizeof(struct fwmem_softc),
|
||||
M_FWMEM, M_WAITOK);
|
||||
sc->si_drv1 = kmem_alloc(sizeof(struct fwmem_softc), KM_SLEEP);
|
||||
if (sc->si_drv1 == NULL)
|
||||
return ENOMEM;
|
||||
fms = (struct fwmem_softc *)sc->si_drv1;
|
||||
@ -225,7 +223,7 @@ fwmem_close(dev_t dev, int flags, int fmt, struct lwp *td)
|
||||
STAILQ_REMOVE_HEAD(&fms->xferlist, link);
|
||||
fw_xfer_free(xfer);
|
||||
}
|
||||
free(sc->si_drv1, M_FW);
|
||||
kmem_free(sc->si_drv1, sizeof(struct fwmem_softc));
|
||||
sc->si_drv1 = NULL;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fwohci.c,v 1.125 2010/04/29 06:53:13 kiyohara Exp $ */
|
||||
/* $NetBSD: fwohci.c,v 1.126 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 Hidetoshi Shimokawa
|
||||
@ -37,7 +37,7 @@
|
||||
*
|
||||
*/
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwohci.c,v 1.125 2010/04/29 06:53:13 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: fwohci.c,v 1.126 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/atomic.h>
|
||||
@ -46,7 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: fwohci.c,v 1.125 2010/04/29 06:53:13 kiyohara Exp $"
|
||||
#include <sys/errno.h>
|
||||
#include <sys/conf.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/reboot.h>
|
||||
@ -1703,10 +1703,10 @@ fwohci_db_free(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
||||
db_tr->buf = NULL;
|
||||
}
|
||||
}
|
||||
dbch->ndb = 0;
|
||||
db_tr = STAILQ_FIRST(&dbch->db_trq);
|
||||
fwdma_free_multiseg(dbch->am);
|
||||
free(db_tr, M_FW);
|
||||
kmem_free(db_tr, sizeof(struct fwohcidb_tr) * dbch->ndb);
|
||||
dbch->ndb = 0;
|
||||
STAILQ_INIT(&dbch->db_trq);
|
||||
dbch->flags &= ~FWOHCI_DBCH_INIT;
|
||||
seldestroy(&dbch->xferq.rsel);
|
||||
@ -1726,9 +1726,9 @@ fwohci_db_init(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
||||
/* allocate DB entries and attach one to each DMA channels */
|
||||
/* DB entry must start at 16 bytes bounary. */
|
||||
STAILQ_INIT(&dbch->db_trq);
|
||||
db_tr = (struct fwohcidb_tr *)malloc(db_tr_sz, M_FW, M_WAITOK | M_ZERO);
|
||||
db_tr = kmem_zalloc(db_tr_sz, KM_SLEEP);
|
||||
if (db_tr == NULL) {
|
||||
aprint_error_dev(fc->dev, "malloc(1) failed\n");
|
||||
aprint_error_dev(fc->dev, "kmem alloc failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1743,7 +1743,7 @@ fwohci_db_init(struct fwohci_softc *sc, struct fwohci_dbch *dbch)
|
||||
#endif
|
||||
if (dbch->am == NULL) {
|
||||
aprint_error_dev(fc->dev, "fwdma_malloc_multiseg failed\n");
|
||||
free(db_tr, M_FW);
|
||||
kmem_free(db_tr, sizeof(struct fwohcidb_tr) * dbch->ndb);
|
||||
return;
|
||||
}
|
||||
/* Attach DB to DMA ch. */
|
||||
@ -2140,9 +2140,9 @@ fwohci_task_sid(struct fwohci_softc *sc)
|
||||
return;
|
||||
}
|
||||
plen -= 4; /* chop control info */
|
||||
buf = (uint32_t *)malloc(OHCI_SIDSIZE, M_FW, M_NOWAIT);
|
||||
buf = kmem_alloc(OHCI_SIDSIZE, KM_NOSLEEP);
|
||||
if (buf == NULL) {
|
||||
aprint_error_dev(fc->dev, "malloc failed\n");
|
||||
aprint_error_dev(fc->dev, "kmem alloc failed\n");
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < plen / 4; i++)
|
||||
@ -2156,7 +2156,7 @@ fwohci_task_sid(struct fwohci_softc *sc)
|
||||
fw_drain_txq(fc);
|
||||
#endif
|
||||
fw_sidrcv(fc, buf, plen);
|
||||
free(buf, M_FW);
|
||||
kmem_free(buf, OHCI_SIDSIZE);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: if_fwip.c,v 1.22 2010/03/29 03:05:28 kiyohara Exp $ */
|
||||
/* $NetBSD: if_fwip.c,v 1.23 2010/05/10 12:17:32 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2004
|
||||
* Doug Rabson
|
||||
@ -38,13 +38,13 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.22 2010/03/29 03:05:28 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: if_fwip.c,v 1.23 2010/05/10 12:17:32 kiyohara Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/bus.h>
|
||||
#include <sys/device.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/mbuf.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/sysctl.h>
|
||||
@ -344,6 +344,8 @@ fwip_init(struct ifnet *ifp)
|
||||
|
||||
fc = sc->sc_fd.fc;
|
||||
if (sc->sc_dma_ch < 0) {
|
||||
const size_t size = sizeof(struct fw_bulkxfer) * rx_queue_len;
|
||||
|
||||
sc->sc_dma_ch = fw_open_isodma(fc, /* tx */0);
|
||||
if (sc->sc_dma_ch < 0)
|
||||
return ENXIO;
|
||||
@ -360,11 +362,9 @@ fwip_init(struct ifnet *ifp)
|
||||
xferq->psize = MCLBYTES;
|
||||
xferq->queued = 0;
|
||||
xferq->buf = NULL;
|
||||
xferq->bulkxfer = (struct fw_bulkxfer *) malloc(
|
||||
sizeof(struct fw_bulkxfer) * xferq->bnchunk,
|
||||
M_FWIP, M_WAITOK);
|
||||
xferq->bulkxfer = kmem_alloc(size, KM_SLEEP);
|
||||
if (xferq->bulkxfer == NULL) {
|
||||
aprint_error_ifnet(ifp, "if_fwip: malloc failed\n");
|
||||
aprint_error_ifnet(ifp, "if_fwip: kmem alloc failed\n");
|
||||
return ENOMEM;
|
||||
}
|
||||
STAILQ_INIT(&xferq->stvalid);
|
||||
@ -455,7 +455,8 @@ fwip_stop(struct ifnet *ifp, int disable)
|
||||
|
||||
for (i = 0; i < xferq->bnchunk; i++)
|
||||
m_freem(xferq->bulkxfer[i].mbuf);
|
||||
free(xferq->bulkxfer, M_FWIP);
|
||||
kmem_free(xferq->bulkxfer,
|
||||
sizeof(struct fw_bulkxfer) * xferq->bnchunk);
|
||||
|
||||
fw_bindremove(fc, &sc->sc_fwb);
|
||||
for (xfer = STAILQ_FIRST(&sc->sc_fwb.xferlist); xfer != NULL;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: sbp.c,v 1.30 2010/04/29 06:51:26 kiyohara Exp $ */
|
||||
/* $NetBSD: sbp.c,v 1.31 2010/05/10 12:17:33 kiyohara Exp $ */
|
||||
/*-
|
||||
* Copyright (c) 2003 Hidetoshi Shimokawa
|
||||
* Copyright (c) 1998-2002 Katsushi Kobayashi and Hidetoshi Shimokawa
|
||||
@ -37,7 +37,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: sbp.c,v 1.30 2010/04/29 06:51:26 kiyohara Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sbp.c,v 1.31 2010/05/10 12:17:33 kiyohara Exp $");
|
||||
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -47,8 +47,8 @@ __KERNEL_RCSID(0, "$NetBSD: sbp.c,v 1.30 2010/04/29 06:51:26 kiyohara Exp $");
|
||||
#include <sys/callout.h>
|
||||
#include <sys/condvar.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/kmem.h>
|
||||
#include <sys/kthread.h>
|
||||
#include <sys/malloc.h>
|
||||
#include <sys/mutex.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/sysctl.h>
|
||||
@ -708,12 +708,14 @@ END_DEBUG
|
||||
|
||||
/* Reallocate */
|
||||
if (maxlun != target->num_lun) {
|
||||
newluns = (struct sbp_dev **) realloc(target->luns,
|
||||
sizeof(struct sbp_dev *) * maxlun,
|
||||
M_SBP, M_NOWAIT | M_ZERO);
|
||||
const int sbp_dev_p_sz = sizeof(struct sbp_dev *);
|
||||
|
||||
if (newluns == NULL) {
|
||||
aprint_error_dev(sc->sc_fd.dev, "realloc failed\n");
|
||||
newluns = kmem_alloc(sbp_dev_p_sz * maxlun, KM_NOSLEEP);
|
||||
if (newluns != NULL)
|
||||
memcpy(*newluns, target->luns,
|
||||
sizeof(struct sbp_dev *) * target->num_lun);
|
||||
else {
|
||||
aprint_error_dev(sc->sc_fd.dev, "kmem alloc failed\n");
|
||||
newluns = target->luns;
|
||||
maxlun = target->num_lun;
|
||||
}
|
||||
@ -722,12 +724,9 @@ END_DEBUG
|
||||
* We must zero the extended region for the case
|
||||
* realloc() doesn't allocate new buffer.
|
||||
*/
|
||||
if (maxlun > target->num_lun) {
|
||||
const int sbp_dev_p_sz = sizeof(struct sbp_dev *);
|
||||
|
||||
if (maxlun > target->num_lun)
|
||||
memset(&newluns[target->num_lun], 0,
|
||||
sbp_dev_p_sz * (maxlun - target->num_lun));
|
||||
}
|
||||
|
||||
target->luns = newluns;
|
||||
target->num_lun = maxlun;
|
||||
@ -749,11 +748,10 @@ END_DEBUG
|
||||
|
||||
sdev = target->luns[lun];
|
||||
if (sdev == NULL) {
|
||||
sdev = malloc(sizeof(struct sbp_dev),
|
||||
M_SBP, M_NOWAIT | M_ZERO);
|
||||
sdev = kmem_zalloc(sizeof(struct sbp_dev), KM_NOSLEEP);
|
||||
if (sdev == NULL) {
|
||||
aprint_error_dev(sc->sc_fd.dev,
|
||||
"malloc failed\n");
|
||||
"kmem alloc failed\n");
|
||||
goto next;
|
||||
}
|
||||
target->luns[lun] = sdev;
|
||||
@ -787,7 +785,7 @@ END_DEBUG
|
||||
fwdma_alloc_setup(sc->sc_fd.dev, sc->sc_dmat, SBP_DMA_SIZE,
|
||||
&sdev->dma, sizeof(uint32_t), BUS_DMA_NOWAIT);
|
||||
if (sdev->dma.v_addr == NULL) {
|
||||
free(sdev, M_SBP);
|
||||
kmem_free(sdev, sizeof(struct sbp_dev));
|
||||
target->luns[lun] = NULL;
|
||||
goto next;
|
||||
}
|
||||
@ -2048,7 +2046,7 @@ sbp_free_sdev(struct sbp_dev *sdev)
|
||||
for (i = 0; i < SBP_QUEUE_LEN; i++)
|
||||
bus_dmamap_destroy(sc->sc_dmat, sdev->ocb[i].dmamap);
|
||||
fwdma_free(sdev->dma.dma_tag, sdev->dma.dma_map, sdev->dma.v_addr);
|
||||
free(sdev, M_SBP);
|
||||
kmem_free(sdev, sizeof(struct sbp_dev));
|
||||
sdev = NULL;
|
||||
}
|
||||
|
||||
@ -2070,7 +2068,7 @@ sbp_free_target(struct sbp_target *target)
|
||||
fw_xfer_free_buf(xfer);
|
||||
}
|
||||
STAILQ_INIT(&target->xferlist);
|
||||
free(target->luns, M_SBP);
|
||||
kmem_free(target->luns, sizeof(struct sbp_dev *) * target->num_lun);
|
||||
target->num_lun = 0;
|
||||
target->luns = NULL;
|
||||
target->fwdev = NULL;
|
||||
@ -2217,7 +2215,8 @@ sbp_timeout(void *arg)
|
||||
/* XXX give up */
|
||||
sbp_scsipi_detach_target(target);
|
||||
if (target->luns != NULL)
|
||||
free(target->luns, M_SBP);
|
||||
kmem_free(target->luns,
|
||||
sizeof(struct sbp_dev *) * target->num_lun);
|
||||
target->num_lun = 0;
|
||||
target->luns = NULL;
|
||||
target->fwdev = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user