Skip to content

Commit 03a3fb0

Browse files
fyin1lijinxia
authored andcommitted
hv: cleanup the shell cmd code.
Remove cmd register API. And use static pre-defined cmd array instead. Signed-off-by: Yin Fengwei <fengwei.yin@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent edb26a7 commit 03a3fb0

File tree

3 files changed

+127
-337
lines changed

3 files changed

+127
-337
lines changed

hypervisor/debug/shell_internal.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -266,27 +266,19 @@ static int shell_process(struct shell *p_shell)
266266

267267
struct shell_cmd *shell_find_cmd(struct shell *p_shell, const char *cmd_str)
268268
{
269-
struct shell_cmd *p_cmd;
270-
bool is_found = false;
271-
struct list_head *pos;
272-
273-
p_cmd = NULL;
269+
uint32_t i;
270+
struct shell_cmd *p_cmd = NULL;
274271

275272
if (p_shell->cmd_count <= 0)
276273
return NULL;
277274

278-
list_for_each(pos, &p_shell->cmd_list) {
279-
p_cmd = list_entry(pos, struct shell_cmd, node);
280-
pr_dbg("shell: cmd in registered list is '%s' in %s",
281-
p_cmd->str, __func__);
282-
283-
if (strcmp(p_cmd->str, cmd_str) == 0) {
284-
is_found = true;
275+
for (i = 0; i < p_shell->cmd_count; i++) {
276+
p_cmd = &p_shell->shell_cmd[i];
277+
if (strcmp(p_cmd->str, cmd_str) == 0)
285278
break;
286-
}
287279
}
288280

289-
if (!is_found) {
281+
if (i == p_shell->cmd_count) {
290282
/* No commands in the list. */
291283
p_cmd = NULL;
292284
}
@@ -360,7 +352,7 @@ int shell_process_cmd(struct shell *p_shell, char *p_input_line)
360352

361353
/* Determine if there is a command to process. */
362354
if (cmd_argc != 0) {
363-
/* See if command is in the registered command list. */
355+
/* See if command is in cmds supported */
364356
p_cmd = shell_find_cmd(p_shell, cmd_argv[0]);
365357

366358
if (p_cmd != NULL) {
@@ -412,7 +404,6 @@ int shell_cmd_help(struct shell *p_shell,
412404
{
413405
int status = 0;
414406
int spaces = 0;
415-
int i;
416407
struct shell_cmd *p_cmd = NULL;
417408
char space_buf[MAX_INDENT_LEN + 1];
418409

@@ -428,11 +419,11 @@ int shell_cmd_help(struct shell *p_shell,
428419
/* No registered commands */
429420
shell_puts(p_shell, "NONE\r\n");
430421
} else {
431-
struct list_head *pos;
422+
int i = 0;
423+
uint32_t j;
432424

433-
i = 0;
434-
list_for_each(pos, &p_shell->cmd_list) {
435-
p_cmd = list_entry(pos, struct shell_cmd, node);
425+
for (j = 0; j < p_shell->cmd_count; j++) {
426+
p_cmd = &p_shell->shell_cmd[j];
436427

437428
/* Check if we've filled the screen with info */
438429
/* i + 1 used to avoid 0%SHELL_ROWS=0 */
@@ -1132,11 +1123,7 @@ int shell_construct(struct shell **p_shell)
11321123
/* Allocate memory for shell session */
11331124
*p_shell = (struct shell *) calloc(1, sizeof(**p_shell));
11341125

1135-
if (*p_shell) {
1136-
/* Zero-initialize the service control block. */
1137-
INIT_LIST_HEAD(&(*p_shell)->cmd_list);
1138-
(*p_shell)->cmd_count = 0;
1139-
} else {
1126+
if (!(*p_shell)) {
11401127
pr_err("Error: out of memory");
11411128
status = -ENOMEM;
11421129
}

hypervisor/debug/shell_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,22 @@ struct shell_io {
5353
#define SHELL_STRING_MAX_LEN (CPU_PAGE_SIZE << 2)
5454

5555
/* Shell Control Block */
56+
struct shell_cmd;
5657
struct shell {
5758
struct shell_io session_io; /* Session I/O information */
5859
char input_line[2][SHELL_CMD_MAX_LEN + 1]; /* current & last */
5960
char name[SHELL_NAME_MAX_LEN]; /* Session name */
6061
uint32_t input_line_len; /* Length of current input line */
6162
uint32_t input_line_active; /* Active input line index */
62-
struct list_head cmd_list; /* List of registered commands */
63-
uint32_t cmd_count; /* Count of added commands */
63+
struct shell_cmd *shell_cmd; /* cmds supported */
64+
uint32_t cmd_count; /* Count of cmds supported */
6465
};
6566

6667
/* Shell Command Function */
6768
typedef int (*shell_cmd_fn_t)(struct shell *, int, char **);
6869

6970
/* Shell Command */
7071
struct shell_cmd {
71-
struct list_head node; /* Linked list node */
7272
char *str; /* Command string */
7373
char *cmd_param; /* Command parameter string */
7474
char *help_str; /* Help text associated with the command */

0 commit comments

Comments
 (0)