From f6d57e521061b472effb663481ed7640a30aa507 Mon Sep 17 00:00:00 2001 From: Andrei Emeltchenko Date: Tue, 29 Aug 2023 15:43:39 +0300 Subject: [PATCH] ivshmem: shell: Fix crashing when device is not ready Fix crash when device is not ready but ivshmem is not NULL. Signed-off-by: Andrei Emeltchenko --- drivers/virtualization/virt_ivshmem_shell.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/drivers/virtualization/virt_ivshmem_shell.c b/drivers/virtualization/virt_ivshmem_shell.c index b073cbf8f41..4423c0fb0ed 100644 --- a/drivers/virtualization/virt_ivshmem_shell.c +++ b/drivers/virtualization/virt_ivshmem_shell.c @@ -8,7 +8,7 @@ #include #include -static const struct device *ivshmem; +static const struct device *ivshmem = DEVICE_DT_GET_ONE(qemu_ivshmem); #ifdef CONFIG_IVSHMEM_DOORBELL @@ -48,14 +48,12 @@ static void doorbell_notification_thread(const struct shell *sh) static bool get_ivshmem(const struct shell *sh) { - if (ivshmem == NULL) { - ivshmem = DEVICE_DT_GET_ONE(qemu_ivshmem); - if (!device_is_ready(ivshmem)) { - shell_error(sh, "IVshmem device is not ready"); - } + if (!device_is_ready(ivshmem)) { + shell_error(sh, "IVshmem device is not ready"); + return false; } - return ivshmem != NULL ? true : false; + return true; } static int cmd_ivshmem_shmem(const struct shell *sh,