0

I've made a driver that is an Industrial I/O (IIO) "producer" (it provides ADC readings). I've compiled it as a module. I've got another driver that is an IIO "consumer" that uses an ADC input from the first driver (it calls iio_channel_get() in its probe() function).

Both these drivers are compiled as modules, and they work fine together. But I've found that it's possible to rmmod the first driver, even when the second driver is loaded and thus using its ADC, which seems surprising because it's "in use" by the second driver. What would be great is to prevent the first driver being unloaded while the second driver is using it. That is, increment the first module's refcnt when the second driver calls iio_channel_get(), and decrement the refcnt when the second driver calls iio_channel_release(). This would be conceptually similar to a module for a char device, which has its refcnt incremented for each process that has it open—so it can't be unloaded until all processes have closed the char device file open.

But I can't see a way to achieve this for an IIO producer (e.g. I can't see any ops function that might be called when the second driver calls iio_channel_get()). How could that be done?

Note, this is not a module dependency in the classical sense, where one module depends on functions/symbols provided by another module. It's an IIO consumer/producer dependency. The dependency from one to the other is hardware-specific, and is specified in the device tree for the hardware. On different hardware, the consumer/producer dependency could involve a different IIO producer module.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
Craig McQueen
  • 41,871
  • 30
  • 130
  • 181
  • Possible duplicate of [External Linux kernel module dependencies](http://stackoverflow.com/questions/2237871/external-linux-kernel-module-dependencies) – Claudio Nov 25 '15 at 08:38
  • @Claudio: `depmod` has nothing common with preventing module unloading. – Tsyvarev Nov 25 '15 at 09:10
  • Do you set `.driver_module` field of `struct iio_info` to `THIS_MODULE` in producer? – Tsyvarev Nov 25 '15 at 09:35
  • @Tsyvarev: yes I do. – Craig McQueen Nov 25 '15 at 22:27
  • @Claudio: no, it's not a module dependency (where one module depends on functions/symbols provided by another module), it's an IIO consumer/producer dependency. The dependency from one to the other is hardware-specific, and is specified in the device tree for the hardware. – Craig McQueen Nov 25 '15 at 22:31

0 Answers0