2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-08-31 06:15:15 +00:00

struct sensors_proc_chips_entry now has a single member, so we may

as well use this member directly for slightly more simple code.


git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4474 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare
2007-06-26 11:33:09 +00:00
parent 6c7effca88
commit 8138489a72
5 changed files with 21 additions and 32 deletions

View File

@@ -304,7 +304,7 @@ const sensors_chip_name *sensors_get_detected_chips(int *nr)
{
const sensors_chip_name *res;
res = (*nr >= sensors_proc_chips_count ?
NULL : &sensors_proc_chips[*nr].name);
NULL : &sensors_proc_chips[*nr]);
(*nr)++;
return res;
}

View File

@@ -36,7 +36,7 @@ sensors_bus *sensors_config_busses = NULL;
int sensors_config_busses_count = 0;
int sensors_config_busses_max = 0;
sensors_proc_chips_entry *sensors_proc_chips = NULL;
sensors_chip_name *sensors_proc_chips = NULL;
int sensors_proc_chips_count = 0;
int sensors_proc_chips_max = 0;

View File

@@ -118,11 +118,6 @@ typedef struct sensors_bus {
int lineno;
} sensors_bus;
/* /proc/sys/dev/sensors/chips line representation */
typedef struct sensors_proc_chips_entry {
sensors_chip_name name;
} sensors_proc_chips_entry;
/* Internal data about a single chip feature.
name is the string name used to refer to this feature (both in config
files and through user functions);
@@ -164,13 +159,13 @@ extern sensors_bus *sensors_config_busses;
extern int sensors_config_busses_count;
extern int sensors_config_busses_max;
extern sensors_proc_chips_entry *sensors_proc_chips;
extern sensors_chip_name *sensors_proc_chips;
extern int sensors_proc_chips_count;
extern int sensors_proc_chips_max;
#define sensors_add_proc_chips(el) sensors_add_array_el( \
(el), &sensors_proc_chips, &sensors_proc_chips_count,\
&sensors_proc_chips_max, sizeof(struct sensors_proc_chips_entry))
&sensors_proc_chips_max, sizeof(struct sensors_chip_name))
extern sensors_bus *sensors_proc_bus;
extern int sensors_proc_bus_count;

View File

@@ -27,7 +27,6 @@
#include "sysfs.h"
#include "scanner.h"
static void free_proc_chips_entry(sensors_proc_chips_entry entry);
static void free_chip_name(sensors_chip_name name);
static void free_bus(sensors_bus bus);
static void free_chip(sensors_chip chip);
@@ -61,7 +60,7 @@ void sensors_cleanup(void)
sensors_scanner_exit();
for (i = 0; i < sensors_proc_chips_count; i++)
free_proc_chips_entry(sensors_proc_chips[i]);
free_chip_name(sensors_proc_chips[i]);
free(sensors_proc_chips);
sensors_proc_chips = NULL;
sensors_proc_chips_count = sensors_proc_chips_max = 0;
@@ -85,11 +84,6 @@ void sensors_cleanup(void)
sensors_proc_bus_count = sensors_proc_bus_max = 0;
}
void free_proc_chips_entry(sensors_proc_chips_entry entry)
{
free_chip_name(entry.name);
}
void free_chip_name(sensors_chip_name name)
{
free(name.prefix);

View File

@@ -219,7 +219,7 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev)
int domain, bus, slot, fn, i;
struct sysfs_attribute *attr, *bus_attr;
char bus_path[SYSFS_PATH_MAX];
sensors_proc_chips_entry entry;
sensors_chip_name name;
/* ignore any device without name attribute */
if (!(attr = sysfs_get_device_attr(dev, "name")))
@@ -231,22 +231,22 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev)
return 0;
/* NB: attr->value[attr->len-1] == '\n'; chop that off */
entry.name.prefix = strndup(attr->value, attr->len - 1);
if (!entry.name.prefix)
name.prefix = strndup(attr->value, attr->len - 1);
if (!name.prefix)
sensors_fatal_error(__FUNCTION__, "out of memory");
entry.name.busname = strdup(dev->path);
if (!entry.name.busname)
name.busname = strdup(dev->path);
if (!name.busname)
sensors_fatal_error(__FUNCTION__, "out of memory");
if (sscanf(dev->name, "%d-%x", &entry.name.bus, &entry.name.addr) == 2) {
if (sscanf(dev->name, "%d-%x", &name.bus, &name.addr) == 2) {
/* find out if legacy ISA or not */
if (entry.name.bus == 9191)
entry.name.bus = SENSORS_CHIP_NAME_BUS_ISA;
if (name.bus == 9191)
name.bus = SENSORS_CHIP_NAME_BUS_ISA;
else {
snprintf(bus_path, sizeof(bus_path),
"%s/class/i2c-adapter/i2c-%d/device/name",
sensors_sysfs_mount, entry.name.bus);
sensors_sysfs_mount, name.bus);
if ((bus_attr = sysfs_open_attribute(bus_path))) {
if (sysfs_read_attribute(bus_attr))
@@ -254,24 +254,24 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev)
if (bus_attr->value
&& !strncmp(bus_attr->value, "ISA ", 4))
entry.name.bus = SENSORS_CHIP_NAME_BUS_ISA;
name.bus = SENSORS_CHIP_NAME_BUS_ISA;
sysfs_close_attribute(bus_attr);
}
}
} else if (sscanf(dev->name, "%*[a-z0-9_].%d", &entry.name.addr) == 1) {
} else if (sscanf(dev->name, "%*[a-z0-9_].%d", &name.addr) == 1) {
/* must be new ISA (platform driver) */
entry.name.bus = SENSORS_CHIP_NAME_BUS_ISA;
name.bus = SENSORS_CHIP_NAME_BUS_ISA;
} else if (sscanf(dev->name, "%x:%x:%x.%x", &domain, &bus, &slot, &fn) == 4) {
/* PCI */
entry.name.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn;
entry.name.bus = SENSORS_CHIP_NAME_BUS_PCI;
name.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn;
name.bus = SENSORS_CHIP_NAME_BUS_PCI;
} else
return -SENSORS_ERR_PARSE;
/* check whether this chip is known in the static list */
for (i = 0; sensors_chip_features_list[i].prefix; i++)
if (!strcasecmp(sensors_chip_features_list[i].prefix, entry.name.prefix))
if (!strcasecmp(sensors_chip_features_list[i].prefix, name.prefix))
break;
/* if no chip definition matches */
@@ -287,7 +287,7 @@ static int sensors_read_one_sysfs_chip(struct sysfs_device *dev)
total_dynamic++;
}
sensors_add_proc_chips(&entry);
sensors_add_proc_chips(&name);
return 0;
}