Sun Jan 24 21:48:38 2021 UTC ()
malloc(9) -> kmem(9)


(thorpej)
diff -r1.47 -r1.48 src/sys/dev/ofw/ofw_subr.c

cvs diff -r1.47 -r1.48 src/sys/dev/ofw/ofw_subr.c (expand / switch to unified diff)

--- src/sys/dev/ofw/ofw_subr.c 2021/01/24 19:38:37 1.47
+++ src/sys/dev/ofw/ofw_subr.c 2021/01/24 21:48:38 1.48
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ofw_subr.c,v 1.47 2021/01/24 19:38:37 thorpej Exp $ */ 1/* $NetBSD: ofw_subr.c,v 1.48 2021/01/24 21:48:38 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright 1998 4 * Copyright 1998
5 * Digital Equipment Corporation. All rights reserved. 5 * Digital Equipment Corporation. All rights reserved.
6 * 6 *
7 * This software is furnished under license and may be used and 7 * This software is furnished under license and may be used and
8 * copied only in accordance with the following terms and conditions. 8 * copied only in accordance with the following terms and conditions.
9 * Subject to these conditions, you may download, copy, install, 9 * Subject to these conditions, you may download, copy, install,
10 * use, modify and distribute this software in source and/or binary 10 * use, modify and distribute this software in source and/or binary
11 * form. No title or ownership is transferred hereby. 11 * form. No title or ownership is transferred hereby.
12 * 12 *
13 * 1) Any source code used, modified or distributed must reproduce 13 * 1) Any source code used, modified or distributed must reproduce
14 * and retain this copyright notice and list of conditions as 14 * and retain this copyright notice and list of conditions as
@@ -24,33 +24,32 @@ @@ -24,33 +24,32 @@
24 * 3) This software is provided "AS-IS" and any express or implied 24 * 3) This software is provided "AS-IS" and any express or implied
25 * warranties, including but not limited to, any implied warranties 25 * warranties, including but not limited to, any implied warranties
26 * of merchantability, fitness for a particular purpose, or 26 * of merchantability, fitness for a particular purpose, or
27 * non-infringement are disclaimed. In no event shall DIGITAL be 27 * non-infringement are disclaimed. In no event shall DIGITAL be
28 * liable for any damages whatsoever, and in particular, DIGITAL 28 * liable for any damages whatsoever, and in particular, DIGITAL
29 * shall not be liable for special, indirect, consequential, or 29 * shall not be liable for special, indirect, consequential, or
30 * incidental damages or damages for lost profits, loss of 30 * incidental damages or damages for lost profits, loss of
31 * revenue or loss of use, whether such damages arise in contract, 31 * revenue or loss of use, whether such damages arise in contract,
32 * negligence, tort, under statute, in equity, at law or otherwise, 32 * negligence, tort, under statute, in equity, at law or otherwise,
33 * even if advised of the possibility of such damage. 33 * even if advised of the possibility of such damage.
34 */ 34 */
35 35
36#include <sys/cdefs.h> 36#include <sys/cdefs.h>
37__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.47 2021/01/24 19:38:37 thorpej Exp $"); 37__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.48 2021/01/24 21:48:38 thorpej Exp $");
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/kmem.h> 41#include <sys/kmem.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/malloc.h> 
44#include <dev/ofw/openfirm.h> 43#include <dev/ofw/openfirm.h>
45 44
46#define OFW_MAX_STACK_BUF_SIZE 256 45#define OFW_MAX_STACK_BUF_SIZE 256
47#define OFW_PATH_BUF_SIZE 512 46#define OFW_PATH_BUF_SIZE 512
48 47
49/* 48/*
50 * int of_decode_int(p) 49 * int of_decode_int(p)
51 * 50 *
52 * This routine converts OFW encoded-int datums 51 * This routine converts OFW encoded-int datums
53 * into the integer format of the host machine. 52 * into the integer format of the host machine.
54 * 53 *
55 * It is primarily used to convert integer properties 54 * It is primarily used to convert integer properties
56 * returned by the OF_getprop routine. 55 * returned by the OF_getprop routine.
@@ -283,49 +282,49 @@ of_search_compatible(int phandle, @@ -283,49 +282,49 @@ of_search_compatible(int phandle,
283 * If the leaf node name was successfully extracted, 'buf' is 282 * If the leaf node name was successfully extracted, 'buf' is
284 * filled in with at most 'bufsize' bytes of the leaf node 283 * filled in with at most 'bufsize' bytes of the leaf node
285 * name. If the leaf node was not successfully extracted, a 284 * name. If the leaf node was not successfully extracted, a
286 * somewhat meaningful string is placed in the buffer. In 285 * somewhat meaningful string is placed in the buffer. In
287 * either case, the contents of 'buf' will be NUL-terminated. 286 * either case, the contents of 'buf' will be NUL-terminated.
288 */ 287 */
289int 288int
290of_packagename(int phandle, char *buf, int bufsize) 289of_packagename(int phandle, char *buf, int bufsize)
291{ 290{
292 char *pbuf; 291 char *pbuf;
293 const char *lastslash; 292 const char *lastslash;
294 int l, rv; 293 int l, rv;
295 294
296 pbuf = malloc(OFW_PATH_BUF_SIZE, M_TEMP, M_WAITOK); 295 pbuf = kmem_alloc(OFW_PATH_BUF_SIZE, KM_SLEEP);
297 l = OF_package_to_path(phandle, pbuf, OFW_PATH_BUF_SIZE); 296 l = OF_package_to_path(phandle, pbuf, OFW_PATH_BUF_SIZE);
298 297
299 /* check that we could get the name, and that it's not too long. */ 298 /* check that we could get the name, and that it's not too long. */
300 if (l < 0 || 299 if (l < 0 ||
301 (l == OFW_PATH_BUF_SIZE && pbuf[OFW_PATH_BUF_SIZE - 1] != '\0')) { 300 (l == OFW_PATH_BUF_SIZE && pbuf[OFW_PATH_BUF_SIZE - 1] != '\0')) {
302 if (bufsize >= 25) 301 if (bufsize >= 25)
303 snprintf(buf, bufsize, "??? (phandle 0x%x)", phandle); 302 snprintf(buf, bufsize, "??? (phandle 0x%x)", phandle);
304 else if (bufsize >= 4) 303 else if (bufsize >= 4)
305 strlcpy(buf, "???", bufsize); 304 strlcpy(buf, "???", bufsize);
306 else 305 else
307 panic("of_packagename: bufsize = %d is silly", 306 panic("of_packagename: bufsize = %d is silly",
308 bufsize); 307 bufsize);
309 rv = -1; 308 rv = -1;
310 } else { 309 } else {
311 pbuf[l] = '\0'; 310 pbuf[l] = '\0';
312 lastslash = strrchr(pbuf, '/'); 311 lastslash = strrchr(pbuf, '/');
313 strlcpy(buf, (lastslash == NULL) ? pbuf : (lastslash + 1), 312 strlcpy(buf, (lastslash == NULL) ? pbuf : (lastslash + 1),
314 bufsize); 313 bufsize);
315 rv = 0; 314 rv = 0;
316 } 315 }
317 316
318 free(pbuf, M_TEMP); 317 kmem_free(pbuf, OFW_PATH_BUF_SIZE);
319 return (rv); 318 return (rv);
320} 319}
321 320
322/*  321/*
323 * Find the first child of a given node that matches name. Does not recurse. 322 * Find the first child of a given node that matches name. Does not recurse.
324 */ 323 */
325int 324int
326of_find_firstchild_byname(int node, const char *name) 325of_find_firstchild_byname(int node, const char *name)
327{ 326{
328 char namex[32];  327 char namex[32];
329 int nn; 328 int nn;
330  329
331 for (nn = OF_child(node); nn; nn = OF_peer(nn)) { 330 for (nn = OF_child(node); nn; nn = OF_peer(nn)) {