diff options
| author | garbled <garbled@NetBSD.org> | 2007-10-25 16:59:38 +0000 |
|---|---|---|
| committer | garbled <garbled@NetBSD.org> | 2007-10-25 16:59:38 +0000 |
| commit | fb3ebfc3c0a0d106ae3ec5d29be8aa6a69a7dfe9 (patch) | |
| tree | e1f93f0549e1d2038de92c59b61ae4c618f39170 /sys/dev | |
| parent | f608ef6f7bf4357ba311168e161844df87b40e1d (diff) | |
Add a new convenience function, of_find_firstchild_byname(), and apply
some minor KNF to this ofw_subr.c.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/ofw/ofw_subr.c | 32 | ||||
| -rw-r--r-- | sys/dev/ofw/openfirm.h | 3 |
2 files changed, 25 insertions, 10 deletions
diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c index c4af56ce6b5..25620a234c6 100644 --- a/sys/dev/ofw/ofw_subr.c +++ b/sys/dev/ofw/ofw_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: ofw_subr.c,v 1.11 2005/12/11 12:22:48 christos Exp $ */ +/* $NetBSD: ofw_subr.c,v 1.12 2007/10/25 16:59:38 garbled Exp $ */ /* * Copyright 1998 @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.11 2005/12/11 12:22:48 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.12 2007/10/25 16:59:38 garbled Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -98,9 +98,7 @@ of_decode_int(p) * None. */ int -of_compatible(phandle, strings) - int phandle; - const char * const *strings; +of_compatible(int phandle, const char * const *strings) { int len, allocated, rv; char *buf; @@ -175,10 +173,7 @@ out: * either case, the contents of 'buf' will be NUL-terminated. */ int -of_packagename(phandle, buf, bufsize) - int phandle; - char *buf; - int bufsize; +of_packagename(int phandle, char *buf, int bufsize) { char *pbuf; const char *lastslash; @@ -209,3 +204,22 @@ of_packagename(phandle, buf, bufsize) free(pbuf, M_TEMP); return (rv); } + +/* + * Find the first child of a given node that matches name. + */ +int +of_find_firstchild_byname(int node, const char *name) +{ + char namex[32]; + int nn; + + for (nn = OF_child(node); nn; nn = OF_peer(nn)) { + memset(namex, 0, sizeof(namex)); + if (OF_getprop(nn, "name", namex, sizeof(namex)) == -1) + continue; + if (strcmp(name, namex) == 0) + return nn; + } + return -1; +} diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h index c72c418be90..3ecaf5e41aa 100644 --- a/sys/dev/ofw/openfirm.h +++ b/sys/dev/ofw/openfirm.h @@ -1,4 +1,4 @@ -/* $NetBSD: openfirm.h,v 1.23 2007/01/20 21:42:12 he Exp $ */ +/* $NetBSD: openfirm.h,v 1.24 2007/10/25 16:59:38 garbled Exp $ */ /* * Copyright (C) 1995, 1996 Wolfgang Solfrank. @@ -99,5 +99,6 @@ int openfirmware(void *); int of_compatible(int, const char * const *); int of_decode_int(const unsigned char *); int of_packagename(int, char *, int); +int of_find_firstchild_byname(int, const char *); int *of_network_decode_media(int, int *, int *); |
