Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofw Fix fallout from migration from alloca() to mall...



details:   https://anonhg.NetBSD.org/src/rev/a6fa8615a075
branches:  trunk
changeset: 935151:a6fa8615a075
user:      rin <rin%NetBSD.org@localhost>
date:      Thu Jun 25 22:50:56 2020 +0000

description:
Fix fallout from migration from alloca() to malloc() in the previous.

of_compatible() is used at least for macppc in very early boot stage
where malloc() is still not available.

Therefore, for small (<= OFW_MAX_STACK_BUF_SIZE = 256) buffer, use
statically allocated one in the stack. For larger one, we continue to
use malloc() but KASSERT(!cold) is added for sure.

Fix boot failure for macppc reported by martin:
http://mail-index.netbsd.org/port-macppc/2020/06/25/msg002756.html

diffstat:

 sys/dev/ofw/ofw_subr.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r c3f0e1ce3953 -r a6fa8615a075 sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Thu Jun 25 18:30:42 2020 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Thu Jun 25 22:50:56 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_subr.c,v 1.37 2020/06/25 11:31:45 jdolecek Exp $   */
+/*     $NetBSD: ofw_subr.c,v 1.38 2020/06/25 22:50:56 rin Exp $        */
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.37 2020/06/25 11:31:45 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.38 2020/06/25 22:50:56 rin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -100,15 +100,22 @@
 of_compatible(int phandle, const char * const *strings)
 {
 
-       int len, olen, nstr, cstr, rv;
-       char *buf;
+       int len, olen, allocated, nstr, cstr, rv;
+       char *buf, sbuf[OFW_MAX_STACK_BUF_SIZE];
        const char *sp, *nsp;
 
        len = OF_getproplen(phandle, "compatible");
        if (len <= 0)
                return (-1);
 
-       buf = malloc(len, M_TEMP, M_WAITOK);
+       if (len > sizeof(sbuf)) {
+               KASSERT(!cold);
+               buf = malloc(len, M_TEMP, M_WAITOK);
+               allocated = 1;
+       } else {
+               buf = sbuf;
+               allocated = 0;
+       }
 
        /* 'compatible' size should not change. */
        if (OF_getprop(phandle, "compatible", buf, len) != len) {
@@ -144,7 +151,8 @@
        rv = -1;
 
 out:
-       free(buf, M_TEMP);
+       if (allocated)
+               free(buf, M_TEMP);
        return (rv);
 }
 



Home | Main Index | Thread Index | Old Index