]> git.sur5r.net Git - groeck-nct6775/blobdiff - nct6775.c
Check for invalid temperature source
[groeck-nct6775] / nct6775.c
index a6ae98032c86c256d38518a1ae6a2c280a04f7c6..6e21ffbd34d5372538d07acbde5971b84fa572cd 100644 (file)
--- a/nct6775.c
+++ b/nct6775.c
@@ -399,7 +399,7 @@ static const char *const nct6779_temp_label[] = {
        "BYTE_TEMP"
 };
 
-static const u16 NCT6775_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6779_temp_label)]
+static const u16 NCT6775_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6775_temp_label)]
        = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x661, 0x662, 0x664 };
 
 static const u16 NCT6776_REG_TEMP_ALTERNATE[ARRAY_SIZE(nct6776_temp_label)]
@@ -966,8 +966,8 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
                            && (reg >= 0xff || (data->kind == nct6775
                                                && reg == 0x00))
                            && data->fan_div[i] < 0x07) {
-                               dev_dbg(dev, "Increasing fan%d "
-                                       "clock divider from %u to %u\n",
+                               dev_dbg(dev,
+                                       "Increasing fan%d clock divider from %u to %u\n",
                                        i + 1, div_from_reg(data->fan_div[i]),
                                        div_from_reg(data->fan_div[i] + 1));
                                data->fan_div[i]++;
@@ -1358,9 +1358,9 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
                 */
                data->fan_min[nr] = 254;
                new_div = 7; /* 128 == (1 << 7) */
-               dev_warn(dev, "fan%u low limit %lu below minimum %u, set to "
-                        "minimum\n", nr + 1, val,
-                        data->fan_from_reg_min(254, 7));
+               dev_warn(dev,
+                        "fan%u low limit %lu below minimum %u, set to minimum\n",
+                        nr + 1, val, data->fan_from_reg_min(254, 7));
        } else if (!reg) {
                /*
                 * Speed above this value cannot possibly be represented,
@@ -1368,9 +1368,9 @@ store_fan_min(struct device *dev, struct device_attribute *attr,
                 */
                data->fan_min[nr] = 1;
                new_div = 0; /* 1 == (1 << 0) */
-               dev_warn(dev, "fan%u low limit %lu above maximum %u, set to "
-                        "maximum\n", nr + 1, val,
-                        data->fan_from_reg_min(1, 0));
+               dev_warn(dev,
+                        "fan%u low limit %lu above maximum %u, set to maximum\n",
+                        nr + 1, val, data->fan_from_reg_min(1, 0));
        } else {
                /*
                 * Automatically pick the best divider, i.e. the one such
@@ -3090,7 +3090,6 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
        switch (data->kind) {
        case nct6775:
                data->in_num = 9;
-               data->have_in = 0x1ff;
                data->pwm_num = 3;
                data->auto_pwm_num = 6;
                data->has_fan_div = true;
@@ -3150,7 +3149,6 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                break;
        case nct6776:
                data->in_num = 9;
-               data->have_in = 0x1ff;
                data->pwm_num = 3;
                data->auto_pwm_num = 4;
                data->has_fan_div = false;
@@ -3209,7 +3207,6 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                break;
        case nct6779:
                data->in_num = 15;
-               data->have_in = 0x7fff;
                data->pwm_num = 5;
                data->auto_pwm_num = 4;
                data->has_fan_div = false;
@@ -3270,7 +3267,7 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                err = -ENODEV;
                goto exit_release;
        }
-
+       data->have_in = (1 << data->in_num) - 1;
        data->have_temp = 0;
 
        /*
@@ -3333,6 +3330,12 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                if (!src || (mask & (1 << src)))
                        continue;
 
+               if (src >= data->temp_label_num ||
+                   !strlen(data->temp_label[src])) {
+                       dev_info(dev, "Invalid temperature source %d\n", src);
+                       continue;
+               }
+
                mask |= 1 << src;
 
                /* Use fixed index for SYSTIN(1), CPUTIN(2), AUXTIN(3) */
@@ -3378,7 +3381,8 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                                if (data->have_temp & (1 << i))
                                        continue;
                                data->have_temp |= 1 << i;
-                               data->reg_temp[0][i] = data->REG_TEMP_ALTERNATE[i];
+                               data->reg_temp[0][i]
+                                 = data->REG_TEMP_ALTERNATE[i];
                                data->temp_src[i] = i + 1;
                                continue;
                        }
@@ -3473,7 +3477,8 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                }
                superio_outb(sio_data->sioreg, NCT6775_REG_CR_FAN_DEBOUNCE,
                             tmp);
-               pr_info("Enabled fan debounce for chip %s\n", data->name);
+               dev_info(&pdev->dev, "Enabled fan debounce for chip %s\n",
+                        data->name);
        }
 
        superio_exit(sio_data->sioreg);
@@ -3587,8 +3592,7 @@ static int __devinit nct6775_probe(struct platform_device *pdev)
                err = device_create_file(dev, &sda_temp_type[i].dev_attr);
                if (err)
                        goto exit_remove;
-               err = device_create_file(dev,
-                                        &sda_temp_offset[i].dev_attr);
+               err = device_create_file(dev, &sda_temp_offset[i].dev_attr);
                if (err)
                        goto exit_remove;
                if (i >= NUM_TEMP_ALARM ||
@@ -3699,8 +3703,7 @@ static int __init nct6775_find(int sioaddr, unsigned short *addr,
        /* Activate logical device if needed */
        val = superio_inb(sioaddr, SIO_REG_ENABLE);
        if (!(val & 0x01)) {
-               pr_warn("Forcibly enabling Super-I/O. "
-                       "Sensor is probably unusable.\n");
+               pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n");
                superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01);
        }