hwmon: (nct6775) Check array index when accessing temp_offset
authorGuenter Roeck <linux@roeck-us.net>
Wed, 11 Sep 2013 17:35:47 +0000 (10:35 -0700)
committerGuenter Roeck <linux@roeck-us.net>
Sun, 13 Oct 2013 23:16:25 +0000 (16:16 -0700)
smatch complains about a potential out-of-bounds access to the
temp_offset array. That doesn't happen in practice, but it doesn't
hurt to add an explicit check either. This prevents potential problems
in the future (for example if the number of 'fixed' temperature
sensors is increased to add support for another chip).

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/nct6775.c

index de57e0d..b82fad4 100644 (file)
@@ -1457,7 +1457,8 @@ static struct nct6775_data *nct6775_update_device(struct device *dev)
                                          = nct6775_read_temp(data,
                                                data->reg_temp[j][i]);
                        }
-                       if (!(data->have_temp_fixed & (1 << i)))
+                       if (i >= NUM_TEMP_FIXED ||
+                           !(data->have_temp_fixed & (1 << i)))
                                continue;
                        data->temp_offset[i]
                          = nct6775_read_value(data, data->REG_TEMP_OFFSET[i]);