从内核空间执行的ioctl [英] Performing an ioctl from the kernel-space

查看:694
本文介绍了从内核空间执行的ioctl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写需要到另一台设备上执行的ioctl内核驱动程序。我知道这不是处理code的最佳方式,但是这仅仅是一个临时的解决办法现在。我从我的函数调用ioctl找回错误code -22(参数无效),但我看不出有什么可能是错误的论点。以下是code的相关部分。

I'm writing a kernel driver that needs to perform an ioctl on another device. I realize this is not the best way to handle the code, but this is just a temporary fix for now. I'm getting back error code -22 (Invalid argument) from my ioctl call in the function, but I don't see what could be wrong with the arguments. Here are the relevant sections of code.

#define GPIO74 "/dev/gpio/74"

struct file* gpio74FD;
  .
  .
  .
gpio74FD = filp_open(GPIO74,O_RDWR,0)
  .
  .
  .
int device_ioctl(struct inode* inode,struct file *file, unsigned int ioctl_num,unsigned long ioctl_param)
{
  .
  .
  .
ret_val = gpio74FD->f_op->ioctl(inode, gpio74FD, GPIO_CONFIG_AS_INP, 0); //returns error code -22 (Invlaid Argument)
  .
  .
  .
return ret_val;
}

我怀疑它可能是与路过此处不正确的索引节点,但即时通讯甚至不知道如何得到正确的inode如果它不是一个通过从用户空间IOCTL。

I suspect it may have something to do with passing the incorrect inode here, but im not even sure how to get the correct inode if its not the one passed to ioctl from the user space.

推荐答案

既然你现在在非常深的不这样做黑客领土,添加一些的printk到GPIO驱动程序可以给你一些有价值的信息。

Since you are now very deep in "don't do that" hacking territory, adding a few printk to the gpio driver could give you some valuable info.

另一个选项是避免这种可怕的黑客攻击,并切换到低害之一:
添加导出函数到GPIO驱动程序,您可以从自己的模块调用

Another options is to avoid this horrible hack, and switch to a less harmful one : add an exported function to the gpio driver, that you can call from your own module

这篇关于从内核空间执行的ioctl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆