From ac14685211b3b692ad6b2b684517781b20023c24 Mon Sep 17 00:00:00 2001 From: Flavio Ceolin Date: Thu, 1 Nov 2018 17:42:07 -0700 Subject: [PATCH] kernel: Delimiting the scope of some variables According with MISRA-C an object should be defined in a block scope if it is used in a single function. MISRA-C rule 8.9 Signed-off-by: Flavio Ceolin --- kernel/device.c | 16 ++++++++-------- kernel/init.c | 8 ++++++-- kernel/mailbox.c | 6 +++--- kernel/pipes.c | 6 +++--- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/kernel/device.c b/kernel/device.c index 2cd588cca4b..ec3515ccad2 100644 --- a/kernel/device.c +++ b/kernel/device.c @@ -17,14 +17,6 @@ extern struct device __device_POST_KERNEL_start[]; extern struct device __device_APPLICATION_start[]; extern struct device __device_init_end[]; -static struct device *config_levels[] = { - __device_PRE_KERNEL_1_start, - __device_PRE_KERNEL_2_start, - __device_POST_KERNEL_start, - __device_APPLICATION_start, - /* End marker */ - __device_init_end, -}; #ifdef CONFIG_DEVICE_POWER_MANAGEMENT extern u32_t __device_busy_start[]; @@ -46,6 +38,14 @@ extern u32_t __device_busy_end[]; void _sys_device_do_config_level(s32_t level) { struct device *info; + static struct device *config_levels[] = { + __device_PRE_KERNEL_1_start, + __device_PRE_KERNEL_2_start, + __device_POST_KERNEL_start, + __device_APPLICATION_start, + /* End marker */ + __device_init_end, + }; for (info = config_levels[level]; info < config_levels[level+1]; info++) { diff --git a/kernel/init.c b/kernel/init.c index 444ea7b6a1b..f0cbed045fe 100644 --- a/kernel/init.c +++ b/kernel/init.c @@ -43,10 +43,8 @@ LOG_MODULE_REGISTER(kernel); #if defined(CONFIG_BOOT_DELAY) && CONFIG_BOOT_DELAY > 0 #define BOOT_DELAY_BANNER " (delayed boot " \ STRINGIFY(CONFIG_BOOT_DELAY) "ms)" -static const unsigned int boot_delay = CONFIG_BOOT_DELAY; #else #define BOOT_DELAY_BANNER "" -static const unsigned int boot_delay; #endif #ifdef BUILD_VERSION @@ -199,6 +197,12 @@ static void bg_thread_main(void *unused1, void *unused2, void *unused3) ARG_UNUSED(unused2); ARG_UNUSED(unused3); +#if defined(CONFIG_BOOT_DELAY) && CONFIG_BOOT_DELAY > 0 + static const unsigned int boot_delay = CONFIG_BOOT_DELAY; +#else + static const unsigned int boot_delay; +#endif + _sys_device_do_config_level(_SYS_INIT_LEVEL_POST_KERNEL); #if CONFIG_STACK_POINTER_RANDOM z_stack_adjust_initialized = 1; diff --git a/kernel/mailbox.c b/kernel/mailbox.c index 4ada85424ad..bb331021897 100644 --- a/kernel/mailbox.c +++ b/kernel/mailbox.c @@ -26,9 +26,6 @@ struct k_mbox_async { struct k_mbox_msg tx_msg; /* transmit message descriptor */ }; -/* array of asynchronous message descriptors */ -static struct k_mbox_async __noinit async_msg[CONFIG_NUM_MBOX_ASYNC_MSGS]; - /* stack of unused asynchronous message descriptors */ K_STACK_DEFINE(async_msg_free, CONFIG_NUM_MBOX_ASYNC_MSGS); @@ -63,6 +60,9 @@ static int init_mbox_module(struct device *dev) { ARG_UNUSED(dev); + /* array of asynchronous message descriptors */ + static struct k_mbox_async __noinit async_msg[CONFIG_NUM_MBOX_ASYNC_MSGS]; + #if (CONFIG_NUM_MBOX_ASYNC_MSGS > 0) /* * Create pool of asynchronous message descriptors. diff --git a/kernel/pipes.c b/kernel/pipes.c index 6d765b91e9e..7f375877e16 100644 --- a/kernel/pipes.c +++ b/kernel/pipes.c @@ -45,9 +45,6 @@ struct k_pipe *_trace_list_k_pipe; #if (CONFIG_NUM_PIPE_ASYNC_MSGS > 0) -/* Array of asynchronous message descriptors */ -static struct k_pipe_async __noinit async_msg[CONFIG_NUM_PIPE_ASYNC_MSGS]; - /* stack of unused asynchronous message descriptors */ K_STACK_DEFINE(pipe_async_msgs, CONFIG_NUM_PIPE_ASYNC_MSGS); @@ -91,6 +88,9 @@ static int init_pipes_module(struct device *dev) { ARG_UNUSED(dev); + /* Array of asynchronous message descriptors */ + static struct k_pipe_async __noinit async_msg[CONFIG_NUM_PIPE_ASYNC_MSGS]; + #if (CONFIG_NUM_PIPE_ASYNC_MSGS > 0) /* * Create pool of asynchronous pipe message descriptors.