From a9e45cfd7846754fa3a86d8e234484d4bbbc3a99 Mon Sep 17 00:00:00 2001 From: Yishai Jaffe Date: Thu, 28 Nov 2024 13:34:44 +0200 Subject: [PATCH] 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 --- drivers/can/can_shell.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/can/can_shell.c b/drivers/can/can_shell.c index 6b0cf37802bbb16..8344bf56f8669d5 100644 --- a/drivers/can/can_shell.c +++ b/drivers/can/can_shell.c @@ -68,6 +68,11 @@ static struct k_poll_event can_shell_rx_msgq_events[] = { static void can_shell_tx_msgq_triggered_work_handler(struct k_work *work); static void can_shell_rx_msgq_triggered_work_handler(struct k_work *work); +static bool device_is_can_and_ready(const struct device *dev) +{ + return device_is_ready(dev) && DEVICE_API_IS(can, dev); +} + #ifdef CONFIG_CAN_SHELL_SCRIPTING_FRIENDLY static void can_shell_dummy_bypass_cb(const struct shell *sh, uint8_t *data, size_t len) { @@ -996,7 +1001,7 @@ static int cmd_can_recover(const struct shell *sh, size_t argc, char **argv) static void cmd_can_device_name(size_t idx, struct shell_static_entry *entry) { - const struct device *dev = shell_device_lookup(idx, NULL); + const struct device *dev = shell_device_filter(idx, device_is_can_and_ready); entry->syntax = (dev != NULL) ? dev->name : NULL; entry->handler = NULL; @@ -1026,7 +1031,7 @@ static void cmd_can_mode(size_t idx, struct shell_static_entry *entry) static void cmd_can_device_name_mode(size_t idx, struct shell_static_entry *entry) { - const struct device *dev = shell_device_lookup(idx, NULL); + const struct device *dev = shell_device_filter(idx, device_is_can_and_ready); entry->syntax = (dev != NULL) ? dev->name : NULL; entry->handler = NULL;