How to deal with cdev_init and proc_create at the same time?

Viewed 31

I know that in linux kernel 5.6 or higher I should use proc_ops to replace file operations, but now I need to use cdev_init() and proc_create() for the same structure, how should I do?

#if LINUX_VERSION_CODE <= KERNEL_VERSION(5, 6, 0)
static struct file_operations ilitek_fops = {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
    .unlocked_ioctl = ilitek_file_ioctl,
#else
    .ioctl = ilitek_file_ioctl,
#endif
    .read = ilitek_file_read,
    .write = ilitek_file_write,
    .open = ilitek_file_open,
    .release = ilitek_file_close,
};
#else
static struct proc_ops ilitek_fops = {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
    .proc_ioctl = ilitek_file_ioctl,
#else
    .ioctl = ilitek_file_ioctl,
#endif
    .proc_read = ilitek_file_read,
    .proc_write = ilitek_file_write,
    .proc_open = ilitek_file_open,
    .proc_release = ilitek_file_close,
};
#endif

cdev_init(&ilitek_dev.cdev, &ilitek_fops);
...
proc_create("ilitek_ctrl", ILITEK_DEVICE_NODE_PERMISSON, NULL, &ilitek_fops);

As shown above, I cannot pass the structure to both functions at the same time.

0 Answers
Related