Changeset 4510

Show
Ignore:
Timestamp:
06/28/07 16:39:34 (6 years ago)
Author:
khali
Message:

With the new dynamic chip features enumeration code, the sensors_proc_chips
and sensors_chip_features_list arrays tend to track the same information.
So it's much more simple, and more efficient, to have a single array. I
decided to keep sensors_proc_chips, because it already has memory management
helpers. One nice side effect is that the arbitrary limit to the number of
supported chips is now gone. Another one is that some of the memory leaks
were fixed.

Location:
lm-sensors/branches/lm-sensors-3.0.0/lib
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/branches/lm-sensors-3.0.0/lib/access.c

    r4508 r4510  
    106106        const sensors_chip_feature *features; 
    107107 
    108         for (i = 0; sensors_chip_features_list[i].chip.prefix; i++) 
    109                 if (sensors_match_chip(sensors_chip_features_list[i].chip, *chip)) { 
    110                         features = sensors_chip_features_list[i].feature; 
     108        for (i = 0; i < sensors_proc_chips_count; i++) 
     109                if (sensors_match_chip(sensors_proc_chips[i].chip, *chip)) { 
     110                        features = sensors_proc_chips[i].feature; 
    111111                        for (j = 0; features[j].data.name; j++) 
    112112                                if (features[j].data.number == feature) 
     
    125125        const sensors_chip_feature *features; 
    126126 
    127         for (i = 0; sensors_chip_features_list[i].chip.prefix; i++) 
    128                 if (sensors_match_chip(sensors_chip_features_list[i].chip, *chip)) { 
    129                         features = sensors_chip_features_list[i].feature; 
     127        for (i = 0; i < sensors_proc_chips_count; i++) 
     128                if (sensors_match_chip(sensors_proc_chips[i].chip, *chip)) { 
     129                        features = sensors_proc_chips[i].feature; 
    130130                        for (j = 0; features[j].data.name; j++) 
    131131                                if (!strcasecmp(features[j].data.name, feature)) 
     
    305305        const sensors_chip_name *res; 
    306306        res = (*nr >= sensors_proc_chips_count ? 
    307                         NULL : &sensors_proc_chips[*nr]); 
     307                        NULL : &sensors_proc_chips[*nr].chip); 
    308308        (*nr)++; 
    309309        return res; 
     
    333333        int i; 
    334334 
    335         for (i = 0; sensors_chip_features_list[i].chip.prefix; i++) 
    336                 if (sensors_match_chip(sensors_chip_features_list[i].chip, name)) { 
    337                         feature_list = sensors_chip_features_list[i].feature; 
     335        for (i = 0; i < sensors_proc_chips_count; i++) 
     336                if (sensors_match_chip(sensors_proc_chips[i].chip, name)) { 
     337                        feature_list = sensors_proc_chips[i].feature; 
    338338                        if (!*nr1 && !*nr2) {   /* Return the first entry */ 
    339339                                if (!feature_list[0].data.name) /* The list may be empty */ 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/data.c

    r4508 r4510  
    3737int sensors_config_busses_max = 0; 
    3838 
    39 sensors_chip_name *sensors_proc_chips = NULL; 
     39sensors_chip_features *sensors_proc_chips = NULL; 
    4040int sensors_proc_chips_count = 0; 
    4141int sensors_proc_chips_max = 0; 
     
    4444int sensors_proc_bus_count = 0; 
    4545int sensors_proc_bus_max = 0; 
    46  
    47 #define PLACEHOLDER_ELEMENTS {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}}, {{0}} 
    48  
    49 sensors_chip_features sensors_chip_features_list[] = { 
    50   PLACEHOLDER_ELEMENTS, 
    51   { { 0 } } 
    52 }; 
    5346 
    5447static int sensors_substitute_chip(sensors_chip_name *name,int lineno); 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/data.h

    r4508 r4510  
    160160extern int sensors_config_busses_max; 
    161161 
    162 extern sensors_chip_name *sensors_proc_chips; 
     162extern sensors_chip_features *sensors_proc_chips; 
    163163extern int sensors_proc_chips_count; 
    164164extern int sensors_proc_chips_max; 
     
    166166#define sensors_add_proc_chips(el) sensors_add_array_el( \ 
    167167        (el), &sensors_proc_chips, &sensors_proc_chips_count,\ 
    168         &sensors_proc_chips_max, sizeof(struct sensors_chip_name)) 
     168        &sensors_proc_chips_max, sizeof(struct sensors_chip_features)) 
    169169 
    170170extern sensors_bus *sensors_proc_bus; 
     
    176176        &sensors_proc_bus_max, sizeof(struct sensors_bus)) 
    177177 
    178 extern sensors_chip_features sensors_chip_features_list[]; 
    179  
    180 /* this should match the total number of elements in PLACEHOLDER_ELEMENTS */ 
    181 #define N_PLACEHOLDER_ELEMENTS 10 
    182  
    183178#endif /* def LIB_SENSORS_DATA_H */ 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/init.c

    r4474 r4510  
    2929 
    3030static void free_chip_name(sensors_chip_name name); 
     31static void free_chip_features(sensors_chip_feature *features); 
    3132static void free_bus(sensors_bus bus); 
    3233static void free_chip(sensors_chip chip); 
     
    6061  sensors_scanner_exit(); 
    6162 
    62   for (i = 0; i < sensors_proc_chips_count; i++) 
    63     free_chip_name(sensors_proc_chips[i]); 
     63  for (i = 0; i < sensors_proc_chips_count; i++) { 
     64    free_chip_name(sensors_proc_chips[i].chip); 
     65    free_chip_features(sensors_proc_chips[i].feature); 
     66  } 
    6467  free(sensors_proc_chips); 
    6568  sensors_proc_chips = NULL; 
     
    8992  free(name.prefix); 
    9093  free(name.busname); 
     94} 
     95 
     96void free_chip_features(sensors_chip_feature *features) 
     97{ 
     98  int i; 
     99 
     100  for (i = 0; features[i].data.name; i++) 
     101    free(features[i].data.name); 
     102  free(features); 
    91103} 
    92104 
  • lm-sensors/branches/lm-sensors-3.0.0/lib/sysfs.c

    r4509 r4510  
    6262} 
    6363 
    64 static  
    65 sensors_chip_features sensors_read_dynamic_chip(struct sysfs_device *sysdir) 
     64static int sensors_read_dynamic_chip(sensors_chip_features *chip, 
     65                                     struct sysfs_device *sysdir) 
    6666{ 
    6767        int i, type, fnum = 1; 
    6868        struct sysfs_attribute *attr; 
    6969        struct dlist *attrs; 
    70         sensors_chip_features ret = {{0}, 0}; 
    7170        /* room for all 3  (in, fan, temp) types, with all their subfeatures 
    7271           + misc features. We use a large sparse table at first to store all 
     
    8281         
    8382        if (attrs == NULL) 
    84                 return ret; 
     83                return -ENOENT; 
    8584                 
    8685        memset(features, 0, sizeof(features)); 
     
    9190                 
    9291                if (!strcmp(name, "name")) { 
    93                         ret.chip.prefix = strndup(attr->value, strlen(attr->value) - 1); 
     92                        /* Already done */ 
    9493                        continue; 
    9594                }  
     
    193192        } 
    194193         
    195         ret.feature = dyn_features; 
    196          
    197         return ret; 
     194        chip->feature = dyn_features; 
     195         
     196        return 0; 
    198197} 
    199198 
     
    216215static int sensors_read_one_sysfs_chip(struct sysfs_device *dev) 
    217216{ 
    218         static int total_dynamic = 0; 
    219         int domain, bus, slot, fn, i; 
     217        int domain, bus, slot, fn; 
    220218        struct sysfs_attribute *attr, *bus_attr; 
    221219        char bus_path[SYSFS_PATH_MAX]; 
    222         sensors_chip_name name; 
     220        sensors_chip_features entry; 
    223221 
    224222        /* ignore any device without name attribute */ 
     
    232230 
    233231        /* NB: attr->value[attr->len-1] == '\n'; chop that off */ 
    234         name.prefix = strndup(attr->value, attr->len - 1); 
    235         if (!name.prefix) 
     232        entry.chip.prefix = strndup(attr->value, attr->len - 1); 
     233        if (!entry.chip.prefix) 
    236234                sensors_fatal_error(__FUNCTION__, "out of memory"); 
    237235 
    238         name.busname = strdup(dev->path); 
    239         if (!name.busname) 
     236        entry.chip.busname = strdup(dev->path); 
     237        if (!entry.chip.busname) 
    240238                sensors_fatal_error(__FUNCTION__, "out of memory"); 
    241239 
    242         if (sscanf(dev->name, "%d-%x", &name.bus, &name.addr) == 2) { 
     240        if (sscanf(dev->name, "%d-%x", &entry.chip.bus, &entry.chip.addr) == 2) { 
    243241                /* find out if legacy ISA or not */ 
    244                 if (name.bus == 9191) 
    245                         name.bus = SENSORS_CHIP_NAME_BUS_ISA; 
     242                if (entry.chip.bus == 9191) 
     243                        entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 
    246244                else { 
    247245                        snprintf(bus_path, sizeof(bus_path), 
    248246                                "%s/class/i2c-adapter/i2c-%d/device/name", 
    249                                 sensors_sysfs_mount, name.bus); 
     247                                sensors_sysfs_mount, entry.chip.bus); 
    250248 
    251249                        if ((bus_attr = sysfs_open_attribute(bus_path))) { 
     
    255253                                if (bus_attr->value 
    256254                                 && !strncmp(bus_attr->value, "ISA ", 4)) 
    257                                         name.bus = SENSORS_CHIP_NAME_BUS_ISA; 
     255                                        entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 
    258256 
    259257                                sysfs_close_attribute(bus_attr); 
    260258                        } 
    261259                } 
    262         } else if (sscanf(dev->name, "%*[a-z0-9_].%d", &name.addr) == 1) { 
     260        } else if (sscanf(dev->name, "%*[a-z0-9_].%d", &entry.chip.addr) == 1) { 
    263261                /* must be new ISA (platform driver) */ 
    264                 name.bus = SENSORS_CHIP_NAME_BUS_ISA; 
     262                entry.chip.bus = SENSORS_CHIP_NAME_BUS_ISA; 
    265263        } else if (sscanf(dev->name, "%x:%x:%x.%x", &domain, &bus, &slot, &fn) == 4) { 
    266264                /* PCI */ 
    267                 name.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn; 
    268                 name.bus = SENSORS_CHIP_NAME_BUS_PCI; 
     265                entry.chip.addr = (domain << 16) + (bus << 8) + (slot << 3) + fn; 
     266                entry.chip.bus = SENSORS_CHIP_NAME_BUS_PCI; 
    269267        } else 
    270268                return -SENSORS_ERR_PARSE; 
    271269         
    272         if (total_dynamic < N_PLACEHOLDER_ELEMENTS) { 
    273                 sensors_chip_features n_entry = sensors_read_dynamic_chip(dev); 
    274                 n_entry.chip.addr = name.addr; 
    275                 n_entry.chip.bus = name.bus; 
    276  
    277                 /* skip to end of list */ 
    278                 for(i = 0; sensors_chip_features_list[i].chip.prefix; i++); 
    279  
    280                 sensors_chip_features_list[i] = n_entry;         
    281  
    282                 total_dynamic++; 
    283         } 
    284                  
    285         sensors_add_proc_chips(&name); 
     270        if (sensors_read_dynamic_chip(&entry, dev) < 0) 
     271                return -SENSORS_ERR_PARSE; 
     272        sensors_add_proc_chips(&entry); 
    286273 
    287274        return 0;