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

/**********************************************
*文 件 名: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. leetcode二分查找问题整理

    自从做完leetcode上的三道关于二分查找的题后,我觉得它是比链表找环还恶心的题,首先能写出bugfree代码的人就不多,而且可以有各种变形,适合面试的时候不断挑战面试者,一个程序猿写代码解决问题的 ...

  2. php.ini的配置

    一.user_agent ini_set('user_agent','Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)') user_agent,再 ...

  3. Makefile中指示符“include”、“-include”和“sinclude”的区别

    转:http://www.cnblogs.com/xmphoenix/archive/2012/02/22/2363335.html 指示符“include”.“-include”和“sinclude ...

  4. sql查询行转列

    昨天下午碰到一个需求,一个大约30万行的表,其中有很多重复行,在这些行中某些字段值是不重复的. 比如有ID,NAME,CONTRACT_id,SALES,PRODUCT等,除了PRODUCT字段,其余 ...

  5. iOS 开发之— NSURLProtocol

    最近在项目里由于电信那边发生dns发生域名劫持,因此需要手动将URL请求的域名重定向到指定的IP地址,但是由于请求可能是通过NSURLConnection,NSURLSession或者AFNetwor ...

  6. 什么是CSS清除浮动?

    在非IE浏览器(如Firefox)下,当容器的高度为auto,且容器的内容中有浮动(float为left或right)的元素,在这种情况下,容器的高度不能自动伸长以适应内容的高度,使得内容溢出到容器外 ...

  7. solr中竞价排名实现

    转载:http://mxsfengg.iteye.com/blog/308335 通常,lucene只返回与用户查询相关的文档,搜索的结果,跟lucene对文档评分有关.而在现实的查询中,我们有些时候 ...

  8. UIView 的transitionFromView方法实现视图切换

    #import "ViewController.h" @interface ViewController () @property (strong, nonatomic) IBOu ...

  9. Android 高级UI设计笔记13:Gallery(画廊控件)之 循环显示图像

    1. 循环显示图像的原理  循环显示有些类似于循环链表,最后一个结点的下一个结点又是第1个结点.循环显示图像也可以模拟这一点. 也许细心的读者从上一节实现的ImageAdapter类中会发现些什么.对 ...

  10. 【LeetCode 1】算法修炼 --- Two Sum

    Question: Given an array of integers, find two numbers such that they add up to a specific target nu ...