今天在写一个简单的内核测试模块的时候出现了一个挺奇怪的问题,网上查了一下也没人解决,自己试了好久终于解决了,所以分享出来供大家参考,先贴出源码:

/**********************************************
*文 件 名:hello.c
*文件描述:给模块传参
*创 建 人:Wang.J,2013.10.26
*版 本 号:0.1
*修改记录:
**********************************************/
#include <linux/kernel.h>
#include <linux/module.h> MODULE_LICENSE("Dual BSD/GPL"); //定义参数
int myint = 100;
char *mystring = "This is name!";
short myshort = 10;
long mylong = 100;
int array[2] = {0}; //模块参数声明
module_param(myshort, short, 0555);
module_param(myint, int, 0444);
module_param(mylong, long, 0444);
module_param(mystring, charp, 0777);
module_param_array(array, int, NULL, 0777); /*==============================================
*函 数 名:hello_module_init
*参 数:void
*功能描述:注册模块
*返 回 值:成功,返回0
*异 常:
*创 建 人:Wang.J,2013.10.26
*修改记录:
==============================================*/
static int hello_module_init(void)
{
int ret = 0;
int i; printk("This shirt is %d\n", myshort);
printk("This int is %d\n", myint);
printk("This long is %ld\n", mylong);
printk("This string is %s\n", mystring);
for (i = 0; i < sizeof(array)/sizeof(array[0]); i++) {
printk("The %d of number is %d\n", i, array[i]);
} return ret;
} /*==============================================
*函 数 名:hello_module_cleanup
*参 数:void
*功能描述:卸载函数
*返 回 值:void
*异 常:
*创 建 人:Wang.J,2013.10.26
*修改记录:
==============================================*/
static void hello_module_cleanup(void)
{
printk("hello_module_cleanup\n");
} module_init(hello_module_init);
module_exit(hello_module_cleanup); //模块声明与描述
MODULE_AUTHOR("Wang.J");
MODULE_DESCRIPTION("hello This");
MODULE_ALIAS("别名");
MODULE_SUPPORTED_DEVICE("内存模拟");

编译错误提示:

make -C /lib/modules/3.2.0-29-generic-pae/build M=/home/linux/driver/experiment/ex04
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
  LD      /home/linux/driver/experiment/ex04/built-in.o
  CC [M]  /home/linux/driver/experiment/ex04/hello.o
/home/linux/driver/experiment/ex04/hello.c:24:1: error: negative width in bit-field ‘<anonymous>’
/home/linux/driver/experiment/ex04/hello.c:25:2: error: negative width in bit-field ‘<anonymous>’
make[2]: *** [/home/linux/driver/experiment/ex04/hello.o] Error 1
make[1]: *** [_module_/home/linux/driver/experiment/ex04] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-29-generic-pae'
make: *** [modules] Error 2

最后发现是module_param声明中有关权限的问题,这个权限不能是可写的.也就是说这个权限只能是rx的任意组合,5或4或1.因为模块运行在内核空间中,权限要求比较严格.

所以将

module_param(mystring, charp, 0777);

module_param_array(array, int, NULL, 0777);

改成

module_param(mystring, charp, 0555);

module_param_array(array, int, NULL, 0444);

就可以了.

编译内核模块出现error: negative width in bit-field 错误的更多相关文章

  1. ubuntu编译内核模块报错:Required key not available 的解决

    系统为ubuntu18.04, 在编译内核模块insmod helloworld.ko的时候提示如下错误. 出现此问题的原因是,Ubuntu Kernel 使用 EFI_SECURE_BOOT_SIG ...

  2. OpenSceneGraph 编译 error LNK2019:unresolved external symbol 错误

    在编译 OpenSceneGraph 的一个简单示例时, #include <osgViewer/Viewer> #include <osgDB/ReadFile> void ...

  3. maven 项目编译时候提示:Error building POM (may not be this project's POM).

    编译时候提示Error building POM (may not be this project's POM)的错误,具体信息如下: [0] 'dependencies.dependency.ver ...

  4. wince6.0 编译报错:"error C2220: warning treated as error - no 'object' file generated"的解决办法

    内容提要:wince6.0编译报错:"error C2220: warning treated as error - no 'object' file generated" 原因是 ...

  5. android stdio 编译项目报Error:Failed to find target with hash string 'android-24

    android stdio 编译项目报Error:Failed to find target with hash string 'android-24 查看已有的SDK 设置项目的sdk为 25 an ...

  6. fedora/centos下gcc编译出现gcc: error trying to exec ‘cc1plus’: execvp: No such file or directory

    fedora/centos下gcc编译出现gcc: error trying to exec 'cc1plus': execvp: No such file or directory解决办法 翻译自: ...

  7. 升级到JDK8,编译时发生 Error:java: java.lang.ExceptionInInitializerError

    编译的时候出现这个问题.使用1.7的jdk没问题,但是由于po主的项目中,使用了java8编写的代码,解决java8兼容问题成为解决这个问题的首选方案. 这个日志太过简单,只告知一个异常信息,这个异常 ...

  8. python psutil 编译中断。 error: command 'gcc' failed with exit status 1

    error info [root@chenbj psutil-2.0.0]# python setup.py install running install running bdist_egg run ...

  9. 在高通平台Android环境下编译内核模块【转】

    本文转载自:http://blog.xeonxu.info/blog/2012/12/04/zai-gao-tong-ping-tai-androidhuan-jing-xia-bian-yi-nei ...

随机推荐

  1. 云服务器 ECS Linux 服务器修改时区的两种方式

    在云服务器 ECS Linux 系统中,以 Centos6.5 为例,可以通过如下两种方式,修改系统时区: 可以使用命令 tzselect,修改时区.操作示例: [root@localhost ~]# ...

  2. ecshop被加入了黑链

    朋友一个ecshop网站被攻击了,查看代码如下: <?php $password = "1";//设置密码 error_reporting(E_ERROR); header( ...

  3. Spring MVC @RequestMapping Annotation Example with Controller, Methods, Headers, Params, @RequestParam, @PathVariable--转载

    原文地址: @RequestMapping is one of the most widely used Spring MVC annotation.org.springframework.web.b ...

  4. seleniu IDE 点点滴滴

    在使用selenium webdriver +python 的过程中遇见了许多的问题,这些问题在网上都没有找到很好的答案,后来在看selenium IDE的时候发现这里面有很好的解决方法,写写.记记. ...

  5. Jquery 扩展方法

    $.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效. 如扩展$.fn.abc() 那么你可以这样子:$("#div").abc(); 通常使 ...

  6. nodejs的mysql模块学习(七)连接池事件

    连接池事件 connection 当建立连接的时候就会触发 pool.on('connection' function(connection){ connection.query('SET SESSI ...

  7. iOS开发libWeChatSDK.a(WXApiObject.o)' does not contain bitcode.

    在使用微信分享的时候可能会报错, 报错如下: ld: '/Users/gti/Documents/********/Lib/SDKExport/libWeChatSDK.a(WXApiObject.o ...

  8. 一分钟加入google站内搜索代码

    一分钟加入google站内搜索代码| 一分钟加入google站内搜索代码|只有7行最精简.网上有很多 google 站内搜索代码,但是出于某些目的,很多都加入了多余的代码,从seo的角度来讲,是很不优 ...

  9. Apps Vol53

    Android 內購破解 Freedom 軟件 iOS破解軟件IAPFree 能偽造UID   IAPFree : 系統已經JB Cydia加入作者的軟件源 Cydia.crazydoraemon.c ...

  10. django 学习-17 Django会话Session

    session   类似于字典的一个对象,是可读可写的 跟cookie的变化不大而且还显得简单 在这里我只说一下改变的地方 1.vim blog/views.py if uf.is_valid():  ...