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

/**********************************************
*文 件 名: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. oc-22-sel

    /** sel: 1.作用:包装方法 2.格式:typedef struct objc_selector *SEL; 3.用法: SEL 名称 = @selector(方法); 调用形式: [对象 p ...

  2. LINUX 内存结构

    1.页框管理 Linux采用4KB页框大小作为标准的内存分配单元.内核必须记录每个页框的状态,这种状态信息保存在一个类型为page的页描述符中,所有的页描述存放在mem_map中.virt_to_pa ...

  3. c#无损高质量压缩图片

    这几天在做同城交友网www.niyuewo.com时遇到的一个问题,如何将会员的头像压缩,在网上搜索整理如下:在此也感谢医药精(www.yiyaojing.com)站长的帮忙 /// <summ ...

  4. C# 中传递多个参数给多线程

    1.方式一:使用ParameterizedThreadStart委托 如果使用了ParameterizedThreadStart委托,线程的入口必须有一个object类型的参数,且返回类型为void. ...

  5. C++实现日期转换类DateTime

    概述 工作中我们在网络传输时使用time_t来传输时间,在显示时使用字符串来显示,下面是一个日期转换类的实现,方便以后使用: // DateTime.hpp #ifndef _DATETIME_H # ...

  6. PHP.12-PHP-设计文件上传类

    设计文件上传类 [PHP参数详解]{文件上传} ********************** *#构造方法编写 ********************** 此种传参方法规定必须用户必须按响应位置输入 ...

  7. kafka java客户端编程

    kafka_2.10-0.8.1.1 maven <dependencies> <dependency> <groupId>org.apache.kafka< ...

  8. docker 中运行 sshd 服务

    创建Dockerfile # sshd # # VERSION 0.0.2 FROM ubuntu:14.04 MAINTAINER admln <admln@docker.com> RU ...

  9. Phone List

    Problem Description Given a list of phone numbers, determine if it is consistent in the sense that n ...

  10. NSTimer定时器的用法

    #import "ViewController.h" @interface ViewController () { NSTimer *countDownTimer; int cou ...