Skip to content

Commit

Permalink
Merge branch 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/…
Browse files Browse the repository at this point in the history
…kernel/git/jdelvare/staging

Pull hwmon fixes from Jean Delvare.

* 'hwmon-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvare/staging:
  hwmon: Prevent some divide by zeros in FAN_TO_REG()
  hwmon: (w83l768ng) Fix fan speed control range
  hwmon: (w83l786ng) Fix fan speed control mode setting and reporting
  hwmon: (lm90) Unregister hwmon device if interrupt setup fails
  • Loading branch information
Linus Torvalds committed Dec 12, 2013
2 parents 11ec50c + 3806b45 commit c846944
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions drivers/hwmon/lm78.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
{
if (rpm <= 0)
return 255;
if (rpm > 1350000)
return 1;
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
}

Expand Down
4 changes: 3 additions & 1 deletion drivers/hwmon/lm90.c
Original file line number Diff line number Diff line change
Expand Up @@ -1610,12 +1610,14 @@ static int lm90_probe(struct i2c_client *client,
"lm90", client);
if (err < 0) {
dev_err(dev, "cannot request IRQ %d\n", client->irq);
goto exit_remove_files;
goto exit_unregister;
}
}

return 0;

exit_unregister:
hwmon_device_unregister(data->hwmon_dev);
exit_remove_files:
lm90_remove_files(client, data);
exit_restore:
Expand Down
2 changes: 2 additions & 0 deletions drivers/hwmon/sis5595.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ static inline u8 FAN_TO_REG(long rpm, int div)
{
if (rpm <= 0)
return 255;
if (rpm > 1350000)
return 1;
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/hwmon/vt8231.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
*/
static inline u8 FAN_TO_REG(long rpm, int div)
{
if (rpm == 0)
if (rpm <= 0 || rpm > 1310720)
return 0;
return clamp_val(1310720 / (rpm * div), 1, 255);
}
Expand Down
13 changes: 8 additions & 5 deletions drivers/hwmon/w83l786ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,11 @@ store_pwm(struct device *dev, struct device_attribute *attr,
if (err)
return err;
val = clamp_val(val, 0, 255);
val = DIV_ROUND_CLOSEST(val, 0x11);

mutex_lock(&data->update_lock);
data->pwm[nr] = val;
data->pwm[nr] = val * 0x11;
val |= w83l786ng_read_value(client, W83L786NG_REG_PWM[nr]) & 0xf0;
w83l786ng_write_value(client, W83L786NG_REG_PWM[nr], val);
mutex_unlock(&data->update_lock);
return count;
Expand All @@ -510,7 +512,7 @@ store_pwm_enable(struct device *dev, struct device_attribute *attr,
mutex_lock(&data->update_lock);
reg = w83l786ng_read_value(client, W83L786NG_REG_FAN_CFG);
data->pwm_enable[nr] = val;
reg &= ~(0x02 << W83L786NG_PWM_ENABLE_SHIFT[nr]);
reg &= ~(0x03 << W83L786NG_PWM_ENABLE_SHIFT[nr]);
reg |= (val - 1) << W83L786NG_PWM_ENABLE_SHIFT[nr];
w83l786ng_write_value(client, W83L786NG_REG_FAN_CFG, reg);
mutex_unlock(&data->update_lock);
Expand Down Expand Up @@ -776,9 +778,10 @@ static struct w83l786ng_data *w83l786ng_update_device(struct device *dev)
((pwmcfg >> W83L786NG_PWM_MODE_SHIFT[i]) & 1)
? 0 : 1;
data->pwm_enable[i] =
((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 2) + 1;
data->pwm[i] = w83l786ng_read_value(client,
W83L786NG_REG_PWM[i]);
((pwmcfg >> W83L786NG_PWM_ENABLE_SHIFT[i]) & 3) + 1;
data->pwm[i] =
(w83l786ng_read_value(client, W83L786NG_REG_PWM[i])
& 0x0f) * 0x11;
}


Expand Down

0 comments on commit c846944

Please sign in to comment.