On a running Linux system, I want to know which device driver module created a particular sysfs entry. Is it possible to know? I know I can grep for relevant strings in the kernel source and try to identify. But, is there a way without doing that?
You can find which driver has created a sysfs entry by going through its source. If the driver uses device_create_file()/device_remove_file() in its init/exit sequences respectively then you can be sure a sysfs attribute file has been created by the driver. You can also find DEVICE_ATTR(_name, _mode, _show, _store) macro in the source to find out what functionality is provided by the sysfs file. Usually you can either cat the file or echo a string to it. A cat /sys/.../file, will correspond to the _show function and an echo /sys/.../file will correspond to the _store function mentioned in the macro.
This is not a universal way, but in many cases sysfs files are symlinks. Looking at symlink path, you probably can realize which module it belongs to.
root@host:~# ls -l /sys/class/hwmon/hwmon5
lrwxrwxrwx 1 root root 0 Feb 27 2021 /sys/class/hwmon/hwmon5 -> ../../devices/platform/iio-hwmon/hwmon/hwmon5
© 2022 - 2024 — McMap. All rights reserved.