- Make libsensors work with hwmon class entries without a device link such
as the acpi thermal_zone driver (bz 437637)
This commit is contained in:
parent
3a7e0ed487
commit
7862977985
@ -1,21 +1,114 @@
|
||||
Index: lib/sensors.h
|
||||
===================================================================
|
||||
--- lib/sensors.h (revision 5145)
|
||||
+++ lib/sensors.h (working copy)
|
||||
@@ -30,7 +30,7 @@
|
||||
when the API + ABI breaks), the third digit is incremented to track small
|
||||
API additions like new flags / enum values. The second digit is for tracking
|
||||
larger additions like new methods. */
|
||||
-#define SENSORS_API_VERSION 0x400
|
||||
+#define SENSORS_API_VERSION 0x401
|
||||
|
||||
#define SENSORS_CHIP_NAME_PREFIX_ANY NULL
|
||||
#define SENSORS_CHIP_NAME_ADDR_ANY -1
|
||||
@@ -40,6 +40,7 @@
|
||||
#define SENSORS_BUS_TYPE_ISA 1
|
||||
#define SENSORS_BUS_TYPE_PCI 2
|
||||
#define SENSORS_BUS_TYPE_SPI 3
|
||||
+#define SENSORS_BUS_TYPE_VIRT 4
|
||||
#define SENSORS_BUS_NR_ANY (-1)
|
||||
#define SENSORS_BUS_NR_IGNORE (-2)
|
||||
|
||||
Index: lib/access.c
|
||||
===================================================================
|
||||
--- lib/access.c (revision 5145)
|
||||
+++ lib/access.c (working copy)
|
||||
@@ -344,6 +344,8 @@
|
||||
so we don't have any custom string to return. */
|
||||
case SENSORS_BUS_TYPE_SPI:
|
||||
return "SPI adapter";
|
||||
+ case SENSORS_BUS_TYPE_VIRT:
|
||||
+ return "Virtual device";
|
||||
}
|
||||
|
||||
/* bus types with several instances */
|
||||
Index: lib/sysfs.c
|
||||
===================================================================
|
||||
--- lib/sysfs.c (revision 5142)
|
||||
--- lib/sysfs.c (revision 5145)
|
||||
+++ lib/sysfs.c (working copy)
|
||||
@@ -591,8 +591,14 @@
|
||||
@@ -475,6 +475,14 @@
|
||||
if (!entry.chip.path)
|
||||
sensors_fatal_error(__func__, "Out of memory");
|
||||
|
||||
+ if (dev_path == NULL) {
|
||||
+ /* Virtual device */
|
||||
+ entry.chip.addr = 0;
|
||||
+ entry.chip.bus.type = SENSORS_BUS_TYPE_VIRT;
|
||||
+ entry.chip.bus.nr = 0;
|
||||
+ goto done;
|
||||
+ }
|
||||
+
|
||||
/* Find bus type */
|
||||
snprintf(linkpath, NAME_MAX, "%s/subsystem", dev_path);
|
||||
sub_len = readlink(linkpath, subsys_path, NAME_MAX - 1);
|
||||
@@ -543,6 +551,7 @@
|
||||
goto exit_free;
|
||||
}
|
||||
|
||||
+done:
|
||||
if (sensors_read_dynamic_chip(&entry, hwmon_path) < 0)
|
||||
goto exit_free;
|
||||
if (!entry.subfeature) { /* No subfeature, discard chip */
|
||||
@@ -591,16 +600,20 @@
|
||||
|
||||
snprintf(linkpath, NAME_MAX, "%s/device", path);
|
||||
dev_len = readlink(linkpath, device, NAME_MAX - 1);
|
||||
- if (dev_len < 0)
|
||||
- return -SENSORS_ERR_KERNEL;
|
||||
- device[dev_len] = '\0';
|
||||
- device_p = strrchr(device, '/') + 1;
|
||||
+ if (dev_len < 0) {
|
||||
+ /* virtual device without a device link (for example
|
||||
+ the acpi thermalzone driver) */
|
||||
+ err = sensors_read_one_sysfs_chip(path, "virtual", path);
|
||||
+ if (err < 0)
|
||||
+ return err;
|
||||
+ return 0;
|
||||
+ }
|
||||
device[dev_len] = '\0';
|
||||
device_p = strrchr(device, '/') + 1;
|
||||
+ /* No device link? Treat as virtual */
|
||||
+ err = sensors_read_one_sysfs_chip(NULL, NULL, path);
|
||||
+ } else {
|
||||
+ device[dev_len] = '\0';
|
||||
+ device_p = strrchr(device, '/') + 1;
|
||||
|
||||
- /* The attributes we want might be those of the hwmon class device,
|
||||
- or those of the device itself. */
|
||||
- err = sensors_read_one_sysfs_chip(linkpath, device_p, path);
|
||||
- if (err == 0)
|
||||
- err = sensors_read_one_sysfs_chip(linkpath, device_p, linkpath);
|
||||
+ /* The attributes we want might be those of the hwmon class
|
||||
+ device, or those of the device itself. */
|
||||
+ err = sensors_read_one_sysfs_chip(linkpath, device_p, path);
|
||||
+ if (err == 0)
|
||||
+ err = sensors_read_one_sysfs_chip(linkpath, device_p,
|
||||
+ linkpath);
|
||||
+ }
|
||||
if (err < 0)
|
||||
return err;
|
||||
return 0;
|
||||
Index: lib/data.c
|
||||
===================================================================
|
||||
--- lib/data.c (revision 5145)
|
||||
+++ lib/data.c (working copy)
|
||||
@@ -108,6 +108,8 @@
|
||||
res->bus.type = SENSORS_BUS_TYPE_PCI;
|
||||
else if (!strncmp(name, "spi", dash - name))
|
||||
res->bus.type = SENSORS_BUS_TYPE_SPI;
|
||||
+ else if (!strncmp(name, "virtual", dash - name))
|
||||
+ res->bus.type = SENSORS_BUS_TYPE_VIRT;
|
||||
else
|
||||
goto ERROR;
|
||||
name = dash + 1;
|
||||
@@ -168,6 +170,9 @@
|
||||
case SENSORS_BUS_TYPE_SPI:
|
||||
return snprintf(str, size, "%s-spi-%hd-%x", chip->prefix,
|
||||
chip->bus.nr, chip->addr);
|
||||
+ case SENSORS_BUS_TYPE_VIRT:
|
||||
+ return snprintf(str, size, "%s-virtual-%x", chip->prefix,
|
||||
+ chip->addr);
|
||||
}
|
||||
|
||||
return -SENSORS_ERR_CHIP_NAME;
|
||||
|
Loading…
Reference in New Issue
Block a user