Thu Jun 9 07:17:02 2011 UTC ()
Use __arraycount


(matt)
diff -r1.46 -r1.47 src/sys/dev/usb/usb_mem.c

cvs diff -r1.46 -r1.47 src/sys/dev/usb/usb_mem.c (expand / switch to unified diff)

--- src/sys/dev/usb/usb_mem.c 2011/03/20 17:38:11 1.46
+++ src/sys/dev/usb/usb_mem.c 2011/06/09 07:17:02 1.47
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: usb_mem.c,v 1.46 2011/03/20 17:38:11 tsutsui Exp $ */ 1/* $NetBSD: usb_mem.c,v 1.47 2011/06/09 07:17:02 matt Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (lennart@augustsson.net) at 8 * by Lennart Augustsson (lennart@augustsson.net) at
9 * Carlstedt Research & Technology. 9 * Carlstedt Research & Technology.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33/* 33/*
34 * USB DMA memory allocation. 34 * USB DMA memory allocation.
35 * We need to allocate a lot of small (many 8 byte, some larger) 35 * We need to allocate a lot of small (many 8 byte, some larger)
36 * memory blocks that can be used for DMA. Using the bus_dma 36 * memory blocks that can be used for DMA. Using the bus_dma
37 * routines directly would incur large overheads in space and time. 37 * routines directly would incur large overheads in space and time.
38 */ 38 */
39 39
40#include <sys/cdefs.h> 40#include <sys/cdefs.h>
41__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.46 2011/03/20 17:38:11 tsutsui Exp $"); 41__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.47 2011/06/09 07:17:02 matt Exp $");
42 42
43#ifdef _KERNEL_OPT 43#ifdef _KERNEL_OPT
44#include "opt_usb.h" 44#include "opt_usb.h"
45#endif 45#endif
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/systm.h> 48#include <sys/systm.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/malloc.h> 50#include <sys/malloc.h>
51#include <sys/queue.h> 51#include <sys/queue.h>
52#include <sys/device.h> /* for usbdivar.h */ 52#include <sys/device.h> /* for usbdivar.h */
53#include <sys/bus.h> 53#include <sys/bus.h>
54#include <sys/cpu.h> 54#include <sys/cpu.h>
@@ -136,27 +136,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si @@ -136,27 +136,27 @@ usb_block_allocmem(bus_dma_tag_t tag, si
136 return (USBD_NOMEM); 136 return (USBD_NOMEM);
137 } 137 }
138#endif 138#endif
139 139
140 DPRINTFN(6, ("usb_block_allocmem: no free\n")); 140 DPRINTFN(6, ("usb_block_allocmem: no free\n"));
141 p = malloc(sizeof *p, M_USB, M_NOWAIT); 141 p = malloc(sizeof *p, M_USB, M_NOWAIT);
142 if (p == NULL) 142 if (p == NULL)
143 return (USBD_NOMEM); 143 return (USBD_NOMEM);
144 144
145 p->tag = tag; 145 p->tag = tag;
146 p->size = size; 146 p->size = size;
147 p->align = align; 147 p->align = align;
148 error = bus_dmamem_alloc(tag, p->size, align, 0, 148 error = bus_dmamem_alloc(tag, p->size, align, 0,
149 p->segs, sizeof(p->segs)/sizeof(p->segs[0]), 149 p->segs, __arraycount(p->segs),
150 &p->nsegs, BUS_DMA_NOWAIT); 150 &p->nsegs, BUS_DMA_NOWAIT);
151 if (error) 151 if (error)
152 goto free0; 152 goto free0;
153 153
154 error = bus_dmamem_map(tag, p->segs, p->nsegs, p->size, 154 error = bus_dmamem_map(tag, p->segs, p->nsegs, p->size,
155 &p->kaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT); 155 &p->kaddr, BUS_DMA_NOWAIT|BUS_DMA_COHERENT);
156 if (error) 156 if (error)
157 goto free1; 157 goto free1;
158 158
159 error = bus_dmamap_create(tag, p->size, 1, p->size, 159 error = bus_dmamap_create(tag, p->size, 1, p->size,
160 0, BUS_DMA_NOWAIT, &p->map); 160 0, BUS_DMA_NOWAIT, &p->map);
161 if (error) 161 if (error)
162 goto unmap; 162 goto unmap;