Module Name: src Committed By: jmcneill Date: Wed Jul 19 20:18:07 UTC 2017
Modified Files: src/sys/dev/fdt: fdt_subr.c Log Message: Fix a problem with fdtbus_get_phandle where we were passing size -1 to kmem_alloc when the property was not found. This seemed to work with DIAGNOSTIC kernels, but panics in vmem with a non-DIAGNOSTIC kernel. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/sys/dev/fdt/fdt_subr.c 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.16 src/sys/dev/fdt/fdt_subr.c:1.17 --- src/sys/dev/fdt/fdt_subr.c:1.16 Sat Jul 8 12:36:51 2017 +++ src/sys/dev/fdt/fdt_subr.c Wed Jul 19 20:18:07 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $ */ +/* $NetBSD: fdt_subr.c,v 1.17 2017/07/19 20:18:07 jmcneill Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,11 +27,10 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.16 2017/07/08 12:36:51 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: fdt_subr.c,v 1.17 2017/07/19 20:18:07 jmcneill Exp $"); #include <sys/param.h> #include <sys/bus.h> -#include <sys/kmem.h> #include <libfdt.h> #include <dev/fdt/fdtvar.h> @@ -108,22 +107,15 @@ int fdtbus_get_phandle(int phandle, const char *prop) { u_int phandle_ref; - u_int *buf; + const u_int *buf; int len; - len = OF_getproplen(phandle, prop); - if (len < sizeof(phandle_ref)) - return -1; - - buf = kmem_alloc(len, KM_SLEEP); - - if (OF_getprop(phandle, prop, buf, len) != len) { - kmem_free(buf, len); + buf = fdt_getprop(fdtbus_get_data(), + fdtbus_phandle2offset(phandle), prop, &len); + if (buf == NULL || len < sizeof(phandle_ref)) return -1; - } - phandle_ref = fdt32_to_cpu(buf[0]); - kmem_free(buf, len); + phandle_ref = be32dec(buf); return fdtbus_get_phandle_from_native(phandle_ref); }