Browse Source

[kernel] add stricter check flags and solve warnings

Meco Man 1 year ago
parent
commit
b450bd5427
7 changed files with 42 additions and 11 deletions
  1. 5 0
      include/rtthread.h
  2. 7 1
      src/SConscript
  3. 2 2
      src/components.c
  4. 1 0
      src/idle.c
  5. 14 4
      src/ipc.c
  6. 7 0
      src/kservice.c
  7. 6 4
      src/thread.c

+ 5 - 0
include/rtthread.h

@@ -42,6 +42,9 @@
 extern "C" {
 #endif
 
+int main(void);
+int entry(void);
+
 /**
  * @addtogroup KernelObject
  * @{
@@ -454,6 +457,8 @@ rt_err_t rt_mb_delete(rt_mailbox_t mb);
 #endif /* RT_USING_HEAP */
 
 rt_err_t rt_mb_send(rt_mailbox_t mb, rt_ubase_t value);
+rt_err_t rt_mb_send_interruptible(rt_mailbox_t mb, rt_ubase_t value);
+rt_err_t rt_mb_send_killable(rt_mailbox_t mb, rt_ubase_t value);
 rt_err_t rt_mb_send_wait(rt_mailbox_t mb,
                          rt_ubase_t  value,
                          rt_int32_t   timeout);

+ 7 - 1
src/SConscript

@@ -1,4 +1,5 @@
 from building import *
+from gcc import GetGCCLikePLATFORM
 import os
 
 src = Glob('*.c')
@@ -6,6 +7,8 @@ cwd = GetCurrentDir()
 
 inc = [os.path.join(cwd, '..', 'include')]
 
+LOCAL_CFLAGS = ''
+
 if GetDepend('RT_USING_SMALL_MEM') == False:
     SrcRemove(src, ['mem.c'])
 
@@ -30,6 +33,9 @@ if GetDepend('RT_USING_SMP') == False:
 if GetDepend('RT_USING_SMP') == True:
     SrcRemove(src, ['scheduler_up.c'])
 
-group = DefineGroup('Kernel', src, depend = [''], CPPPATH = inc, CPPDEFINES = ['__RTTHREAD__'])
+if rtconfig.PLATFORM in GetGCCLikePLATFORM():
+    LOCAL_CFLAGS += ' -Wstrict-prototypes -Wmissing-prototypes -Wunused-parameter -Wunused -Wreturn-type -Wformat -Wswitch'
+
+group = DefineGroup('Kernel', src, depend = [''], CPPPATH = inc, CPPDEFINES = ['__RTTHREAD__'], LOCAL_CFLAGS=LOCAL_CFLAGS)
 
 Return('group')

+ 2 - 2
src/components.c

@@ -178,9 +178,9 @@ struct rt_thread main_thread;
  *
  * @param  parameter is the arg of the thread.
  */
-void main_thread_entry(void *parameter)
+static void main_thread_entry(void *parameter)
 {
-    extern int main(void);
+    RT_UNUSED(parameter);
 
 #ifdef RT_USING_COMPONENTS_INIT
     /* RT-Thread components initialization */

+ 1 - 0
src/idle.c

@@ -267,6 +267,7 @@ static void rt_defunct_execute(void)
 
 static void idle_thread_entry(void *parameter)
 {
+    RT_UNUSED(parameter);
 #ifdef RT_USING_SMP
     if (rt_hw_cpu_id() != 0)
     {

+ 14 - 4
src/ipc.c

@@ -1591,11 +1591,11 @@ RTM_EXPORT(rt_mutex_release);
  */
 rt_err_t rt_mutex_control(rt_mutex_t mutex, int cmd, void *arg)
 {
-    /* parameter check */
-    RT_ASSERT(mutex != RT_NULL);
-    RT_ASSERT(rt_object_get_type(&mutex->parent.parent) == RT_Object_Class_Mutex);
+    RT_UNUSED(mutex);
+    RT_UNUSED(cmd);
+    RT_UNUSED(arg);
 
-    return -RT_ERROR;
+    return -RT_EINVAL;
 }
 RTM_EXPORT(rt_mutex_control);
 
@@ -2123,6 +2123,8 @@ rt_err_t rt_event_control(rt_event_t event, int cmd, void *arg)
 {
     rt_base_t level;
 
+    RT_UNUSED(arg);
+
     /* parameter check */
     RT_ASSERT(event != RT_NULL);
     RT_ASSERT(rt_object_get_type(&event->parent.parent) == RT_Object_Class_Event);
@@ -2866,6 +2868,8 @@ rt_err_t rt_mb_control(rt_mailbox_t mb, int cmd, void *arg)
 {
     rt_base_t level;
 
+    RT_UNUSED(arg);
+
     /* parameter check */
     RT_ASSERT(mb != RT_NULL);
     RT_ASSERT(rt_object_get_type(&mb->parent.parent) == RT_Object_Class_MailBox);
@@ -3243,6 +3247,8 @@ static rt_err_t _rt_mq_send_wait(rt_mq_t mq,
     struct rt_thread *thread;
     rt_err_t ret;
 
+    RT_UNUSED(prio);
+
     /* parameter check */
     RT_ASSERT(mq != RT_NULL);
     RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);
@@ -3626,6 +3632,8 @@ static rt_ssize_t _rt_mq_recv(rt_mq_t mq,
     rt_err_t ret;
     rt_size_t len;
 
+    RT_UNUSED(prio);
+
     /* parameter check */
     RT_ASSERT(mq != RT_NULL);
     RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);
@@ -3839,6 +3847,8 @@ rt_err_t rt_mq_control(rt_mq_t mq, int cmd, void *arg)
     rt_base_t level;
     struct rt_mq_message *msg;
 
+    RT_UNUSED(arg);
+
     /* parameter check */
     RT_ASSERT(mq != RT_NULL);
     RT_ASSERT(rt_object_get_type(&mq->parent.parent) == RT_Object_Class_MessageQueue);

+ 7 - 0
src/kservice.c

@@ -95,12 +95,18 @@ rt_weak void rt_hw_cpu_shutdown(void)
 
 rt_weak rt_err_t rt_hw_backtrace_frame_get(rt_thread_t thread, struct rt_hw_backtrace_frame *frame)
 {
+    RT_UNUSED(thread);
+    RT_UNUSED(frame);
+
     LOG_W("%s is not implemented", __func__);
     return -RT_ENOSYS;
 }
 
 rt_weak rt_err_t rt_hw_backtrace_frame_unwind(rt_thread_t thread, struct rt_hw_backtrace_frame *frame)
 {
+    RT_UNUSED(thread);
+    RT_UNUSED(frame);
+
     LOG_W("%s is not implemented", __func__);
     return -RT_ENOSYS;
 }
@@ -1482,6 +1488,7 @@ RTM_EXPORT(rt_console_set_device);
 rt_weak void rt_hw_console_output(const char *str)
 {
     /* empty console output */
+    RT_UNUSED(str);
 }
 RTM_EXPORT(rt_hw_console_output);
 

+ 6 - 4
src/thread.c

@@ -30,7 +30,7 @@
  * 2021-11-15     THEWON       Remove duplicate work between idle and _thread_exit
  * 2021-12-27     Meco Man     remove .init_priority
  * 2022-01-07     Gabriel      Moving __on_rt_xxxxx_hook to thread.c
- * 2022-01-24     THEWON       let rt_thread_sleep return thread->error when using signal
+ * 2022-01-24     THEWON       let _thread_sleep return thread->error when using signal
  * 2022-10-15     Bernard      add nested mutex feature
  * 2023-09-15     xqyjlj       perf rt_hw_interrupt_disable/enable
  * 2023-12-10     xqyjlj       fix thread_exit/detach/delete
@@ -164,6 +164,8 @@ static rt_err_t _thread_init(struct rt_thread *thread,
                              rt_uint8_t        priority,
                              rt_uint32_t       tick)
 {
+    RT_UNUSED(name);
+
     /* init thread list */
     rt_list_init(&(thread->tlist));
     rt_list_init(&(thread->tlist_schedule));
@@ -622,7 +624,7 @@ RTM_EXPORT(rt_thread_yield);
  * @return  Return the operation status. If the return value is RT_EOK, the function is successfully executed.
  *          If the return value is any other values, it means this operation failed.
  */
-rt_err_t rt_thread_sleep(rt_tick_t tick)
+static rt_err_t _thread_sleep(rt_tick_t tick)
 {
     rt_base_t level;
     struct rt_thread *thread;
@@ -686,7 +688,7 @@ rt_err_t rt_thread_sleep(rt_tick_t tick)
  */
 rt_err_t rt_thread_delay(rt_tick_t tick)
 {
-    return rt_thread_sleep(tick);
+    return _thread_sleep(tick);
 }
 RTM_EXPORT(rt_thread_delay);
 
@@ -773,7 +775,7 @@ rt_err_t rt_thread_mdelay(rt_int32_t ms)
 
     tick = rt_tick_from_millisecond(ms);
 
-    return rt_thread_sleep(tick);
+    return _thread_sleep(tick);
 }
 RTM_EXPORT(rt_thread_mdelay);