mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-08-31 14:25:39 +00:00
Another minor optimization to sensors_read_dynamic_chip():
* We don't need a temporary structure for the feature being currently processed. Instead we can work on the large sparse array directly. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4764 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
31
lib/sysfs.c
31
lib/sysfs.c
@@ -84,7 +84,6 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
|||||||
sensors_fatal_error(__FUNCTION__, "Out of memory");
|
sensors_fatal_error(__FUNCTION__, "Out of memory");
|
||||||
|
|
||||||
dlist_for_each_data(attrs, attr, struct sysfs_attribute) {
|
dlist_for_each_data(attrs, attr, struct sysfs_attribute) {
|
||||||
sensors_chip_feature feature;
|
|
||||||
name = attr->name;
|
name = attr->name;
|
||||||
int nr;
|
int nr;
|
||||||
|
|
||||||
@@ -92,14 +91,6 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
|||||||
if (type == SENSORS_FEATURE_UNKNOWN)
|
if (type == SENSORS_FEATURE_UNKNOWN)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
memset(&feature, 0, sizeof(sensors_chip_feature));
|
|
||||||
/* check for _input extension and remove */
|
|
||||||
i = strlen(name);
|
|
||||||
if (i > 6 && !strcmp(name + i - 6, "_input"))
|
|
||||||
feature.data.name = strndup(name, i-6);
|
|
||||||
else
|
|
||||||
feature.data.name = strdup(name);
|
|
||||||
|
|
||||||
/* Adjust the channel number */
|
/* Adjust the channel number */
|
||||||
switch (type & 0xFF00) {
|
switch (type & 0xFF00) {
|
||||||
case SENSORS_FEATURE_FAN:
|
case SENSORS_FEATURE_FAN:
|
||||||
@@ -113,7 +104,6 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
|||||||
fprintf(stderr, "libsensors error, more sensors of one"
|
fprintf(stderr, "libsensors error, more sensors of one"
|
||||||
" type then MAX_SENSORS_PER_TYPE, ignoring "
|
" type then MAX_SENSORS_PER_TYPE, ignoring "
|
||||||
"feature: %s\n", name);
|
"feature: %s\n", name);
|
||||||
free(feature.data.name);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,29 +122,34 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip,
|
|||||||
fprintf(stderr, "libsensors error, trying to add dupli"
|
fprintf(stderr, "libsensors error, trying to add dupli"
|
||||||
"cate feature: %s to dynamic feature table\n",
|
"cate feature: %s to dynamic feature table\n",
|
||||||
name);
|
name);
|
||||||
free(feature.data.name);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill in the other feature members */
|
/* fill in the feature members */
|
||||||
feature.data.type = type;
|
features[i].data.type = type;
|
||||||
|
|
||||||
|
/* check for _input extension and remove */
|
||||||
|
nr = strlen(name);
|
||||||
|
if (nr > 6 && !strcmp(name + nr - 6, "_input"))
|
||||||
|
features[i].data.name = strndup(name, nr - 6);
|
||||||
|
else
|
||||||
|
features[i].data.name = strdup(name);
|
||||||
|
|
||||||
if ((type & 0x00FF) == 0) {
|
if ((type & 0x00FF) == 0) {
|
||||||
/* main feature */
|
/* main feature */
|
||||||
feature.data.mapping = SENSORS_NO_MAPPING;
|
features[i].data.mapping = SENSORS_NO_MAPPING;
|
||||||
} else {
|
} else {
|
||||||
/* sub feature */
|
/* sub feature */
|
||||||
/* The mapping is set below after numbering */
|
/* The mapping is set below after numbering */
|
||||||
if (!(type & 0x10))
|
if (!(type & 0x10))
|
||||||
feature.data.flags |= SENSORS_COMPUTE_MAPPING;
|
features[i].data.flags |= SENSORS_COMPUTE_MAPPING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attr->method & SYSFS_METHOD_SHOW)
|
if (attr->method & SYSFS_METHOD_SHOW)
|
||||||
feature.data.flags |= SENSORS_MODE_R;
|
features[i].data.flags |= SENSORS_MODE_R;
|
||||||
if (attr->method & SYSFS_METHOD_STORE)
|
if (attr->method & SYSFS_METHOD_STORE)
|
||||||
feature.data.flags |= SENSORS_MODE_W;
|
features[i].data.flags |= SENSORS_MODE_W;
|
||||||
|
|
||||||
features[i] = feature;
|
|
||||||
fnum++;
|
fnum++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user