mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-14 19:03:13 +00:00
Compute MAX_SUBFEATURES at run-time (#2378).
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5896 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
421f0575b0
commit
a29f126e08
2 files changed
+36
-3
No files matched your search
@@ -4,6 +4,7 @@ lm-sensors CHANGES file
|
||||
SVN HEAD
|
||||
Makefile: Check for bison and flex
|
||||
libsensors: Add support for intrusion detection (#2370)
|
||||
Compute MAX_SUBFEATURES at run-time (#2378)
|
||||
sensors.conf.defauit: Add a section for the W83627THF
|
||||
Add a section for the SCH5127
|
||||
sensors: Display 3 decimal places in raw output
|
||||
|
||||
+35
-3
@@ -139,8 +139,8 @@ char sensors_sysfs_mount[NAME_MAX];
|
||||
#define MAX_MAIN_SENSOR_TYPES 6
|
||||
#define MAX_OTHER_SENSOR_TYPES 2
|
||||
#define MAX_SENSORS_PER_TYPE 24
|
||||
#define MAX_SUBFEATURES 8
|
||||
#define FEATURE_SIZE (MAX_SUBFEATURES * 2)
|
||||
/* max_subfeatures is now computed dynamically */
|
||||
#define FEATURE_SIZE (max_subfeatures * 2)
|
||||
#define FEATURE_TYPE_SIZE (MAX_SENSORS_PER_TYPE * FEATURE_SIZE)
|
||||
|
||||
/* Room for all 6 main types (in, fan, temp, power, energy, current) and 2
|
||||
@@ -337,6 +337,33 @@ sensors_subfeature_type sensors_subfeature_get_type(const char *name, int *nr)
|
||||
return SENSORS_SUBFEATURE_UNKNOWN;
|
||||
}
|
||||
|
||||
static int sensors_compute_max(void)
|
||||
{
|
||||
int i, j, max, offset;
|
||||
const struct subfeature_type_match *submatches;
|
||||
sensors_feature_type ftype;
|
||||
|
||||
max = 0;
|
||||
for (i = 0; i < ARRAY_SIZE(matches); i++) {
|
||||
submatches = matches[i].submatches;
|
||||
for (j = 0; submatches[j].name != NULL; j++) {
|
||||
ftype = submatches[j].type >> 8;
|
||||
|
||||
if (ftype < SENSORS_FEATURE_VID) {
|
||||
offset = submatches[j].type & 0x7F;
|
||||
if (offset >= max)
|
||||
max = offset + 1;
|
||||
} else {
|
||||
offset = submatches[j].type & 0xFF;
|
||||
if (offset >= max * 2)
|
||||
max = ((offset + 1) + 1) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
static int sensors_get_attr_mode(const char *device, const char *attr)
|
||||
{
|
||||
char path[NAME_MAX];
|
||||
@@ -357,6 +384,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
const char *dev_path)
|
||||
{
|
||||
int i, fnum = 0, sfnum = 0, prev_slot;
|
||||
static int max_subfeatures;
|
||||
DIR *dir;
|
||||
struct dirent *ent;
|
||||
sensors_subfeature *all_subfeatures;
|
||||
@@ -368,6 +396,10 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
if (!(dir = opendir(dev_path)))
|
||||
return -errno;
|
||||
|
||||
/* Dynamically figure out the max number of subfeatures */
|
||||
if (!max_subfeatures)
|
||||
max_subfeatures = sensors_compute_max();
|
||||
|
||||
/* We use a large sparse table at first to store all found
|
||||
subfeatures, so that we can store them sorted at type and index
|
||||
and then later create a dense sorted table. */
|
||||
@@ -430,7 +462,7 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
||||
default:
|
||||
i = ftype * FEATURE_TYPE_SIZE +
|
||||
nr * FEATURE_SIZE +
|
||||
((sftype & 0x80) >> 7) * MAX_SUBFEATURES +
|
||||
((sftype & 0x80) >> 7) * max_subfeatures +
|
||||
(sftype & 0x7F);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user