当前位置: 技术问答>linux和unix
大家给看一下,这个驱动程序哪块有问题,谢谢了
来源: 互联网 发布时间:2016-07-05
本文导语: 这个是驱动程序,我是动态加载到内核中的--insmod 为了找到问题,我把其他的地方都去掉了,现在是我想通过copy_to_user把 key_values的值传到用户空间,但一直有问题, 大家给看一下是哪里有问题,刚刚接触驱动,请...
这个是驱动程序,我是动态加载到内核中的--insmod
为了找到问题,我把其他的地方都去掉了,现在是我想通过copy_to_user把 key_values的值传到用户空间,但一直有问题,
大家给看一下是哪里有问题,刚刚接触驱动,请大家帮忙看看。
一 驱动程序代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "armbuttons" /* 加载模式后,执行”cat /proc/devices”命令看到的设备名称 */
#define BUTTON_MAJOR 236 /* 主设备号 */
static volatile int key_values [] = {1, 1, 0, 0, 0, 0};
static int share_button_open(struct inode *inode, struct file *file)
{
return 0;
}
static int share_button_read(struct file *filp, char __user *buff,size_t count, loff_t *offp)
{
unsigned long err;
err = copy_to_user(buff, (const void *)key_values, min(sizeof(key_values), count));
memset((void *)key_values, 0, sizeof(key_values));
return err ? -EFAULT : min(sizeof(key_values), count);
}
static struct file_operations share_buttons_fops = {
.owner = THIS_MODULE,
.open = share_button_open,
.read = share_button_read,
};
static int __init share_buttons_init(void)
{
int ret;
ret = register_chrdev(BUTTON_MAJOR, DEVICE_NAME,&share_buttons_fops);
if (ret
为了找到问题,我把其他的地方都去掉了,现在是我想通过copy_to_user把 key_values的值传到用户空间,但一直有问题,
大家给看一下是哪里有问题,刚刚接触驱动,请大家帮忙看看。
一 驱动程序代码
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define DEVICE_NAME "armbuttons" /* 加载模式后,执行”cat /proc/devices”命令看到的设备名称 */
#define BUTTON_MAJOR 236 /* 主设备号 */
static volatile int key_values [] = {1, 1, 0, 0, 0, 0};
static int share_button_open(struct inode *inode, struct file *file)
{
return 0;
}
static int share_button_read(struct file *filp, char __user *buff,size_t count, loff_t *offp)
{
unsigned long err;
err = copy_to_user(buff, (const void *)key_values, min(sizeof(key_values), count));
memset((void *)key_values, 0, sizeof(key_values));
return err ? -EFAULT : min(sizeof(key_values), count);
}
static struct file_operations share_buttons_fops = {
.owner = THIS_MODULE,
.open = share_button_open,
.read = share_button_read,
};
static int __init share_buttons_init(void)
{
int ret;
ret = register_chrdev(BUTTON_MAJOR, DEVICE_NAME,&share_buttons_fops);
if (ret