1
votes

I am writing a kernel module that needs to perform the equivalent of an ioctl on another device (the "target" device). The target device is an input device which is mounted at dev/something.

I know that one way to do this would be to open the target device from my module and then just call ioctl as described in this SO question. However I understand that this is a hack and that there is probably a better way.

Is it possible to retrieve to a struct *input_dev from my kernel module, given either the target module name or the mount point of the target device?

1
Why needs your code need be a kernel module? - CL.
Would it help if it was built into the kernel instead? I see the same problem. - Grodriguez
Sorry; why needs your code be in the kernel? - CL.
Because it is using kernel timers. But this is not relevant to the actual question. - Grodriguez
Timer are also available in user space. - CL.

1 Answers

1
votes

Option1: 1st option of opening your target device node is the better option. I have done same 2-3 times in past. But here it works only after file system get mounted and then your test module can open that module.

struct file* test;
test = filp_open("/dev/targetDevice",O_RDWR,0);

Now in call ioctl

test->f_op->unlocked_ioctl(test,IOCTL_MACRO,params);

Option2:

Another solution i am thinking is, If target module is under your control then from that target module make that pointer as EXPORT_SYMBOL() and access that in your test module.

Option3:

Another option is instead of exporting pointer of that struct just export any function of target module and perform your required from that task.