summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTangyuxin <[email protected]>2022-04-19 22:46:42 +0800
committerGitHub <[email protected]>2022-04-19 22:46:42 +0800
commit14d9709fdce9748efdd922ac5dc30687f9d21e80 (patch)
tree3cd70897f427869cbbaff57bad5d580fc32649ad
parent7847c5e98d7ec7ca81b0b6dd5dfbd694ef3ba512 (diff)
[finsh][cmd] Enhance system robustness (#5832)
-rw-r--r--components/finsh/cmd.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c
index aa48faea87..521cb9e73f 100644
--- a/components/finsh/cmd.c
+++ b/components/finsh/cmd.c
@@ -793,7 +793,7 @@ long list_timer(void)
MSH_CMD_EXPORT(list_timer, list timer in system);
#ifdef RT_USING_DEVICE
-static char *const device_type_str[] =
+static char *const device_type_str[RT_Device_Class_Unknown] =
{
"Character Device",
"Block Device",
@@ -825,7 +825,6 @@ static char *const device_type_str[] =
"DAC Device",
"WDT Device",
"PWM Device",
- "Unknown"
};
long list_device(void)
@@ -834,6 +833,7 @@ long list_device(void)
list_get_next_t find_arg;
rt_list_t *obj_list[LIST_FIND_OBJ_NR];
rt_list_t *next = (rt_list_t *)RT_NULL;
+ const char *device_type;
int maxlen;
const char *item_title = "device";
@@ -866,12 +866,16 @@ long list_device(void)
rt_hw_interrupt_enable(level);
device = (struct rt_device *)obj;
+ device_type = "Unknown";
+ if (device->type < RT_Device_Class_Unknown &&
+ device_type_str[device->type] != RT_NULL)
+ {
+ device_type = device_type_str[device->type];
+ }
rt_kprintf("%-*.*s %-20s %-8d\n",
maxlen, RT_NAME_MAX,
device->parent.name,
- (device->type <= RT_Device_Class_Unknown) ?
- device_type_str[device->type] :
- device_type_str[RT_Device_Class_Unknown],
+ device_type,
device->ref_count);
}