copy_to_user undefined in linux kernel version 4.12.8

In my project I am using char driver to communicate between user space and kernel space. I use the function copy_to_user(void user *to, const void *from, unsigned long n) to copy data from kernel space to user space buffer. We can find this function under #include < asm/uaccess.h > header file. I complied the project using Linux Kernel version 4.4.0-59-generic, Ubuntu OS version 16.04 LTS and its working fine without any error and warning. I get the desired output.

I compiled the same project using Linux kernel version 4.12.8, Ubuntu OS version 16.04.2 LTS and it throws me an warning during compile time WARNING: "copy_to_user" [/home/ldrv1/Desktop/Vijay/code/build/uts.ko] undefined!. When I do insmod of my module I get error as follows insmod: ERROR: could not insert module uts.ko: Unknown symbol in module. I think that #include <asm/uaccess.h> header file is still supported in 4.12.8 kernel version else I would have got fatal error: no such file or directory error while compiling. I tried updating the linux kernel headers using apt-get install linux-headers-$(uname -r) command and I got the following response:

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.12.8
E: Couldn't find any package by glob 'linux-headers-4.12.8'
E: Couldn't find any package by regex 'linux-headers-4.12.8'

This OS version 16.04.2 LTS has linux-headers-4.10.0-35. How do I get rid of this warning? Suggestions and support appreciated. If more information is required please feel free to ask.

Upvotes: 13

Views: 18802

Answers (3)

The answer given by Bronislav Elizaveti is correct. If instead of #include <asm/uaccess.h> we use #include <linux/uaccess.h>, then we won't get the warning.

If you still want to use only #include <asm/uaccess.h>, then you'll need to use _copy_to_user instead of copy_to_user (with the same arguments). A simple _ will do the job.

Upvotes: 0

Hai Dang
Hai Dang

Reputation: 21

The function copy_to_user and copy_from_user defined in asm/uaccess.h . I think you have some issue when you define this function. I wrote the character device driver with some example about data transfer between Kernel space and User space. View my github: my code for reference. Please star if you feel it is helpful for you :). it has small bug in example 3. I am figuring them, but example 1 and example 2 work well

Upvotes: 0

user8549610
user8549610

Reputation:

  1. You should use #include <linux/uaccess.h> for 4.12.8. Here is the definition.

    In 4.4 some drivers use #include <asm/uaccess.h> whilst the others use #include <linux/uaccess.h>.

    #include <linux/uaccess.h> is preferable, I think.

  2. You should do apt-get update and then apt-get install linux-headers-generic.

Upvotes: 17

Related Questions