From 9b44cc28191c2dd5faea30eff5ffe018daa29708 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Tue, 2 Nov 2010 12:59:31 +0000 Subject: [PATCH] Work with the feature type instead of the shifted subfeature type where possible. This makes the code more readable. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5875 7894878c-1315-0410-8ee3-d5d059ff63e0 --- lib/sysfs.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/sysfs.c b/lib/sysfs.c index 79cf559f..1e1f790b 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -382,16 +382,19 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, sftype = sensors_subfeature_get_type(name, &nr); if (sftype == SENSORS_SUBFEATURE_UNKNOWN) continue; + ftype = sftype >> 8; /* Adjust the channel number */ - switch (sftype & 0xFF00) { - case SENSORS_SUBFEATURE_FAN_INPUT: - case SENSORS_SUBFEATURE_TEMP_INPUT: - case SENSORS_SUBFEATURE_POWER_AVERAGE: - case SENSORS_SUBFEATURE_ENERGY_INPUT: - case SENSORS_SUBFEATURE_CURR_INPUT: + switch (ftype) { + case SENSORS_FEATURE_FAN: + case SENSORS_FEATURE_TEMP: + case SENSORS_FEATURE_POWER: + case SENSORS_FEATURE_ENERGY: + case SENSORS_FEATURE_CURR: nr--; break; + default: + break; } if (nr < 0 || nr >= MAX_SENSORS_PER_TYPE) { @@ -406,19 +409,18 @@ static int sensors_read_dynamic_chip(sensors_chip_features *chip, /* "calculate" a place to store the subfeature in our sparse, sorted table */ - switch (sftype) { - case SENSORS_SUBFEATURE_VID: + switch (ftype) { + case SENSORS_FEATURE_VID: i = SUB_OFFSET_OTHER + - ((sftype >> 8) - SENSORS_FEATURE_VID) * - FEATURE_TYPE_SIZE + + (ftype - SENSORS_FEATURE_VID) * FEATURE_TYPE_SIZE + nr * FEATURE_SIZE + (sftype & 0xFF); break; - case SENSORS_SUBFEATURE_BEEP_ENABLE: + case SENSORS_FEATURE_BEEP_ENABLE: i = SUB_OFFSET_MISC + - ((sftype >> 8) - SENSORS_FEATURE_BEEP_ENABLE); + (ftype - SENSORS_FEATURE_BEEP_ENABLE); break; default: - i = (sftype >> 8) * FEATURE_TYPE_SIZE + + i = ftype * FEATURE_TYPE_SIZE + nr * FEATURE_SIZE + ((sftype & 0x80) >> 7) * MAX_SUBFEATURES + (sftype & 0x7F);