linux - 热插拔设备驱动模块的问题

标签 linux usb

我正在编写一个模块,当您插入 USB 鼠标时,它会打印“hello world”。当我插入鼠标时出现问题,dmesg 打印六次以下消息:

[ 7367.238560] helwor_mod: disagrees about version of symbol module_layout

这是我的代码

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/usb.h>
#include <linux/usb/input.h>
#include <linux/hid.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Isaac Lleida <isakyllr@opmbx.org>");
MODULE_VERSION("0.1");


static struct usb_device_id usb_mouse_id_table [] = {
    { USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,
            USB_INTERFACE_PROTOCOL_MOUSE) },
    { }
};
MODULE_DEVICE_TABLE(usb, usb_mouse_id_table);


static int mouse_probe(struct usb_interface *iface,
    const struct usb_device_id *id)
{
    pr_info("Hello World!");
    return 0;
}

static void mouse_disconnect(struct usb_interface *iface)
{
    pr_info("Bye World!");
}


static struct usb_driver mouse_driver = {
    .name  = "usbmouse",
    .probe = mouse_probe,
    .disconnect = mouse_disconnect,
    .id_table = usb_mouse_id_table,
};
module_usb_driver(mouse_driver);

static int __init hello_init(void)
{
    int res = 0;
    res = usb_register(&mouse_driver);

    if(res)
        pr_err("usb_register failed with error %d", res);
    return res;
}

static void __exit hello_exit(void)
{
    pr_debug("USB Mouse Removed...");
    usb_deregister(&mouse_driver);
}

我google了一下午,还是不知道怎么解决。 我希望有人能帮助我,谢谢。

最佳答案

这是相关的: module_layout version incompatibility

我敢打赌,您用于编译模块的内核源代码(头文件)来自与您正在运行的版本不同的内核版本。

关于linux - 热插拔设备驱动模块的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23484528/

相关文章:

linux - 将文件中的纪元时间转换为 dd/mm/yy

c++ - 简单的 USB 主机堆栈

c# - 可移植 C# IDE?

c# - 如何在 C# 中从 USB 闪存驱动器获取 VID/PID?

linux - Oracle select 不返回 sqlplus 下的所有列

linux - 如何让system()函数畅通无阻?

Java 1.7ea : Files. probeContentType(path) 返回 null

c - 需要像 read() 这样的函数将整数数据读入缓冲区并获得与 read() 相同的缓冲区值

c - 使用 C 程序(fopen、fread、fwrite)扫描 USB 驱动器

linux - 如何获取USB存储设备的设备名称?