Module Name: src Committed By: jmcneill Date: Sat Apr 29 12:38:26 UTC 2017
Modified Files: src/sys/dev/fdt: fdt_subr.c fdtbus.c fdtvar.h Log Message: Move logic for checking "status" property out of fdtbus into a public fdtbus_status_okay function. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/sys/dev/fdt/fdt_subr.c cvs rdiff -u -r1.10 -r1.11 src/sys/dev/fdt/fdtbus.c cvs rdiff -u -r1.14 -r1.15 src/sys/dev/fdt/fdtvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/fdt/fdt_subr.c diff -u src/sys/dev/fdt/fdt_subr.c:1.9 src/sys/dev/fdt/fdt_subr.c:1.10 --- src/sys/dev/fdt/fdt_subr.c:1.9 Mon Apr 24 10:56:03 2017 +++ src/sys/dev/fdt/fdt_subr.c Sat Apr 29 12:38:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fdt_subr.c,v 1.9 2017/04/24 10:56:03 jmcneill Exp $ */ +/* $NetBSD: fdt_subr.c,v 1.10 2017/04/29 12:38:26 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.9 2017/04/24 10:56:03 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.10 2017/04/29 12:38:26 jmcneill Exp $"); #include <sys/param.h> #include <sys/bus.h> @@ -275,3 +275,15 @@ fdtbus_get_stdout_speed(void) return (int)strtoul(p + 1, NULL, 10); } + +bool +fdtbus_status_okay(int phandle) +{ + const int off = fdtbus_phandle2offset(phandle); + + const char *prop = fdt_getprop(fdtbus_get_data(), off, "status", NULL); + if (prop == NULL) + return true; + + return strncmp(prop, "ok", 2) == 0; +} Index: src/sys/dev/fdt/fdtbus.c diff -u src/sys/dev/fdt/fdtbus.c:1.10 src/sys/dev/fdt/fdtbus.c:1.11 --- src/sys/dev/fdt/fdtbus.c:1.10 Fri Apr 28 10:37:41 2017 +++ src/sys/dev/fdt/fdtbus.c Sat Apr 29 12:38:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fdtbus.c,v 1.10 2017/04/28 10:37:41 jmcneill Exp $ */ +/* $NetBSD: fdtbus.c,v 1.11 2017/04/29 12:38:26 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.10 2017/04/28 10:37:41 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.11 2017/04/29 12:38:26 jmcneill Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -100,7 +100,7 @@ fdt_attach(device_t parent, device_t sel const struct fdt_attach_args *faa = aux; const int phandle = faa->faa_phandle; struct fdt_node *node; - char *model, *name, *status; + char *model, *name; int len, child; sc->sc_dev = self; @@ -122,28 +122,16 @@ fdt_attach(device_t parent, device_t sel } for (child = OF_child(phandle); child; child = OF_peer(child)) { - /* If there is a "status" property, make sure it is "okay" */ - len = OF_getproplen(child, "status"); - if (len > 0) { - status = kmem_zalloc(len, KM_SLEEP); - int alen __diagused = OF_getprop(child, "status", status, len); - KASSERT(alen == len); - const bool okay_p = strcmp(status, "okay") == 0 || - strcmp(status, "ok") == 0; - kmem_free(status, len); - if (!okay_p) { - continue; - } - } + if (!fdtbus_status_okay(child)) + continue; len = OF_getproplen(child, "name"); - if (len <= 0) { + if (len <= 0) continue; - } + name = kmem_zalloc(len, KM_SLEEP); - if (OF_getprop(child, "name", name, len) != len) { + if (OF_getprop(child, "name", name, len) != len) continue; - } /* Add the node to our device list */ node = kmem_alloc(sizeof(*node), KM_SLEEP); Index: src/sys/dev/fdt/fdtvar.h diff -u src/sys/dev/fdt/fdtvar.h:1.14 src/sys/dev/fdt/fdtvar.h:1.15 --- src/sys/dev/fdt/fdtvar.h:1.14 Sat Apr 29 11:00:56 2017 +++ src/sys/dev/fdt/fdtvar.h Sat Apr 29 12:38:26 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fdtvar.h,v 1.14 2017/04/29 11:00:56 jmcneill Exp $ */ +/* $NetBSD: fdtvar.h,v 1.15 2017/04/29 12:38:26 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -235,4 +235,6 @@ const char * fdtbus_get_stdout_path(void int fdtbus_get_stdout_phandle(void); int fdtbus_get_stdout_speed(void); +bool fdtbus_status_okay(int); + #endif /* _DEV_FDT_FDTVAR_H */