Commit ce15a81da33b961852f6e6a55305ccc60856de25

Authored by Guenter Roeck
Committed by Guenter Roeck
1 parent 6394011d65

hwmon: (adm1031) Fix compiler warning

Some configurations produce the following compile warning:

drivers/hwmon/adm1031.c: In function 'set_fan_auto_channel':
drivers/hwmon/adm1031.c:292: warning: 'reg' may be used uninitialized in this function

While this is a false positive, it can easily be fixed by overloading the return
value from get_fan_auto_nearest with both register value and error return code
(the register value is never negative). Coincidentially, that also reduces
module size by a few bytes.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>

Showing 1 changed file with 8 additions and 12 deletions Side-by-side Diff

drivers/hwmon/adm1031.c
... ... @@ -233,18 +233,15 @@
233 233 * nearest match if no exact match where found.
234 234 */
235 235 static int
236   -get_fan_auto_nearest(struct adm1031_data *data,
237   - int chan, u8 val, u8 reg, u8 *new_reg)
  236 +get_fan_auto_nearest(struct adm1031_data *data, int chan, u8 val, u8 reg)
238 237 {
239 238 int i;
240 239 int first_match = -1, exact_match = -1;
241 240 u8 other_reg_val =
242 241 (*data->chan_select_table)[FAN_CHAN_FROM_REG(reg)][chan ? 0 : 1];
243 242  
244   - if (val == 0) {
245   - *new_reg = 0;
  243 + if (val == 0)
246 244 return 0;
247   - }
248 245  
249 246 for (i = 0; i < 8; i++) {
250 247 if ((val == (*data->chan_select_table)[i][chan]) &&
251 248  
252 249  
... ... @@ -264,13 +261,11 @@
264 261 }
265 262  
266 263 if (exact_match >= 0)
267   - *new_reg = exact_match;
  264 + return exact_match;
268 265 else if (first_match >= 0)
269   - *new_reg = first_match;
270   - else
271   - return -EINVAL;
  266 + return first_match;
272 267  
273   - return 0;
  268 + return -EINVAL;
274 269 }
275 270  
276 271 static ssize_t show_fan_auto_channel(struct device *dev,
277 272  
... ... @@ -301,11 +296,12 @@
301 296  
302 297 mutex_lock(&data->update_lock);
303 298  
304   - ret = get_fan_auto_nearest(data, nr, val, data->conf1, &reg);
305   - if (ret) {
  299 + ret = get_fan_auto_nearest(data, nr, val, data->conf1);
  300 + if (ret < 0) {
306 301 mutex_unlock(&data->update_lock);
307 302 return ret;
308 303 }
  304 + reg = ret;
309 305 data->conf1 = FAN_CHAN_TO_REG(reg, data->conf1);
310 306 if ((data->conf1 & ADM1031_CONF1_AUTO_MODE) ^
311 307 (old_fan_mode & ADM1031_CONF1_AUTO_MODE)) {