Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic Fix binary search logic.
details: https://anonhg.NetBSD.org/src/rev/a0f33643d760
branches: trunk
changeset: 328963:a0f33643d760
user: riastradh <riastradh%NetBSD.org@localhost>
date: Fri Apr 25 23:54:58 2014 +0000
description:
Fix binary search logic.
Doesn't matter for the one user of this, but still.
diffstat:
sys/dev/ic/apple_smc.c | 13 +++++++++----
1 files changed, 9 insertions(+), 4 deletions(-)
diffs (43 lines):
diff -r 4bf5a5250c56 -r a0f33643d760 sys/dev/ic/apple_smc.c
--- a/sys/dev/ic/apple_smc.c Fri Apr 25 20:17:28 2014 +0000
+++ b/sys/dev/ic/apple_smc.c Fri Apr 25 23:54:58 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: apple_smc.c,v 1.5 2014/04/01 17:49:17 riastradh Exp $ */
+/* $NetBSD: apple_smc.c,v 1.6 2014/04/25 23:54:59 riastradh Exp $ */
/*
* Apple System Management Controller
@@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: apple_smc.c,v 1.5 2014/04/01 17:49:17 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apple_smc.c,v 1.6 2014/04/25 23:54:59 riastradh Exp $");
#include <sys/types.h>
#include <sys/param.h>
@@ -480,6 +480,7 @@
{
struct apple_smc_key *key;
uint32_t start = 0, end = apple_smc_nkeys(smc), median;
+ int cmp;
int error;
/* Do a binary search on the SMC's key space. */
@@ -489,10 +490,14 @@
if (error)
return error;
- if (memcmp(name, apple_smc_key_name(key), 4) < 0)
+ cmp = memcmp(name, apple_smc_key_name(key), 4);
+ if (cmp < 0)
end = median;
+ else if (cmp > 0)
+ start = (median + 1);
else
- start = (median + 1);
+ start = end = median; /* stop here */
+
apple_smc_release_key(smc, key);
}
Home |
Main Index |
Thread Index |
Old Index