From 00cfab6cfc0e981228198f58070ab6f21cb9f5bf Mon Sep 17 00:00:00 2001 From: Nick Ward Date: Sat, 13 Jan 2024 15:31:28 +1100 Subject: [PATCH] mgmt: mcumgr: use delayed workqueue for reset Same behaviour, less code, smaller code size. Signed-off-by: Nick Ward --- subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c index 13de45f02a9f57..7eef7f398f7603 100644 --- a/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c +++ b/subsys/mgmt/mcumgr/grp/os_mgmt/src/os_mgmt.c @@ -59,10 +59,8 @@ LOG_MODULE_REGISTER(mcumgr_os_grp, CONFIG_MCUMGR_GRP_OS_LOG_LEVEL); #ifdef CONFIG_REBOOT static void os_mgmt_reset_work_handler(struct k_work *work); -static void os_mgmt_reset_cb(struct k_timer *timer); -K_WORK_DEFINE(os_mgmt_reset_work, os_mgmt_reset_work_handler); -static K_TIMER_DEFINE(os_mgmt_reset_timer, os_mgmt_reset_cb, NULL); +K_WORK_DELAYABLE_DEFINE(os_mgmt_reset_work, os_mgmt_reset_work_handler); #endif /* This is passed to zcbor_map_start/end_endcode as a number of @@ -358,13 +356,9 @@ static int os_mgmt_taskstat_read(struct smp_streamer *ctxt) */ static void os_mgmt_reset_work_handler(struct k_work *work) { - sys_reboot(SYS_REBOOT_WARM); -} + ARG_UNUSED(work); -static void os_mgmt_reset_cb(struct k_timer *timer) -{ - /* Reboot the system from the system workqueue thread. */ - k_work_submit(&os_mgmt_reset_work); + sys_reboot(SYS_REBOOT_WARM); } static int os_mgmt_reset(struct smp_streamer *ctxt) @@ -404,8 +398,9 @@ static int os_mgmt_reset(struct smp_streamer *ctxt) } #endif - k_timer_start(&os_mgmt_reset_timer, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS), - K_NO_WAIT); + /* Reboot the system from the system workqueue thread. */ + k_work_schedule(&os_mgmt_reset_work, K_MSEC(CONFIG_MCUMGR_GRP_OS_RESET_MS)); + return 0; } #endif