为什么我在带有ioctl的内核模块中收到此编译警告?

0x9*_*x90 0 c linux-kernel

当这样定义时t_ioctl,我没有得到警告:

long t_ioctl(struct file *filep, unsigned int cmd, unsigned long input){
Run Code Online (Sandbox Code Playgroud)

定义时t_ioctl如下:

static long t_ioctl(struct file *filep, unsigned int cmd, unsigned long input){
Run Code Online (Sandbox Code Playgroud)

我收到警告:

warning: 't_ioctl' defined but not used
Run Code Online (Sandbox Code Playgroud)

但是当它达到t_readt_write静态和非静态函数声明不会导致警告.例如:

static ssize_t t_read(struct file *filp, char __user * buf, size_t count, loff_t * f_pos);
Run Code Online (Sandbox Code Playgroud)

为什么我在一个案例而不是另一个案件中得到警告?

Lan*_*son 5

很可能你在同一个文件中有这样的定义:

static struct file_operations fileops = {
    .read     = t_read,
    .write    = t_write,
    /* etc. ... */
};
Run Code Online (Sandbox Code Playgroud)

你错过了

.compat_ioctl = t_ioctl, /* or .ioctl/.unlocked_ioctl, depending on version etc. */
Run Code Online (Sandbox Code Playgroud)