【问题标题】:Error compiling kernel module for simple device driver为简单设备驱动程序编译内核模块时出错
【发布时间】:2012-06-15 09:06:52
【问题描述】:

我有这样的功能:

void cleanup_module(void)
{
    /* 
     * Unregister the device 
     */
    if(unregister_chrdev(Major, DEVICE_NAME)<0) 
        printk(KERN_ALERT "Error in unregister_chrdev:\n");
}

和错误:

/home/student/kernel/hello.c: In function ‘cleanup_module’:
/home/student/kernel/hello.c:39:2: error: void value not ignored as it ought to be

这一行是带有 if 语句的那一行。你知道我做错了什么吗?

【问题讨论】:

    标签: c device-driver kernel-module


    【解决方案1】:

    这意味着unregister_chrdev 没有返回值(它是void),但是你把它放在了一个if 中。也就是说,您正在使用一个应该被忽略的 void 值。因此出现错误消息。

    查看this question,它询问为什么将返回值更改为 void。

    【讨论】:

      【解决方案2】:

      基于this unregister_chrdev() 曾经返回一个int 但它的返回类型更改为void 因为返回的值没有意义。从发布的代码中完全删除if

      unregister_chrdev(Major, DEVICE_NAME);
      

      【讨论】:

        【解决方案3】:

        错误表明unregister_chrdev() 函数是void 类型函数,即它什么也不返回。但是,您正在使用 &lt; 运算符检查其返回值。

        【讨论】:

          猜你喜欢
          • 2018-05-23
          • 2021-09-09
          • 1970-01-01
          • 2012-05-11
          • 2018-07-29
          • 1970-01-01
          • 2015-06-01
          • 2013-11-12
          • 2023-04-03
          相关资源
          最近更新 更多