Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofw no need for alloca() in of_compatible(), malloc(...



details:   https://anonhg.NetBSD.org/src/rev/5d04e566d61a
branches:  trunk
changeset: 973258:5d04e566d61a
user:      jdolecek <jdolecek%NetBSD.org@localhost>
date:      Thu Jun 25 11:31:45 2020 +0000

description:
no need for alloca() in of_compatible(), malloc() is fine

diffstat:

 sys/dev/ofw/ofw_subr.c |  17 +++++------------
 1 files changed, 5 insertions(+), 12 deletions(-)

diffs (52 lines):

diff -r 8365cddb178e -r 5d04e566d61a sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Thu Jun 25 11:26:05 2020 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Thu Jun 25 11:31:45 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_subr.c,v 1.36 2020/06/12 14:52:11 thorpej Exp $    */
+/*     $NetBSD: ofw_subr.c,v 1.37 2020/06/25 11:31:45 jdolecek Exp $   */
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.36 2020/06/12 14:52:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.37 2020/06/25 11:31:45 jdolecek Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -100,7 +100,7 @@
 of_compatible(int phandle, const char * const *strings)
 {
 
-       int len, olen, allocated, nstr, cstr, rv;
+       int len, olen, nstr, cstr, rv;
        char *buf;
        const char *sp, *nsp;
 
@@ -108,13 +108,7 @@
        if (len <= 0)
                return (-1);
 
-       if (len > OFW_MAX_STACK_BUF_SIZE) {
-               buf = malloc(len, M_TEMP, M_WAITOK);
-               allocated = 1;
-       } else {
-               buf = alloca(len);
-               allocated = 0;
-       }
+       buf = malloc(len, M_TEMP, M_WAITOK);
 
        /* 'compatible' size should not change. */
        if (OF_getprop(phandle, "compatible", buf, len) != len) {
@@ -150,8 +144,7 @@
        rv = -1;
 
 out:
-       if (allocated)
-               free(buf, M_TEMP);
+       free(buf, M_TEMP);
        return (rv);
 }
 



Home | Main Index | Thread Index | Old Index