I am trying to add a new IIO sensor driver to the kernel source and build it into the existing kernel. In particular I am trying to utilize the IIO device drivers from ST in the LSM6DS family that are multi-functional IIO devices. This is not uncommon as many IIO devices on the market support several functions within the same device. These devices work by having a core framework that allows access to multiple features of the chip all using the same hardware interface. They then allocate (iio_device_alloc) and register (iio_device_register) multiple IIO devices that have the core device as the parent of the IIO devices.
However, the changes by NVIDIA here in the latest 4.9 kernel nv-tegra: linux-4.9: iio: core: add Android L support for sensors to industrialio-core.c cause issues with multi-function IIO device drivers that have a single parent device. The changes appear to be NVIDIA specific and related to the NVS (NVIDIA Sensor) support and do not exist in upstream kernels, and are possibly only for Android.
I have tested with JetPack 4.4 Developer Preview (L4T R32.4.2) release and I get the following kernel error from the industrialio-core.c in iio_device_register() @ sysfs_create_link() line 1597 when the second iio_dev gets registered with the same parent:
sysfs: cannot create duplicate filename ‘/devices/3180000.i2c/i2c-2/2-006a/iio_device’
WARNING: CPU: 5 PID: 7506 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x68/0x88
It appears the problem exists on all version of L4T that are using the 4.9 kernel.
The extra call to sysfs_create_link() that NVIDIA added to the industrialio-core.c iio_device_register() function, does not seem necessary. All it looks like it is doing is creating a link
iio_device -> iio:deviceX in the parent device’s sysfs directory, which does not seem necessary or that helpful.
Can the calls to sysfs_create_link/sysfs_delete_link() that NVIDIA added in industrialio-core.c be completely removed?
Or if the symbolic link needs to be created for some Android API, can the error condition on failure at least be downgraded from an error condition that causes a failed iio_device_register() to just a warning message?