aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/abituguru.c
diff options
context:
space:
mode:
authorHans de Goede <j.w.r.degoede@hhs.nl>2006-06-04 14:23:01 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-06-22 14:10:34 -0400
commita2392e0b907b9633c31be14ee75bb39fce348b01 (patch)
tree7e393e1c53b7f26c87d871fd9eb401b0f4369d7d /drivers/hwmon/abituguru.c
parentf2b84bbcebfdbe4855bab532909eef6621999f9f (diff)
[PATCH] abituguru: Review fixes
Fixes to the Abit uGuru driver as requested in review by Jean Delvare: - exactly calculate the sysfs_names array length using macro - use snprintf when generating names to double check that the sysfs_names array does not overflow. - use ARRAY_SIZE and / or defines to determine number of loops in for loops instead of using hardcoded values. - In abituguru_probe(), refactor the error path leaving a single call to kfree Signed-off-by: Hans de Goede <j.w.r.degoede@hhs.nl> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/hwmon/abituguru.c')
-rw-r--r--drivers/hwmon/abituguru.c197
1 files changed, 111 insertions, 86 deletions
diff --git a/drivers/hwmon/abituguru.c b/drivers/hwmon/abituguru.c
index bf2cb0aa69b4..ab80b418bd69 100644
--- a/drivers/hwmon/abituguru.c
+++ b/drivers/hwmon/abituguru.c
@@ -36,6 +36,10 @@
36#define ABIT_UGURU_SENSOR_BANK1 0x21 /* 16x volt and temp */ 36#define ABIT_UGURU_SENSOR_BANK1 0x21 /* 16x volt and temp */
37#define ABIT_UGURU_FAN_PWM 0x24 /* 3x 5 bytes */ 37#define ABIT_UGURU_FAN_PWM 0x24 /* 3x 5 bytes */
38#define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */ 38#define ABIT_UGURU_SENSOR_BANK2 0x26 /* fans */
39/* max nr of sensors in bank1, a bank1 sensor can be in, temp or nc */
40#define ABIT_UGURU_MAX_BANK1_SENSORS 16
41/* Warning if you increase one of the 2 MAX defines below to 10 or higher you
42 should adjust the belonging _NAMES_LENGTH macro for the 2 digit number! */
39/* max nr of sensors in bank2, currently mb's with max 6 fans are known */ 43/* max nr of sensors in bank2, currently mb's with max 6 fans are known */
40#define ABIT_UGURU_MAX_BANK2_SENSORS 6 44#define ABIT_UGURU_MAX_BANK2_SENSORS 6
41/* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */ 45/* max nr of pwm outputs, currently mb's with max 5 pwm outputs are known */
@@ -74,10 +78,33 @@
74/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */ 78/* Maximum 3 retries on timedout reads/writes, delay 200 ms before retrying */
75#define ABIT_UGURU_MAX_RETRIES 3 79#define ABIT_UGURU_MAX_RETRIES 3
76#define ABIT_UGURU_RETRY_DELAY (HZ/5) 80#define ABIT_UGURU_RETRY_DELAY (HZ/5)
77/* Maximum 2 timeouts in abituguru_update_device, iow 3 in a row is a error */ 81/* Maximum 2 timeouts in abituguru_update_device, iow 3 in a row is an error */
78#define ABIT_UGURU_MAX_TIMEOUTS 2 82#define ABIT_UGURU_MAX_TIMEOUTS 2
79 83/* utility macros */
80/* All the variables below are named identical to the oguru and oguru2 programs 84#define ABIT_UGURU_NAME "abituguru"
85#define ABIT_UGURU_DEBUG(level, format, arg...) \
86 if (level <= verbose) \
87 printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg)
88/* Macros to help calculate the sysfs_names array length */
89/* sum of strlen of: in??_input\0, in??_{min,max}\0, in??_{min,max}_alarm\0,
90 in??_{min,max}_alarm_enable\0, in??_beep\0, in??_shutdown\0 */
91#define ABITUGURU_IN_NAMES_LENGTH (11 + 2 * 9 + 2 * 15 + 2 * 22 + 10 + 14)
92/* sum of strlen of: temp??_input\0, temp??_max\0, temp??_crit\0,
93 temp??_alarm\0, temp??_alarm_enable\0, temp??_beep\0, temp??_shutdown\0 */
94#define ABITUGURU_TEMP_NAMES_LENGTH (13 + 11 + 12 + 13 + 20 + 12 + 16)
95/* sum of strlen of: fan?_input\0, fan?_min\0, fan?_alarm\0,
96 fan?_alarm_enable\0, fan?_beep\0, fan?_shutdown\0 */
97#define ABITUGURU_FAN_NAMES_LENGTH (11 + 9 + 11 + 18 + 10 + 14)
98/* sum of strlen of: pwm?_enable\0, pwm?_auto_channels_temp\0,
99 pwm?_auto_point{1,2}_pwm\0, pwm?_auto_point{1,2}_temp\0 */
100#define ABITUGURU_PWM_NAMES_LENGTH (12 + 24 + 2 * 21 + 2 * 22)
101/* IN_NAMES_LENGTH > TEMP_NAMES_LENGTH so assume all bank1 sensors are in */
102#define ABITUGURU_SYSFS_NAMES_LENGTH ( \
103 ABIT_UGURU_MAX_BANK1_SENSORS * ABITUGURU_IN_NAMES_LENGTH + \
104 ABIT_UGURU_MAX_BANK2_SENSORS * ABITUGURU_FAN_NAMES_LENGTH + \
105 ABIT_UGURU_MAX_PWMS * ABITUGURU_PWM_NAMES_LENGTH)
106
107/* All the macros below are named identical to the oguru and oguru2 programs
81 reverse engineered by Olle Sandberg, hence the names might not be 100% 108 reverse engineered by Olle Sandberg, hence the names might not be 100%
82 logical. I could come up with better names, but I prefer keeping the names 109 logical. I could come up with better names, but I prefer keeping the names
83 identical so that this driver can be compared with his work more easily. */ 110 identical so that this driver can be compared with his work more easily. */
@@ -93,11 +120,6 @@
93#define ABIT_UGURU_STATUS_READ 0x01 /* Ready to be read */ 120#define ABIT_UGURU_STATUS_READ 0x01 /* Ready to be read */
94#define ABIT_UGURU_STATUS_INPUT 0x08 /* More input */ 121#define ABIT_UGURU_STATUS_INPUT 0x08 /* More input */
95#define ABIT_UGURU_STATUS_READY 0x09 /* Ready to be written */ 122#define ABIT_UGURU_STATUS_READY 0x09 /* Ready to be written */
96/* utility macros */
97#define ABIT_UGURU_NAME "abituguru"
98#define ABIT_UGURU_DEBUG(level, format, arg...) \
99 if (level <= verbose) \
100 printk(KERN_DEBUG ABIT_UGURU_NAME ": " format , ## arg)
101 123
102/* Constants */ 124/* Constants */
103/* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */ 125/* in (Volt) sensors go up to 3494 mV, temp to 255000 millidegrees Celsius */
@@ -156,24 +178,23 @@ struct abituguru_data {
156 of a sensor is a volt or a temp sensor, for bank2 and the pwms its 178 of a sensor is a volt or a temp sensor, for bank2 and the pwms its
157 easier todo things the same way. For in sensors we have 9 (temp 7) 179 easier todo things the same way. For in sensors we have 9 (temp 7)
158 sysfs entries per sensor, for bank2 and pwms 6. */ 180 sysfs entries per sensor, for bank2 and pwms 6. */
159 struct sensor_device_attribute_2 sysfs_attr[16 * 9 + 181 struct sensor_device_attribute_2 sysfs_attr[
182 ABIT_UGURU_MAX_BANK1_SENSORS * 9 +
160 ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6]; 183 ABIT_UGURU_MAX_BANK2_SENSORS * 6 + ABIT_UGURU_MAX_PWMS * 6];
161 /* Buffer to store the dynamically generated sysfs names, we need 2120 184 /* Buffer to store the dynamically generated sysfs names */
162 bytes for bank1 (worst case scenario of 16 in sensors), 444 bytes 185 char sysfs_names[ABITUGURU_SYSFS_NAMES_LENGTH];
163 for fan1-6 and 738 bytes for pwm1-6 + some room to spare in case I
164 miscounted :) */
165 char bank1_names[3400];
166 186
167 /* Bank 1 data */ 187 /* Bank 1 data */
168 u8 bank1_sensors[2]; /* number of [0] in, [1] temp sensors */ 188 /* number of and addresses of [0] in, [1] temp sensors */
169 u8 bank1_address[2][16];/* addresses of [0] in, [1] temp sensors */ 189 u8 bank1_sensors[2];
170 u8 bank1_value[16]; 190 u8 bank1_address[2][ABIT_UGURU_MAX_BANK1_SENSORS];
171 /* This array holds 16 x 3 entries for all the bank 1 sensor settings 191 u8 bank1_value[ABIT_UGURU_MAX_BANK1_SENSORS];
192 /* This array holds 3 entries per sensor for the bank 1 sensor settings
172 (flags, min, max for voltage / flags, warn, shutdown for temp). */ 193 (flags, min, max for voltage / flags, warn, shutdown for temp). */
173 u8 bank1_settings[16][3]; 194 u8 bank1_settings[ABIT_UGURU_MAX_BANK1_SENSORS][3];
174 /* Maximum value for each sensor used for scaling in mV/millidegrees 195 /* Maximum value for each sensor used for scaling in mV/millidegrees
175 Celsius. */ 196 Celsius. */
176 int bank1_max_value[16]; 197 int bank1_max_value[ABIT_UGURU_MAX_BANK1_SENSORS];
177 198
178 /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */ 199 /* Bank 2 data, ABIT_UGURU_MAX_BANK2_SENSORS entries for bank2 */
179 u8 bank2_sensors; /* actual number of bank2 sensors found */ 200 u8 bank2_sensors; /* actual number of bank2 sensors found */
@@ -379,7 +400,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
379 /* First read the sensor and the current settings */ 400 /* First read the sensor and the current settings */
380 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val, 401 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, sensor_addr, &val,
381 1, ABIT_UGURU_MAX_RETRIES) != 1) 402 1, ABIT_UGURU_MAX_RETRIES) != 1)
382 return -EIO; 403 return -ENODEV;
383 404
384 /* Test val is sane / usable for sensor type detection. */ 405 /* Test val is sane / usable for sensor type detection. */
385 if ((val < 10u) || (val > 240u)) { 406 if ((val < 10u) || (val > 240u)) {
@@ -401,7 +422,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
401 buf[2] = 250; 422 buf[2] = 250;
402 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 423 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
403 buf, 3) != 3) 424 buf, 3) != 3)
404 return -EIO; 425 return -ENODEV;
405 /* Now we need 20 ms to give the uguru time to read the sensors 426 /* Now we need 20 ms to give the uguru time to read the sensors
406 and raise a voltage alarm */ 427 and raise a voltage alarm */
407 set_current_state(TASK_UNINTERRUPTIBLE); 428 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -409,19 +430,19 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
409 /* Check for alarm and check the alarm is a volt low alarm. */ 430 /* Check for alarm and check the alarm is a volt low alarm. */
410 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 431 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
411 ABIT_UGURU_MAX_RETRIES) != 3) 432 ABIT_UGURU_MAX_RETRIES) != 3)
412 return -EIO; 433 return -ENODEV;
413 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 434 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
414 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 435 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
415 sensor_addr, buf, 3, 436 sensor_addr, buf, 3,
416 ABIT_UGURU_MAX_RETRIES) != 3) 437 ABIT_UGURU_MAX_RETRIES) != 3)
417 return -EIO; 438 return -ENODEV;
418 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) { 439 if (buf[0] & ABIT_UGURU_VOLT_LOW_ALARM_FLAG) {
419 /* Restore original settings */ 440 /* Restore original settings */
420 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, 441 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2,
421 sensor_addr, 442 sensor_addr,
422 data->bank1_settings[sensor_addr], 443 data->bank1_settings[sensor_addr],
423 3) != 3) 444 3) != 3)
424 return -EIO; 445 return -ENODEV;
425 ABIT_UGURU_DEBUG(2, " found volt sensor\n"); 446 ABIT_UGURU_DEBUG(2, " found volt sensor\n");
426 return ABIT_UGURU_IN_SENSOR; 447 return ABIT_UGURU_IN_SENSOR;
427 } else 448 } else
@@ -439,7 +460,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
439 buf[2] = 10; 460 buf[2] = 10;
440 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 461 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
441 buf, 3) != 3) 462 buf, 3) != 3)
442 return -EIO; 463 return -ENODEV;
443 /* Now we need 50 ms to give the uguru time to read the sensors 464 /* Now we need 50 ms to give the uguru time to read the sensors
444 and raise a temp alarm */ 465 and raise a temp alarm */
445 set_current_state(TASK_UNINTERRUPTIBLE); 466 set_current_state(TASK_UNINTERRUPTIBLE);
@@ -447,12 +468,12 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
447 /* Check for alarm and check the alarm is a temp high alarm. */ 468 /* Check for alarm and check the alarm is a temp high alarm. */
448 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3, 469 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, buf, 3,
449 ABIT_UGURU_MAX_RETRIES) != 3) 470 ABIT_UGURU_MAX_RETRIES) != 3)
450 return -EIO; 471 return -ENODEV;
451 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) { 472 if (buf[sensor_addr/8] & (0x01 << (sensor_addr % 8))) {
452 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1, 473 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1 + 1,
453 sensor_addr, buf, 3, 474 sensor_addr, buf, 3,
454 ABIT_UGURU_MAX_RETRIES) != 3) 475 ABIT_UGURU_MAX_RETRIES) != 3)
455 return -EIO; 476 return -ENODEV;
456 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) { 477 if (buf[0] & ABIT_UGURU_TEMP_HIGH_ALARM_FLAG) {
457 ret = ABIT_UGURU_TEMP_SENSOR; 478 ret = ABIT_UGURU_TEMP_SENSOR;
458 ABIT_UGURU_DEBUG(2, " found temp sensor\n"); 479 ABIT_UGURU_DEBUG(2, " found temp sensor\n");
@@ -466,7 +487,7 @@ abituguru_detect_bank1_sensor_type(struct abituguru_data *data,
466 /* Restore original settings */ 487 /* Restore original settings */
467 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr, 488 if (abituguru_write(data, ABIT_UGURU_SENSOR_BANK1 + 2, sensor_addr,
468 data->bank1_settings[sensor_addr], 3) != 3) 489 data->bank1_settings[sensor_addr], 3) != 3)
469 return -EIO; 490 return -ENODEV;
470 491
471 return ret; 492 return ret;
472} 493}
@@ -1061,21 +1082,21 @@ static const struct sensor_device_attribute_2 abituguru_sysfs_pwm_templ[6] = {
1061 store_pwm_setting, 4, 0), 1082 store_pwm_setting, 4, 0),
1062}; 1083};
1063 1084
1064static const struct sensor_device_attribute_2 abituguru_sysfs_attr[] = { 1085static struct sensor_device_attribute_2 abituguru_sysfs_attr[] = {
1065 SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0), 1086 SENSOR_ATTR_2(name, 0444, show_name, NULL, 0, 0),
1066}; 1087};
1067 1088
1068static int __devinit abituguru_probe(struct platform_device *pdev) 1089static int __devinit abituguru_probe(struct platform_device *pdev)
1069{ 1090{
1070 struct abituguru_data *data; 1091 struct abituguru_data *data;
1071 int i, j, res; 1092 int i, j, used, sysfs_names_free, sysfs_attr_i, res = -ENODEV;
1072 char *sysfs_filename; 1093 char *sysfs_filename;
1073 int sysfs_attr_i = 0;
1074 1094
1075 /* El weirdo probe order, to keep the sysfs order identical to the 1095 /* El weirdo probe order, to keep the sysfs order identical to the
1076 BIOS and window-appliction listing order. */ 1096 BIOS and window-appliction listing order. */
1077 const u8 probe_order[16] = { 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 1097 const u8 probe_order[ABIT_UGURU_MAX_BANK1_SENSORS] = {
1078 0x02, 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C }; 1098 0x00, 0x01, 0x03, 0x04, 0x0A, 0x08, 0x0E, 0x02,
1099 0x09, 0x06, 0x05, 0x0B, 0x0F, 0x0D, 0x07, 0x0C };
1079 1100
1080 if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL))) 1101 if (!(data = kzalloc(sizeof(struct abituguru_data), GFP_KERNEL)))
1081 return -ENOMEM; 1102 return -ENOMEM;
@@ -1092,24 +1113,18 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1092 - testread / see if one really is there. 1113 - testread / see if one really is there.
1093 - make an in memory copy of all the uguru settings for future use. */ 1114 - make an in memory copy of all the uguru settings for future use. */
1094 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1115 if (abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
1095 data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3) { 1116 data->alarms, 3, ABIT_UGURU_MAX_RETRIES) != 3)
1096 kfree(data); 1117 goto abituguru_probe_error;
1097 return -ENODEV;
1098 }
1099 1118
1100 for (i = 0; i < 16; i++) { 1119 for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) {
1101 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, i, 1120 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1, i,
1102 &data->bank1_value[i], 1, 1121 &data->bank1_value[i], 1,
1103 ABIT_UGURU_MAX_RETRIES) != 1) { 1122 ABIT_UGURU_MAX_RETRIES) != 1)
1104 kfree(data); 1123 goto abituguru_probe_error;
1105 return -ENODEV;
1106 }
1107 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1+1, i, 1124 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK1+1, i,
1108 data->bank1_settings[i], 3, 1125 data->bank1_settings[i], 3,
1109 ABIT_UGURU_MAX_RETRIES) != 3) { 1126 ABIT_UGURU_MAX_RETRIES) != 3)
1110 kfree(data); 1127 goto abituguru_probe_error;
1111 return -ENODEV;
1112 }
1113 } 1128 }
1114 /* Note: We don't know how many bank2 sensors / pwms there really are, 1129 /* Note: We don't know how many bank2 sensors / pwms there really are,
1115 but in order to "detect" this we need to read the maximum amount 1130 but in order to "detect" this we need to read the maximum amount
@@ -1119,48 +1134,45 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1119 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) { 1134 for (i = 0; i < ABIT_UGURU_MAX_BANK2_SENSORS; i++) {
1120 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i, 1135 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2, i,
1121 &data->bank2_value[i], 1, 1136 &data->bank2_value[i], 1,
1122 ABIT_UGURU_MAX_RETRIES) != 1) { 1137 ABIT_UGURU_MAX_RETRIES) != 1)
1123 kfree(data); 1138 goto abituguru_probe_error;
1124 return -ENODEV;
1125 }
1126 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2+1, i, 1139 if (abituguru_read(data, ABIT_UGURU_SENSOR_BANK2+1, i,
1127 data->bank2_settings[i], 2, 1140 data->bank2_settings[i], 2,
1128 ABIT_UGURU_MAX_RETRIES) != 2) { 1141 ABIT_UGURU_MAX_RETRIES) != 2)
1129 kfree(data); 1142 goto abituguru_probe_error;
1130 return -ENODEV;
1131 }
1132 } 1143 }
1133 for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) { 1144 for (i = 0; i < ABIT_UGURU_MAX_PWMS; i++) {
1134 if (abituguru_read(data, ABIT_UGURU_FAN_PWM, i, 1145 if (abituguru_read(data, ABIT_UGURU_FAN_PWM, i,
1135 data->pwm_settings[i], 5, 1146 data->pwm_settings[i], 5,
1136 ABIT_UGURU_MAX_RETRIES) != 5) { 1147 ABIT_UGURU_MAX_RETRIES) != 5)
1137 kfree(data); 1148 goto abituguru_probe_error;
1138 return -ENODEV;
1139 }
1140 } 1149 }
1141 data->last_updated = jiffies; 1150 data->last_updated = jiffies;
1142 1151
1143 /* Detect sensor types and fill the sysfs attr for bank1 */ 1152 /* Detect sensor types and fill the sysfs attr for bank1 */
1144 sysfs_filename = data->bank1_names; 1153 sysfs_attr_i = 0;
1145 for (i = 0; i < 16; i++) { 1154 sysfs_filename = data->sysfs_names;
1155 sysfs_names_free = ABITUGURU_SYSFS_NAMES_LENGTH;
1156 for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) {
1146 res = abituguru_detect_bank1_sensor_type(data, probe_order[i]); 1157 res = abituguru_detect_bank1_sensor_type(data, probe_order[i]);
1147 if (res < 0) { 1158 if (res < 0)
1148 kfree(data); 1159 goto abituguru_probe_error;
1149 return -ENODEV;
1150 }
1151 if (res == ABIT_UGURU_NC) 1160 if (res == ABIT_UGURU_NC)
1152 continue; 1161 continue;
1153 1162
1163 /* res 1 (temp) sensors have 7 sysfs entries, 0 (in) 9 */
1154 for (j = 0; j < (res ? 7 : 9); j++) { 1164 for (j = 0; j < (res ? 7 : 9); j++) {
1155 const char *name_templ = abituguru_sysfs_bank1_templ[ 1165 used = snprintf(sysfs_filename, sysfs_names_free,
1156 res][j].dev_attr.attr.name; 1166 abituguru_sysfs_bank1_templ[res][j].dev_attr.
1167 attr.name, data->bank1_sensors[res] + res)
1168 + 1;
1157 data->sysfs_attr[sysfs_attr_i] = 1169 data->sysfs_attr[sysfs_attr_i] =
1158 abituguru_sysfs_bank1_templ[res][j]; 1170 abituguru_sysfs_bank1_templ[res][j];
1159 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1171 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name =
1160 sysfs_filename; 1172 sysfs_filename;
1161 sysfs_filename += sprintf(sysfs_filename, name_templ,
1162 data->bank1_sensors[res] + res) + 1;
1163 data->sysfs_attr[sysfs_attr_i].index = probe_order[i]; 1173 data->sysfs_attr[sysfs_attr_i].index = probe_order[i];
1174 sysfs_filename += used;
1175 sysfs_names_free -= used;
1164 sysfs_attr_i++; 1176 sysfs_attr_i++;
1165 } 1177 }
1166 data->bank1_max_value[probe_order[i]] = 1178 data->bank1_max_value[probe_order[i]] =
@@ -1172,52 +1184,65 @@ static int __devinit abituguru_probe(struct platform_device *pdev)
1172 /* Detect number of sensors and fill the sysfs attr for bank2 (fans) */ 1184 /* Detect number of sensors and fill the sysfs attr for bank2 (fans) */
1173 abituguru_detect_no_bank2_sensors(data); 1185 abituguru_detect_no_bank2_sensors(data);
1174 for (i = 0; i < data->bank2_sensors; i++) { 1186 for (i = 0; i < data->bank2_sensors; i++) {
1175 for (j = 0; j < 6; j++) { 1187 for (j = 0; j < ARRAY_SIZE(abituguru_sysfs_fan_templ); j++) {
1176 const char *name_templ = abituguru_sysfs_fan_templ[j]. 1188 used = snprintf(sysfs_filename, sysfs_names_free,
1177 dev_attr.attr.name; 1189 abituguru_sysfs_fan_templ[j].dev_attr.attr.name,
1190 i + 1) + 1;
1178 data->sysfs_attr[sysfs_attr_i] = 1191 data->sysfs_attr[sysfs_attr_i] =
1179 abituguru_sysfs_fan_templ[j]; 1192 abituguru_sysfs_fan_templ[j];
1180 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1193 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name =
1181 sysfs_filename; 1194 sysfs_filename;
1182 sysfs_filename += sprintf(sysfs_filename, name_templ,
1183 i + 1) + 1;
1184 data->sysfs_attr[sysfs_attr_i].index = i; 1195 data->sysfs_attr[sysfs_attr_i].index = i;
1196 sysfs_filename += used;
1197 sysfs_names_free -= used;
1185 sysfs_attr_i++; 1198 sysfs_attr_i++;
1186 } 1199 }
1187 } 1200 }
1188 /* Detect number of sensors and fill the sysfs attr for pwms */ 1201 /* Detect number of sensors and fill the sysfs attr for pwms */
1189 abituguru_detect_no_pwms(data); 1202 abituguru_detect_no_pwms(data);
1190 for (i = 0; i < data->pwms; i++) { 1203 for (i = 0; i < data->pwms; i++) {
1191 for (j = 0; j < 6; j++) { 1204 for (j = 0; j < ARRAY_SIZE(abituguru_sysfs_pwm_templ); j++) {
1192 const char *name_templ = abituguru_sysfs_pwm_templ[j]. 1205 used = snprintf(sysfs_filename, sysfs_names_free,
1193 dev_attr.attr.name; 1206 abituguru_sysfs_pwm_templ[j].dev_attr.attr.name,
1207 i + 1) + 1;
1194 data->sysfs_attr[sysfs_attr_i] = 1208 data->sysfs_attr[sysfs_attr_i] =
1195 abituguru_sysfs_pwm_templ[j]; 1209 abituguru_sysfs_pwm_templ[j];
1196 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name = 1210 data->sysfs_attr[sysfs_attr_i].dev_attr.attr.name =
1197 sysfs_filename; 1211 sysfs_filename;
1198 sysfs_filename += sprintf(sysfs_filename, name_templ,
1199 i + 1) + 1;
1200 data->sysfs_attr[sysfs_attr_i].index = i; 1212 data->sysfs_attr[sysfs_attr_i].index = i;
1213 sysfs_filename += used;
1214 sysfs_names_free -= used;
1201 sysfs_attr_i++; 1215 sysfs_attr_i++;
1202 } 1216 }
1203 } 1217 }
1204 /* Last add any "generic" entries to sysfs */ 1218 /* Fail safe check, this should never happen! */
1205 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++) { 1219 if (sysfs_names_free < 0) {
1206 data->sysfs_attr[sysfs_attr_i] = abituguru_sysfs_attr[i]; 1220 printk(KERN_ERR ABIT_UGURU_NAME ": Fatal error ran out of "
1207 sysfs_attr_i++; 1221 "space for sysfs attr names. This should never "
1222 "happen please report to the abituguru maintainer "
1223 "(see MAINTAINERS)\n");
1224 res = -ENAMETOOLONG;
1225 goto abituguru_probe_error;
1208 } 1226 }
1209 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n"); 1227 printk(KERN_INFO ABIT_UGURU_NAME ": found Abit uGuru\n");
1210 1228
1211 /* Register sysfs hooks */ 1229 /* Register sysfs hooks */
1212 data->class_dev = hwmon_device_register(&pdev->dev); 1230 data->class_dev = hwmon_device_register(&pdev->dev);
1213 if (IS_ERR(data->class_dev)) { 1231 if (IS_ERR(data->class_dev)) {
1214 kfree(data); 1232 res = PTR_ERR(data->class_dev);
1215 return PTR_ERR(data->class_dev); 1233 goto abituguru_probe_error;
1216 } 1234 }
1217 for (i = 0; i < sysfs_attr_i; i++) 1235 for (i = 0; i < sysfs_attr_i; i++)
1218 device_create_file(&pdev->dev, &data->sysfs_attr[i].dev_attr); 1236 device_create_file(&pdev->dev, &data->sysfs_attr[i].dev_attr);
1237 for (i = 0; i < ARRAY_SIZE(abituguru_sysfs_attr); i++)
1238 device_create_file(&pdev->dev,
1239 &abituguru_sysfs_attr[i].dev_attr);
1219 1240
1220 return 0; 1241 return 0;
1242
1243abituguru_probe_error:
1244 kfree(data);
1245 return res;
1221} 1246}
1222 1247
1223static int __devexit abituguru_remove(struct platform_device *pdev) 1248static int __devexit abituguru_remove(struct platform_device *pdev)
@@ -1244,7 +1269,7 @@ static struct abituguru_data *abituguru_update_device(struct device *dev)
1244 if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0, 1269 if ((err = abituguru_read(data, ABIT_UGURU_ALARM_BANK, 0,
1245 data->alarms, 3, 0)) != 3) 1270 data->alarms, 3, 0)) != 3)
1246 goto LEAVE_UPDATE; 1271 goto LEAVE_UPDATE;
1247 for (i = 0; i < 16; i++) { 1272 for (i = 0; i < ABIT_UGURU_MAX_BANK1_SENSORS; i++) {
1248 if ((err = abituguru_read(data, 1273 if ((err = abituguru_read(data,
1249 ABIT_UGURU_SENSOR_BANK1, i, 1274 ABIT_UGURU_SENSOR_BANK1, i,
1250 &data->bank1_value[i], 1, 0)) != 1) 1275 &data->bank1_value[i], 1, 0)) != 1)