Skip to content

Commit ef30184

Browse files
committed
can: shell: filter device lookup using DEVICE_API macros
Filter for can devices when looking them up in dynamic shell commands. Signed-off-by: Yishai Jaffe <[email protected]>
1 parent 7a13a3d commit ef30184

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/can/can_shell.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ static struct k_poll_event can_shell_rx_msgq_events[] = {
6868
static void can_shell_tx_msgq_triggered_work_handler(struct k_work *work);
6969
static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work);
7070

71+
static bool device_is_can_and_ready(const struct device *dev)
72+
{
73+
return device_is_ready(dev) && DEVICE_API_IS(can, dev);
74+
}
75+
7176
#ifdef CONFIG_CAN_SHELL_SCRIPTING_FRIENDLY
7277
static void can_shell_dummy_bypass_cb(const struct shell *sh, uint8_t *data, size_t len)
7378
{
@@ -996,7 +1001,7 @@ static int cmd_can_recover(const struct shell *sh, size_t argc, char **argv)
9961001

9971002
static void cmd_can_device_name(size_t idx, struct shell_static_entry *entry)
9981003
{
999-
const struct device *dev = shell_device_lookup(idx, NULL);
1004+
const struct device *dev = shell_device_filter(idx, device_is_can_and_ready);
10001005

10011006
entry->syntax = (dev != NULL) ? dev->name : NULL;
10021007
entry->handler = NULL;
@@ -1026,7 +1031,7 @@ static void cmd_can_mode(size_t idx, struct shell_static_entry *entry)
10261031

10271032
static void cmd_can_device_name_mode(size_t idx, struct shell_static_entry *entry)
10281033
{
1029-
const struct device *dev = shell_device_lookup(idx, NULL);
1034+
const struct device *dev = shell_device_filter(idx, device_is_can_and_ready);
10301035

10311036
entry->syntax = (dev != NULL) ? dev->name : NULL;
10321037
entry->handler = NULL;

0 commit comments

Comments
 (0)