天嵌 ARM开发社区

 找回密码
 注册
查看: 2032|回复: 3

请看我的内核初始化函数,

[复制链接]
wang12zhedi 发表于 2012-9-15 16:08:22 | 显示全部楼层 |阅读模式
函数如下
int major;
static int __init butt_led_init(void)
{
   major = register_chrdev(0,DEVICE_NAME,&butt_led_fops);
   if(major < 0)
           printk(DEVICE_NAME "can't register butt_led");

    butt_led_class = class_create(THIS_MODULE,"butt_led");
   
    butt_led_class_dev = device_create(butt_led_class,NULL,MKDEV(major,0),NULL,"butt_led_dev");
    //printk("major =  %d\n",major);
         return major;       
}
,加载后总是提示
sys_init_module: 'but_led'->init suspiciously returned 252, it should follow 0/-E convention
sys_init_module: loading module anyway...
[<c002b700>] (unwind_backtrace+0x0/0xdc) from [<c0064968>] (sys_init_module+0x10c/0x18c)
[<c0064968>] (sys_init_module+0x10c/0x18c) from [<c0025d60>] (ret_fast_syscall+0x0/0x2c)
[root@myself /lx]#nit suspiciously returned 252, it should follow 0/-E conventio
n
,我知道这是提示没有返回值,可是我有用return返回major呀,如果最后改成return 0,或者在return major前加上  printk("major =  %d\n",major);就可以正常加载,这是怎么回事,经检查major=252,没发现什么冲突呀,求解
亚瑟王 发表于 2012-9-15 18:08:41 | 显示全部楼层
你的驱动有没有添加这个声明:MODULE_LICENSE("GPL");
 楼主| wang12zhedi 发表于 2012-9-15 19:17:03 | 显示全部楼层
亚瑟王 发表于 2012-9-15 18:08
你的驱动有没有添加这个声明:MODULE_LICENSE("GPL");

有的 ,下边是我自己的驱动源码:刚学习驱动不久,代码写的不怎么样,包涵
刚又试过还是出现同样的问题
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/irq.h>
#include <asm/irq.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <mach/regs-gpio.h>
#include <mach/hardware.h>
#include <linux/platform_device.h>
#include <linux/cdev.h>
#include <linux/miscdevice.h>
#include <linux/device.h>

#define DEVICE_NAME "butt_led"

static struct class *butt_led_class;
static struct class_deviced *butt_led_class_dev;


static unsigned int gpio_table[]=
{
S3C2410_GPB5,
S3C2410_GPB6,
S3C2410_GPB7,
S3C2410_GPB8,

};
static unsigned int gpio_conf_table[]=
{
S3C2410_GPB5_OUTP,
S3C2410_GPB6_OUTP,
S3C2410_GPB7_OUTP,
S3C2410_GPB8_OUTP,
};

static int butt_led_open (struct inode *inode, struct file *file)
  {
     int i;
     for(i=0;i<4;i++)
        s3c2410_gpio_cfgpin(gpio_table,gpio_conf_table);

     printk("but_led open \n");
     return 0;         
  }

static int butt_led_ioctl (struct inode *inode,struct file *file,unsigned int cmd,unsigned long arg)
{
  s3c2410_gpio_setpin(gpio_table[arg],cmd);
  printk("butt_led_ioctl\n");
  return 0;
}

static struct file_operations butt_led_fops = {
        .owner = THIS_MODULE,
        .open = butt_led_open,
        .ioctl = butt_led_ioctl,
};

int major;
static int __init butt_led_init(void)
{
   major = register_chrdev(0,DEVICE_NAME,&butt_led_fops);
   if(major < 0)
           printk(DEVICE_NAME "can't register butt_led");

    butt_led_class = class_create(THIS_MODULE,"butt_led");
   
    butt_led_class_dev = device_create(butt_led_class,NULL,MKDEV(major,0),NULL,"butt_led_dev");
    //printk("major =  %d\n",major);
         return major;       
}

static void __exit butt_led_exit(void)
{
   unregister_chrdev(major,DEVICE_NAME);
   device_unregister(butt_led_class_dev);
   class_destroy(butt_led_class);
   
}

module_init(butt_led_init);
module_exit(butt_led_exit);
MODULE_LICENSE("GPL");
另外,编译时总是提示两个警告,也请看看
make -C /home/a123/lx/linux-2.6.30.4 M=`pwd` modules
make[1]: Entering directory `/home/a123/lx/linux-2.6.30.4'
  CC [M]  /mnt/hgfs/Ub/but_led/but_led.o
/mnt/hgfs/Ub/but_led/but_led.c: In function 'butt_led_init':
/mnt/hgfs/Ub/but_led/but_led.c:72: warning: assignment from incompatible pointer type
/mnt/hgfs/Ub/but_led/but_led.c: In function 'butt_led_exit':
/mnt/hgfs/Ub/but_led/but_led.c:80: warning: passing argument 1 of 'device_unregister' from incompatible pointer type
  Building modules, stage 2.
make[2]: Warning: File `/mnt/hgfs/Ub/but_led/but_led.o' has modification time 1.6 s in the future
  MODPOST 1 modules
  LD [M]  /mnt/hgfs/Ub/but_led/but_led.ko
make[2]: warning:  Clock skew detected.  Your build may be incomplete.
make[1]: Leaving directory `/home/a123/lx/linux-2.6.30.4'
其中72行代码是 butt_led_class_dev = device_create(butt_led_class,NULL,MKDEV(major,0),NULL,"butt_led_dev");
80行代码是 device_unregister(butt_led_class_dev);
亚瑟王 发表于 2012-9-17 10:53:50 | 显示全部楼层
wang12zhedi 发表于 2012-9-15 19:17
有的 ,下边是我自己的驱动源码:刚学习驱动不久,代码写的不怎么样,包涵
刚又试过还是出现同样的问题
...

你不要开好几个帖子来说同一件事情,你说的警告问题已经给你回复了,C语言的强制转换可以随便找本C语言的书来学习一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

i.MX8系列ARM cortex A53 M4 工控板上一条 /1 下一条

Archiver|手机版|小黑屋|天嵌 嵌入式开发社区 ( 粤ICP备11094220号 )

GMT+8, 2024-5-18 04:51 , Processed in 1.046875 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表