从内核空间执行 ioctl
我正在编写一个需要在另一个设备上执行 ioctl 的内核驱动程序。我意识到这不是处理代码的最佳方法,但这只是目前的临时修复。我从函数中的 ioctl 调用返回错误代码 -22(无效参数),但我不知道参数可能有什么问题。这是代码的相关部分。
#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 有关,但我什至不确定如何获取正确的 inode(如果它不是从用户空间传递给 ioctl 的 inode)。
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;
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您现在已经深陷“不要这样做”的黑客领域,因此向 GPIO 驱动程序添加一些 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.
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