diff options
| author | Thomas Moestl <tmm@FreeBSD.org> | 2001-11-18 20:38:44 +0000 |
|---|---|---|
| committer | Thomas Moestl <tmm@FreeBSD.org> | 2001-11-18 20:38:44 +0000 |
| commit | 398e05ab1ccf6fe9c21426b0627e0570656dde93 (patch) | |
| tree | f5fd72ad640b097477c78af41a09eb2e4caedfac /sys/dev/ofw/openfirm.c | |
| parent | 656ad29399a3a53d43acae98e609cc9f9e2d3d95 (diff) | |
Notes
Diffstat (limited to 'sys/dev/ofw/openfirm.c')
| -rw-r--r-- | sys/dev/ofw/openfirm.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c index 61b639119a87..7704109b44a3 100644 --- a/sys/dev/ofw/openfirm.c +++ b/sys/dev/ofw/openfirm.c @@ -58,12 +58,16 @@ */ #include <sys/param.h> +#include <sys/kernel.h> +#include <sys/malloc.h> #include <sys/systm.h> #include <machine/stdarg.h> #include <dev/ofw/openfirm.h> +MALLOC_DEFINE(M_OFWPROP, "openfirm", "OpenFirmware properties"); + static ihandle_t stdin; static ihandle_t stdout; @@ -286,6 +290,30 @@ OF_getprop(phandle_t package, char *propname, void *buf, int buflen) return args.size; } +/* + * Store the value of a property of a package into newly allocated memory (using + * the M_OFWPROP malloc pool and M_WAITOK). elsz is the size of a single element, + * the number of elements is return in number. + */ +int +OF_getprop_alloc(phandle_t package, char *propname, int elsz, void **buf) +{ + int len; + + *buf = NULL; + if ((len = OF_getproplen(package, propname)) == -1 || + len % elsz != 0) + return (-1); + + *buf = malloc(len, M_OFWPROP, M_WAITOK); + if (OF_getprop(package, propname, *buf, len) == -1) { + free(*buf, M_OFWPROP); + *buf = NULL; + return (-1); + } + return (len / elsz); +} + /* Get the next property of a package. */ int OF_nextprop(phandle_t package, char *previous, char *buf) |
