在kernel中有一些变量不想或者没有必要初始化,但是这样编译器会报警告,这样可以采用宏uninitialized_var 来解决这个未初始化的警告
例如下面这段code中calltime就没有初始化,但是用uninitialized_var包起来,这样编译器就不会报警告了
static void async_run_entry_fn(struct work_struct *work)
{
struct async_entry *entry =
container_of(work, struct async_entry, work);
unsigned long flags;
ktime_t uninitialized_var(calltime), delta, rettime;
/* 1) run (and print duration) */
if (initcall_debug && system_state < SYSTEM_RUNNING) {
pr_debug("calling %lli_%pF @ %i\n",
(long long)entry->cookie,
entry->func, task_pid_nr(current));
calltime = ktime_get();
}
}
这个宏的定义如下:
#define uninitialized_var(x) x = x
可以看到是将自己赋值给自己,这样就消除了没有初始化的警告
uninitialized_var
最新推荐文章于 2024-06-18 12:16:21 发布