| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: kern_drvctl.c,v 1.19.6.2 2009/04/04 23:36:27 snj Exp $ */ | | 1 | /* $NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2004 | | 4 | * Copyright (c) 2004 |
5 | * Matthias Drochner. All rights reserved. | | 5 | * Matthias Drochner. All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions, and the following disclaimer. | | 11 | * notice, this list of conditions, and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.19.6.2 2009/04/04 23:36:27 snj Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: kern_drvctl.c,v 1.19.6.3 2009/05/03 22:39:49 snj Exp $"); |
31 | | | 31 | |
32 | #include <sys/param.h> | | 32 | #include <sys/param.h> |
33 | #include <sys/systm.h> | | 33 | #include <sys/systm.h> |
34 | #include <sys/kernel.h> | | 34 | #include <sys/kernel.h> |
35 | #include <sys/conf.h> | | 35 | #include <sys/conf.h> |
36 | #include <sys/device.h> | | 36 | #include <sys/device.h> |
37 | #include <sys/event.h> | | 37 | #include <sys/event.h> |
38 | #include <sys/malloc.h> | | 38 | #include <sys/malloc.h> |
39 | #include <sys/kmem.h> | | 39 | #include <sys/kmem.h> |
40 | #include <sys/ioctl.h> | | 40 | #include <sys/ioctl.h> |
41 | #include <sys/fcntl.h> | | 41 | #include <sys/fcntl.h> |
42 | #include <sys/file.h> | | 42 | #include <sys/file.h> |
43 | #include <sys/filedesc.h> | | 43 | #include <sys/filedesc.h> |
| @@ -188,27 +188,31 @@ pmdevbyname(u_long cmd, struct devpmargs | | | @@ -188,27 +188,31 @@ pmdevbyname(u_long cmd, struct devpmargs |
188 | } | | 188 | } |
189 | default: | | 189 | default: |
190 | return EPASSTHROUGH; | | 190 | return EPASSTHROUGH; |
191 | } | | 191 | } |
192 | } | | 192 | } |
193 | | | 193 | |
194 | static int | | 194 | static int |
195 | listdevbyname(struct devlistargs *l) | | 195 | listdevbyname(struct devlistargs *l) |
196 | { | | 196 | { |
197 | device_t d, child; | | 197 | device_t d, child; |
198 | deviter_t di; | | 198 | deviter_t di; |
199 | int cnt = 0, idx, error = 0; | | 199 | int cnt = 0, idx, error = 0; |
200 | | | 200 | |
201 | if ((d = device_find_by_xname(l->l_devname)) == NULL) | | 201 | if (*l->l_devname == '\0') |
| | | 202 | d = (device_t)NULL; |
| | | 203 | else if (memchr(l->l_devname, 0, sizeof(l->l_devname)) == NULL) |
| | | 204 | return EINVAL; |
| | | 205 | else if ((d = device_find_by_xname(l->l_devname)) == NULL) |
202 | return ENXIO; | | 206 | return ENXIO; |
203 | | | 207 | |
204 | for (child = deviter_first(&di, 0); child != NULL; | | 208 | for (child = deviter_first(&di, 0); child != NULL; |
205 | child = deviter_next(&di)) { | | 209 | child = deviter_next(&di)) { |
206 | if (device_parent(child) != d) | | 210 | if (device_parent(child) != d) |
207 | continue; | | 211 | continue; |
208 | idx = cnt++; | | 212 | idx = cnt++; |
209 | if (l->l_childname == NULL || idx >= l->l_children) | | 213 | if (l->l_childname == NULL || idx >= l->l_children) |
210 | continue; | | 214 | continue; |
211 | error = copyoutstr(device_xname(child), l->l_childname[idx], | | 215 | error = copyoutstr(device_xname(child), l->l_childname[idx], |
212 | sizeof(l->l_childname[idx]), NULL); | | 216 | sizeof(l->l_childname[idx]), NULL); |
213 | if (error != 0) | | 217 | if (error != 0) |
214 | break; | | 218 | break; |