From 0266bc4fff3b9f50badd8cf517f162f80cd73e3c Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Wed, 13 Jan 2016 23:11:23 +0000 Subject: Change aml_find_node() such that it only walks down the tree and doesn't traverse sideways. This seems to be what all callersexpect it to do, and fixes a bug in dwiic(4) where it would try to access i2c devices on busses they're not attached to. If there is any fallout from this change, the right thing to do is probably to make sure callers pass the right node. While there, change the return type to void, as the return value was useless and none of the callers looked at it. ok mlarkin@ --- sys/dev/acpi/dsdt.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'sys/dev/acpi/dsdt.c') diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c index 85885949141..769f8686096 100644 --- a/sys/dev/acpi/dsdt.c +++ b/sys/dev/acpi/dsdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dsdt.c,v 1.218 2015/08/20 20:50:10 kettenis Exp $ */ +/* $OpenBSD: dsdt.c,v 1.219 2016/01/13 23:11:22 kettenis Exp $ */ /* * Copyright (c) 2005 Jordan Hargrave * @@ -1249,26 +1249,26 @@ aml_walknodes(struct aml_node *node, int mode, nodecb(node, arg); } -int +void aml_find_node(struct aml_node *node, const char *name, int (*cbproc)(struct aml_node *, void *arg), void *arg) { + struct aml_node *child; const char *nn; - int st = 0; - while (node) { - if ((nn = node->name) != NULL) { + SIMPLEQ_FOREACH(child, &node->son, sib) { + nn = child->name; + if ((nn = child->name) != NULL) { if (*nn == AMLOP_ROOTCHAR) nn++; while (*nn == AMLOP_PARENTPREFIX) nn++; - if (!strcmp(name, nn)) - st = cbproc(node, arg); + if (strcmp(name, nn) == 0) { + /* Only recurse if cbproc() wants us to */ + if (cbproc(child, arg) == 0) + continue; + } } - /* Only recurse if cbproc() wants us to */ - if (!st) - aml_find_node(SIMPLEQ_FIRST(&node->son), name, cbproc, arg); - node = SIMPLEQ_NEXT(node, sib); + aml_find_node(child, name, cbproc, arg); } - return st; } /* -- cgit v1.2.3