Skip to content

Commit b88b2f8

Browse files
committed
Merge tag 'hwmon-for-v6.19-take-2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes Guenter Roeck: - Documentation: Fix link to g762 devicetree binding - emc2305: Fix devicetree refcount leak and double put - dell-smm: Fix channel-index off-by-one error - w83791d: Convert macros to functions to avoid TOCTOU * tag 'hwmon-for-v6.19-take-2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: docs: hwmon: fix link to g762 devicetree binding hwmon: (emc2305) fix device node refcount leak in error path hwmon: (emc2305) fix double put in emc2305_probe_childs_from_dt hwmon: (dell-smm) Fix off-by-one error in dell_smm_is_visible() hwmon: (w83791d) Convert macros to functions to avoid TOCTOU
2 parents a110f94 + 08bfcf4 commit b88b2f8

4 files changed

Lines changed: 18 additions & 13 deletions

File tree

Documentation/hwmon/g762.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ done via a userland daemon like fancontrol.
1717
Note that those entries do not provide ways to setup the specific
1818
hardware characteristics of the system (reference clock, pulses per
1919
fan revolution, ...); Those can be modified via devicetree bindings
20-
documented in Documentation/devicetree/bindings/hwmon/g762.txt or
20+
documented in Documentation/devicetree/bindings/hwmon/gmt,g762.yaml or
2121
using a specific platform_data structure in board initialization
2222
file (see include/linux/platform_data/g762.h).
2323

drivers/hwmon/dell-smm-hwmon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,9 +861,9 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types
861861
if (auto_fan) {
862862
/*
863863
* The setting affects all fans, so only create a
864-
* single attribute.
864+
* single attribute for the first fan channel.
865865
*/
866-
if (channel != 1)
866+
if (channel != 0)
867867
return 0;
868868

869869
/*

drivers/hwmon/emc2305.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,8 @@ static int emc2305_probe_childs_from_dt(struct device *dev)
593593
for_each_child_of_node(dev->of_node, child) {
594594
if (of_property_present(child, "reg")) {
595595
ret = emc2305_of_parse_pwm_child(dev, child, data);
596-
if (ret) {
597-
of_node_put(child);
596+
if (ret)
598597
continue;
599-
}
600598
count++;
601599
}
602600
}
@@ -685,8 +683,10 @@ static int emc2305_probe(struct i2c_client *client)
685683
i = 0;
686684
for_each_child_of_node(dev->of_node, child) {
687685
ret = emc2305_set_single_tz(dev, child, i);
688-
if (ret != 0)
686+
if (ret != 0) {
687+
of_node_put(child);
689688
return ret;
689+
}
690690
i++;
691691
}
692692
} else {

drivers/hwmon/w83791d.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,14 @@ static u8 fan_to_reg(long rpm, int div)
218218
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
219219
}
220220

221-
#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \
222-
((val) == 255 ? 0 : \
223-
1350000 / ((val) * (div))))
221+
static int fan_from_reg(int val, int div)
222+
{
223+
if (val == 0)
224+
return -1;
225+
if (val == 255)
226+
return 0;
227+
return 1350000 / (val * div);
228+
}
224229

225230
/* for temp1 which is 8-bit resolution, LSB = 1 degree Celsius */
226231
#define TEMP1_FROM_REG(val) ((val) * 1000)
@@ -521,7 +526,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
521526
struct w83791d_data *data = w83791d_update_device(dev); \
522527
int nr = sensor_attr->index; \
523528
return sprintf(buf, "%d\n", \
524-
FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
529+
fan_from_reg(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
525530
}
526531

527532
show_fan_reg(fan);
@@ -585,10 +590,10 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr,
585590
if (err)
586591
return err;
587592

593+
mutex_lock(&data->update_lock);
588594
/* Save fan_min */
589-
min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
595+
min = fan_from_reg(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
590596

591-
mutex_lock(&data->update_lock);
592597
data->fan_div[nr] = div_to_reg(nr, val);
593598

594599
switch (nr) {

0 commit comments

Comments
 (0)