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

/**********************************************
*文 件 名: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. 使用Linux的mail命令发送邮件

    由于经常工作在linux下,所以很多时候需要将自己工作的报告或其他有用的东东发送给相关的人,所以花时间研究了一下在linux下如何发送mail.我们通常能用到下面3中发送方式: 1. 使用Shell当 ...

  2. php 日期

    获取两个日期之间的间隔天列表: $begin = new DateTime( '2012-08-0' );$end = new DateTime( '2012-08-31' );$end = $end ...

  3. alljoyn连接时-fno-rtti选项测试结果

    以AllJoyn自带的chat示例在pc上测试结果如下: libAllJoyn.a编译选项 Chat编译选项 测试结果 -Wall -Werror=non-virtual-dtor -pipe -st ...

  4. LeetCode10 Regular Expression Matching

    题意: Implement regular expression matching with support for '.' and '*'. '.' Matches any single chara ...

  5. hql & mysql 札记

    最近在某D实习,刚去就开始各种写HQL,碰壁很多次. 几个知识点记录一下,逐个攻破. sql 中的case when, 选择循环的写法.(http://www.cnblogs.com/zengen/a ...

  6. ASP.NET MVC与WebForm区别

    [转贴一] 使用ASP.NET MVC框架,创建默认项目,第一直观感觉就是地址都是Rewrite过的.对源码和配置文件稍加分析不难看出,MVC使用了httpModules来拦截地址请求,具体用到了Sy ...

  7. putty ssh login linux

    (1) in linux $ ssh-keygen -t dsa $ cd .ssh $ cat id_dsa.pub > authorized_keys $ chmod 600 authori ...

  8. 【Android 界面效果41】Matrix 与 ColorMatrix

    Matrix: 简单用法就是直接使用它的setXX()方法 而高级一点来理解他就是去理解一个线性矩形 首先我们来认识线性矩形:(用画图粗略地画不要见怪) 分析: 那还有一组 MRERSP_0 MRER ...

  9. Hadoop学习笔记(5) ——编写HelloWorld(2)

    Hadoop学习笔记(5) ——编写HelloWorld(2) 前面我们写了一个Hadoop程序,并让它跑起来了.但想想不对啊,Hadoop不是有两块功能么,DFS和MapReduce.没错,上一节我 ...

  10. IOS设计模式六大法则

    设计模式的六大原则 单一职责原则 定义:不要存在多于一个导致类变更的原因.通俗的说,即一个类只负责一项职责 问题由来:类T负责两个不同的职责:职责P1,职责P2.当由于职责P1需求发生改变而需要修改类 ...