Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/fdt Fix a problem with fdtbus_get_phandle where we w...



details:   https://anonhg.NetBSD.org/src/rev/6e28988a57ce
branches:  trunk
changeset: 825523:6e28988a57ce
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Wed Jul 19 20:18:07 2017 +0000

description:
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.

diffstat:

 sys/dev/fdt/fdt_subr.c |  22 +++++++---------------
 1 files changed, 7 insertions(+), 15 deletions(-)

diffs (50 lines):

diff -r 3b464da01d03 -r 6e28988a57ce sys/dev/fdt/fdt_subr.c
--- a/sys/dev/fdt/fdt_subr.c    Wed Jul 19 16:55:12 2017 +0000
+++ b/sys/dev/fdt/fdt_subr.c    Wed Jul 19 20:18:07 2017 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 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))
+       buf = fdt_getprop(fdtbus_get_data(),
+           fdtbus_phandle2offset(phandle), prop, &len);
+       if (buf == NULL || len < sizeof(phandle_ref))
                return -1;
 
-       buf = kmem_alloc(len, KM_SLEEP);
-
-       if (OF_getprop(phandle, prop, buf, len) != len) {
-               kmem_free(buf, len);
-               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);
 }



Home | Main Index | Thread Index | Old Index