Fri May 14 02:48:43 2021 UTC ()
Skip nodes without a "compatible" property.


(thorpej)
diff -r1.1.6.4 -r1.1.6.5 src/sys/dev/ofw/ofw_i2c_subr.c

cvs diff -r1.1.6.4 -r1.1.6.5 src/sys/dev/ofw/ofw_i2c_subr.c (expand / switch to unified diff)

--- src/sys/dev/ofw/ofw_i2c_subr.c 2021/05/14 01:52:36 1.1.6.4
+++ src/sys/dev/ofw/ofw_i2c_subr.c 2021/05/14 02:48:43 1.1.6.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $ */ 1/* $NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2021 The NetBSD Foundation, Inc. 4 * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * 3) This software is provided "AS-IS" and any express or implied 50 * 3) This software is provided "AS-IS" and any express or implied
51 * warranties, including but not limited to, any implied warranties 51 * warranties, including but not limited to, any implied warranties
52 * of merchantability, fitness for a particular purpose, or 52 * of merchantability, fitness for a particular purpose, or
53 * non-infringement are disclaimed. In no event shall DIGITAL be 53 * non-infringement are disclaimed. In no event shall DIGITAL be
54 * liable for any damages whatsoever, and in particular, DIGITAL 54 * liable for any damages whatsoever, and in particular, DIGITAL
55 * shall not be liable for special, indirect, consequential, or 55 * shall not be liable for special, indirect, consequential, or
56 * incidental damages or damages for lost profits, loss of 56 * incidental damages or damages for lost profits, loss of
57 * revenue or loss of use, whether such damages arise in contract, 57 * revenue or loss of use, whether such damages arise in contract,
58 * negligence, tort, under statute, in equity, at law or otherwise, 58 * negligence, tort, under statute, in equity, at law or otherwise,
59 * even if advised of the possibility of such damage. 59 * even if advised of the possibility of such damage.
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $");
64 64
65#include <sys/param.h> 65#include <sys/param.h>
66#include <sys/device.h> 66#include <sys/device.h>
67#include <sys/endian.h> 67#include <sys/endian.h>
68#include <sys/kmem.h> 68#include <sys/kmem.h>
69#include <sys/systm.h> 69#include <sys/systm.h>
70#include <dev/ofw/openfirm.h> 70#include <dev/ofw/openfirm.h>
71#include <dev/i2c/i2cvar.h> 71#include <dev/i2c/i2cvar.h>
72 72
73#ifdef __HAVE_OPENFIRMWARE_VARIANT_AAPL 73#ifdef __HAVE_OPENFIRMWARE_VARIANT_AAPL
74/* 74/*
75 * Apple OpenFirmware implementations have the i2c device 75 * Apple OpenFirmware implementations have the i2c device
76 * address shifted left 1 bit to account for the r/w bit 76 * address shifted left 1 bit to account for the r/w bit
@@ -166,26 +166,29 @@ of_i2c_enumerate_devices(device_t dev, d @@ -166,26 +166,29 @@ of_i2c_enumerate_devices(device_t dev, d
166 bool cbrv; 166 bool cbrv;
167 167
168 i2c_node = devhandle_to_of(call_handle); 168 i2c_node = devhandle_to_of(call_handle);
169 169
170 for (node = OF_child(i2c_node); node != 0; node = OF_peer(node)) { 170 for (node = OF_child(i2c_node); node != 0; node = OF_peer(node)) {
171 if (OF_getprop(node, "name", name, sizeof(name)) <= 0) { 171 if (OF_getprop(node, "name", name, sizeof(name)) <= 0) {
172 continue; 172 continue;
173 } 173 }
174 if (!of_i2c_get_address(args->ia->ia_tag, node, &addr)) { 174 if (!of_i2c_get_address(args->ia->ia_tag, node, &addr)) {
175 continue; 175 continue;
176 } 176 }
177 177
178 clist_size = OF_getproplen(node, "compatible"); 178 clist_size = OF_getproplen(node, "compatible");
 179 if (clist_size <= 0) {
 180 continue;
 181 }
179 clist = kmem_tmpbuf_alloc(clist_size, 182 clist = kmem_tmpbuf_alloc(clist_size,
180 compat_buf, sizeof(compat_buf), KM_SLEEP); 183 compat_buf, sizeof(compat_buf), KM_SLEEP);
181 if (OF_getprop(node, "compatible", clist, clist_size) < 184 if (OF_getprop(node, "compatible", clist, clist_size) <
182 clist_size) { 185 clist_size) {
183 kmem_tmpbuf_free(clist, clist_size, compat_buf); 186 kmem_tmpbuf_free(clist, clist_size, compat_buf);
184 continue; 187 continue;
185 } 188 }
186 props = prop_dictionary_create(); 189 props = prop_dictionary_create();
187 190
188 args->ia->ia_addr = (i2c_addr_t)addr; 191 args->ia->ia_addr = (i2c_addr_t)addr;
189 args->ia->ia_name = name; 192 args->ia->ia_name = name;
190 args->ia->ia_clist = clist; 193 args->ia->ia_clist = clist;
191 args->ia->ia_clist_size = clist_size; 194 args->ia->ia_clist_size = clist_size;