hwmon: (w83627ehf) Get rid of smatch warnings
Guenter Roeck
Reviewed-byQuoted 14 lines · Jean Delvare
The smatch static code analyzer complains:
drivers/hwmon/w83627ehf.c:911w83627ehf_update_device()error: buffer overflow 'W83627EHF_REG_TEMP_OFFSET' 3 <= 8drivers/hwmon/w83627ehf.c:909w83627ehf_update_device()error: buffer overflow 'data->temp_offset' 3 <= 8drivers/hwmon/w83627ehf.c:2672w83627ehf_resume()error: buffer overflow 'W83627EHF_REG_TEMP_OFFSET' 3 <= 8drivers/hwmon/w83627ehf.c:2673w83627ehf_resume()error: buffer overflow 'data->temp_offset' 3 <= 8A deeper analysis of the code shows that these are false positives, as only the lower 3 bits of
data->have_temp_offsetcan be set so the write is never attempted with i >= 3. However this shows that the code isn't very robust and future changes could easily introduce a buffer overflow. So let's add a safety check to prevent that and make smatch happy.
Quoted 2 lines
Signed-off-by Jean Delvare <[email protected]>Cc Peter Huewe <[email protected]>
Quoted 33 lines
--- drivers/hwmon/w83627ehf.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/hwmon/w83627ehf.c +4
-0@@ -905,6 +905,8 @@ static struct w83627ehf_data *w83627ehf_ data->temp_max_hyst[i] =w83627ehf_read_temp (data, data->reg_temp_hyst[i]); +if (i >2 ) +continue ;if (data->have_temp_offset & (1 << i)) data->temp_offset[i] = w83627ehf_read_value(data,@@ -2670,6 +2672,8 @@ static int w83627ehf_resume(struct devicif (data->reg_temp_hyst[i])w83627ehf_write_temp (data, data->reg_temp_hyst[i], data->temp_max_hyst[i]); +if (i >2 ) +continue ;if (data->have_temp_offset & (1 << i)) w83627ehf_write_value(data, W83627EHF_REG_TEMP_OFFSET[i],Signature · 7 lines
-- Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors