Android 内核编译错误 - 从类型“kuid_t”分配给类型“uid_t”时类型不兼容

Android kernel compile error - incompatible types when assigning to type ‘uid_t’ from type ‘kuid_t’

我在尝试编译 Android 内核时遇到以下错误,我不确定如何更改这部分代码来解决错误。

  CC      net/netfilter/xt_IDLETIMER.o
net/netfilter/xt_IDLETIMER.c: In function ‘reset_timer’:
net/netfilter/xt_IDLETIMER.c:360:16: error: incompatible types when assigning to type ‘uid_t’ from type ‘kuid_t’
     timer->uid = sk->sk_socket->file->f_cred->uid;
                ^
scripts/Makefile.build:257: recipe for target 'net/netfilter/xt_IDLETIMER.o' failed
make[2]: *** [net/netfilter/xt_IDLETIMER.o] Error 1
scripts/Makefile.build:402: recipe for target 'net/netfilter' failed
make[1]: *** [net/netfilter] Error 2
Makefile:937: recipe for target 'net' failed
make: *** [net] Error 2

我使用的是 https://android.googlesource.com/kernel/common.git/+/android-3.18 的 3.18 内核。 我用 make menuconfig 生成了一个默认的 .config,然后我合并了 Android 基础和推荐的配置,包括在 android/configs 文件夹中。执行 make bzImage 后出现上述错误。

我正在 ARM 机器上构建(用于 ARM)运行 Ubuntu 14.10 和 gcc 4.9.1。

封闭函数的代码是:

static void reset_timer(const struct idletimer_tg_info *info,
                        struct sk_buff *skb)
{
        unsigned long now = jiffies;
        struct idletimer_tg *timer = info->timer;
        bool timer_prev;

        spin_lock_bh(&timestamp_lock);
        timer_prev = timer->active;
        timer->active = true;
        /* timer_prev is used to guard overflow problem in time_before*/
        if (!timer_prev || time_before(timer->timer.expires, now)) {
                pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
                                timer->timer.expires, now);

                /* Stores the uid resposible for waking up the radio */
                if (skb && (skb->sk)) {
                        struct sock *sk = skb->sk;
                        read_lock_bh(&sk->sk_callback_lock);
                        if ((sk->sk_socket) && (sk->sk_socket->file) &&
                    (sk->sk_socket->file->f_cred))
                                timer->uid = sk->sk_socket->file->f_cred->uid;
                        read_unlock_bh(&sk->sk_callback_lock);
                }

                /* checks if there is a pending inactive notification*/
                if (timer->work_pending)
                        timer->delayed_timer_trigger = timer->last_modified_timer;
                else {  
                        timer->work_pending = true;
                        schedule_work(&timer->work);
                }
        }

        get_monotonic_boottime(&timer->last_modified_timer);
        mod_timer(&timer->timer,
                        msecs_to_jiffies(info->timeout * 1000) + now);
        spin_unlock_bh(&timestamp_lock);
}

我认为下面的函数会对你有所帮助:

 static inline uid_t __kuid_val(kuid_t uid)
 {
         return uid.val;
 }

您可以在 include/linux/uidgid.h

中找到它