From 7e976f1325e55b5e26a63c8f9c7af0cb9aac3aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Lyson=C4=9Bk?= Date: Tue, 6 Nov 2018 15:49:11 +0100 Subject: [PATCH] libsensors: Treat devices without a known ancestor bus as virtual MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently only hwmon devices that don't have a parent device are treated as virtual. Let's extend the concept to hwmon devices, that don't have a *recognized ancestor* device (hwmon devices that according to the kernel don't reside on a bus that we recognize). This change is meant to address cases where a hwmon device has a thermal class device for a parent, but the thermal class device doesn't have a parent device. These kind of hwmon devices started appearing in the 4.19 kernel due to commit f6b6b52ef7a54160c0. It was not reported as a kernel regression and fixed in the kernel, because according to Documentation/admin-guide/sysfs-rules.rst, the change was OK to make (it says "Position of devices along device chain can change"). Fixes #139 Signed-off-by: Ondřej Lysoněk --- lib/sysfs.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 1691b9f5..e63688b7 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -759,6 +759,7 @@ static int sensors_read_one_sysfs_chip(const char *dev_path, const char *hwmon_path) { int ret = 1; + int virtual = 0; sensors_chip_features entry; /* ignore any device without name attribute */ @@ -770,15 +771,22 @@ static int sensors_read_one_sysfs_chip(const char *dev_path, sensors_fatal_error(__func__, "Out of memory"); if (dev_path == NULL) { + virtual = 1; + } else { + ret = find_bus_type(dev_path, dev_name, &entry); + if (ret == 0) { + virtual = 1; + ret = 1; + } else if (ret < 0) { + goto exit_free; + } + } + if (virtual) { /* Virtual device */ entry.chip.bus.type = SENSORS_BUS_TYPE_VIRTUAL; entry.chip.bus.nr = 0; /* For now we assume that virtual devices are unique */ entry.chip.addr = 0; - } else { - ret = find_bus_type(dev_path, dev_name, &entry); - if (ret <= 0) - goto exit_free; } if (sensors_read_dynamic_chip(&entry, hwmon_path) < 0) {