Search code examples
androidcompiler-errorslinux-kernelandroid-sourceandroid-kernel

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


I'm getting the following error when trying to compile an Android kernel and I'm not sure how to change this part of the code to solve the error.

  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

I'm using the 3.18 kernel from https://android.googlesource.com/kernel/common.git/+/android-3.18. I generated a default .config with make menuconfig and then I merged the Android base and recommended configs included in the android/configs folder. Upon doing a make bzImage I get the above error.

I'm building on a ARM machine (for ARM) running Ubuntu 14.10 and gcc 4.9.1.

The enclosing function's code is:

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);
}

Solution

  • I think the following function will help you:

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

    You can find it in include/linux/uidgid.h