diff options
Diffstat (limited to 'common/host_command.c')
-rw-r--r-- | common/host_command.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/common/host_command.c b/common/host_command.c index 3034419503..6a4b491936 100644 --- a/common/host_command.c +++ b/common/host_command.c @@ -363,6 +363,30 @@ host_packet_bad: */ static const struct host_command *find_host_command(int command) { +#ifdef CONFIG_HOSTCMD_SECTION_SORTED + const struct host_command *l, *r, *m; + uint32_t num, hc_size; + +/* Use binary search to locate host command handler */ + l = __hcmds; + r = __hcmds_end; + hc_size = sizeof(struct host_command); + + while (1) { + if (l > r) + return NULL; + + num = ((intptr_t)r - (intptr_t)l) / hc_size; + m = l + (num / 2); + + if (m->command < command) + l = m + 1; + else if (m->command > command) + r = m - 1; + else + return m; + } +#else const struct host_command *cmd; for (cmd = __hcmds; cmd < __hcmds_end; cmd++) { @@ -371,6 +395,7 @@ static const struct host_command *find_host_command(int command) } return NULL; +#endif } static void host_command_init(void) |