Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/fdt Move logic for checking "status" property out of...
details: https://anonhg.NetBSD.org/src/rev/60d61e49cecd
branches: trunk
changeset: 353322:60d61e49cecd
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sat Apr 29 12:38:26 2017 +0000
description:
Move logic for checking "status" property out of fdtbus into a public
fdtbus_status_okay function.
diffstat:
sys/dev/fdt/fdt_subr.c | 16 ++++++++++++++--
sys/dev/fdt/fdtbus.c | 28 ++++++++--------------------
sys/dev/fdt/fdtvar.h | 4 +++-
3 files changed, 25 insertions(+), 23 deletions(-)
diffs (111 lines):
diff -r 9e7001fe04c1 -r 60d61e49cecd sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c Sat Apr 29 11:47:32 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c Sat Apr 29 12:38:26 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
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;
+}
diff -r 9e7001fe04c1 -r 60d61e49cecd sys/dev/fdt/fdtbus.c
--- a/sys/dev/fdt/fdtbus.c Sat Apr 29 11:47:32 2017 +0000
+++ b/sys/dev/fdt/fdtbus.c Sat Apr 29 12:38:26 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
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 @@
}
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);
diff -r 9e7001fe04c1 -r 60d61e49cecd sys/dev/fdt/fdtvar.h
--- a/sys/dev/fdt/fdtvar.h Sat Apr 29 11:47:32 2017 +0000
+++ b/sys/dev/fdt/fdtvar.h Sat Apr 29 12:38:26 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -235,4 +235,6 @@
int fdtbus_get_stdout_phandle(void);
int fdtbus_get_stdout_speed(void);
+bool fdtbus_status_okay(int);
+
#endif /* _DEV_FDT_FDTVAR_H */
Home |
Main Index |
Thread Index |
Old Index