Module Name:    src
Committed By:   jdolecek
Date:           Thu Jun 25 11:31:45 UTC 2020

Modified Files:
        src/sys/dev/ofw: ofw_subr.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/ofw/ofw_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/ofw/ofw_subr.c
diff -u src/sys/dev/ofw/ofw_subr.c:1.36 src/sys/dev/ofw/ofw_subr.c:1.37
--- src/sys/dev/ofw/ofw_subr.c:1.36	Fri Jun 12 14:52:11 2020
+++ src/sys/dev/ofw/ofw_subr.c	Thu Jun 25 11:31:45 2020
@@ -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 @@ int
 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 @@ of_compatible(int phandle, const char * 
 	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 @@ of_compatible(int phandle, const char * 
 	rv = -1;
 
 out:
-	if (allocated)
-		free(buf, M_TEMP);
+	free(buf, M_TEMP);
 	return (rv);
 }
 

Reply via email to