1

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?

Community
  • 1
  • 1
Grodriguez
  • 21,501
  • 10
  • 63
  • 107

1 Answers1

1

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.

Jeegar Patel
  • 26,264
  • 51
  • 149
  • 222
  • Can you show some example code? (btw the target module is not under my control) – Grodriguez Jul 22 '14 at 11:15
  • @Grodriguez if can not do changes in target module then my both suggestion are not useful. – Jeegar Patel Jul 22 '14 at 11:19
  • Why would I need to have control over the target module in order to open the device node? – Grodriguez Jul 22 '14 at 11:19
  • For opening target device node you do not need to change anything in target device driver but for option2 and option3 i suggested in that you need to change some code in target device driver file. – Jeegar Patel Jul 22 '14 at 11:28
  • Do you have any example code showing how to open the device node and perform a ioctl call? I found that ioctl needs an fd, sys_open which returns an fd is no longer exported, and filp_open returns a file* instead. – Grodriguez Jul 22 '14 at 11:29