Changeset 5874

Show
Ignore:
Timestamp:
11/02/10 13:57:11 (3 years ago)
Author:
khali
Message:

Reorganize the temporary sparse subfeature table. It's a little larger
now, but this make it possible to add more feature types without
increasing the code complexity beyond reason. Define constants and use
them to make the code even easier to understand.

If anyone is really worried about the relatively large memory
allocation, one way to improve the situation would be a two-pass
approach. But remember the memory is only needed for a short time...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/sysfs.c

    r5844 r5874  
    137137char sensors_sysfs_mount[NAME_MAX]; 
    138138 
     139#define MAX_MAIN_SENSOR_TYPES   6 
     140#define MAX_OTHER_SENSOR_TYPES  1 
    139141#define MAX_SENSORS_PER_TYPE    24 
    140142#define MAX_SUBFEATURES         8 
    141 #define MAX_SENSOR_TYPES        6 
    142 /* Room for all 6 types (in, fan, temp, power, energy, current) with all 
    143    their subfeatures + VID + misc features */ 
    144 #define ALL_POSSIBLE_SUBFEATURES \ 
    145                                 (MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * \ 
    146                                  MAX_SENSOR_TYPES * 2 + \ 
    147                                  MAX_SENSORS_PER_TYPE + 1) 
     143#define FEATURE_SIZE            (MAX_SUBFEATURES * 2) 
     144#define FEATURE_TYPE_SIZE       (MAX_SENSORS_PER_TYPE * FEATURE_SIZE) 
     145 
     146/* Room for all 6 main types (in, fan, temp, power, energy, current) and 1 
     147   other type (VID) with all their subfeatures + misc features */ 
     148#define SUB_OFFSET_OTHER        (MAX_MAIN_SENSOR_TYPES * FEATURE_TYPE_SIZE) 
     149#define SUB_OFFSET_MISC         (SUB_OFFSET_OTHER + \ 
     150                                 MAX_OTHER_SENSOR_TYPES * FEATURE_TYPE_SIZE) 
     151#define ALL_POSSIBLE_SUBFEATURES        (SUB_OFFSET_MISC + 1) 
    148152 
    149153static 
     
    405409                switch (sftype) { 
    406410                case SENSORS_SUBFEATURE_VID: 
    407                         i = nr + MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
    408                             MAX_SENSOR_TYPES * 2; 
     411                        i = SUB_OFFSET_OTHER + 
     412                            ((sftype >> 8) - SENSORS_FEATURE_VID) * 
     413                            FEATURE_TYPE_SIZE + 
     414                            nr * FEATURE_SIZE + (sftype & 0xFF); 
    409415                        break; 
    410416                case SENSORS_SUBFEATURE_BEEP_ENABLE: 
    411                         i = MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
    412                             MAX_SENSOR_TYPES * 2 + MAX_SENSORS_PER_TYPE; 
     417                        i = SUB_OFFSET_MISC + 
     418                            ((sftype >> 8) - SENSORS_FEATURE_BEEP_ENABLE); 
    413419                        break; 
    414420                default: 
    415                         i = (sftype >> 8) * MAX_SENSORS_PER_TYPE * 
    416                             MAX_SUBFEATURES * 2 + nr * MAX_SUBFEATURES * 2 + 
     421                        i = (sftype >> 8) * FEATURE_TYPE_SIZE + 
     422                            nr * FEATURE_SIZE + 
    417423                            ((sftype & 0x80) >> 7) * MAX_SUBFEATURES + 
    418424                            (sftype & 0x7F); 
     
    451457                        continue; 
    452458 
    453                 if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
    454                     MAX_SENSOR_TYPES * 2 || 
    455                     i / (MAX_SUBFEATURES * 2) != prev_slot) { 
     459                if (i >= SUB_OFFSET_MISC || i / FEATURE_SIZE != prev_slot) { 
    456460                        fnum++; 
    457                         prev_slot = i / (MAX_SUBFEATURES * 2); 
     461                        prev_slot = i / FEATURE_SIZE; 
    458462                } 
    459463        } 
     
    473477 
    474478                /* New main feature? */ 
    475                 if (i >= MAX_SENSORS_PER_TYPE * MAX_SUBFEATURES * 
    476                     MAX_SENSOR_TYPES * 2 || 
    477                     i / (MAX_SUBFEATURES * 2) != prev_slot) { 
     479                if (i >= SUB_OFFSET_MISC || i / FEATURE_SIZE != prev_slot) { 
    478480                        ftype = all_subfeatures[i].type >> 8; 
    479481                        fnum++; 
    480                         prev_slot = i / (MAX_SUBFEATURES * 2); 
     482                        prev_slot = i / FEATURE_SIZE; 
    481483 
    482484                        dyn_features[fnum].name = get_feature_name(ftype,