From: Jean Delvare Date: Wed, 31 Oct 2012 23:18:28 +0000 (+1100) Subject: hwmon: (w83627ehf) Get rid of smatch warnings X-Git-Tag: next-20121101~78^2~9 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=2e0e7ac3b8cc66ce4142b83625320bb41f4fe633;p=karo-tx-linux.git hwmon: (w83627ehf) Get rid of smatch warnings The smatch static code analyzer complains: drivers/hwmon/w83627ehf.c:911 w83627ehf_update_device() error: buffer overflow 'W83627EHF_REG_TEMP_OFFSET' 3 <= 8 drivers/hwmon/w83627ehf.c:909 w83627ehf_update_device() error: buffer overflow 'data->temp_offset' 3 <= 8 drivers/hwmon/w83627ehf.c:2672 w83627ehf_resume() error: buffer overflow 'W83627EHF_REG_TEMP_OFFSET' 3 <= 8 drivers/hwmon/w83627ehf.c:2673 w83627ehf_resume() error: buffer overflow 'data->temp_offset' 3 <= 8 A deeper analysis of the code shows that these are false positives, as only the lower 3 bits of data->have_temp_offset can 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. Signed-off-by: Jean Delvare Cc: Peter Huewe Reviewed-by: Guenter Roeck --- diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c index 7a6d42f38a01..3af84fbd23d5 100644 --- a/drivers/hwmon/w83627ehf.c +++ b/drivers/hwmon/w83627ehf.c @@ -905,6 +905,8 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) 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 device *dev) if (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],