hwmon fixes for v6.19-rc1

* 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
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCAAdFiEEiHPvMQj9QTOCiqgVyx8mb86fmYEFAmk25tQACgkQyx8mb86f
 mYEHzQ/+N07lGU1M1uv1Jr3FLGntiT7yIh04zgxwxqE9+R1bTWV/+x9K6s2kDNyG
 Q+UYjtV3mEf7EawvAeXgo8Zi+9V5lKdCvUonIJ20Gx88aOPjWdBesmztUNTg7pJi
 S9Au9R+w0oDZWWdtnwVEmLfMAL6huCusoj2pb4miaFcxzBa1ZlzH5whtwW1uRBQm
 NbRW+Wn6Yuf317rF2nGaGTKp9U7iGUid8ONl0wdCJGikamnf46g+m5r0QzpcinNS
 Km0wK+YatBVhWte6kQ1YE+3oI0uLXtA70J0SKUeyw0CnyuCX+Z/D5LMp7X5y2cDV
 /kxqV5WcU0H1VQOKeRga8vclBhqN32vad8nOJ/sKYUezoZpbkrIIu7I0u2ZKZbX1
 LdVtq5i47Llt/zY/V1tBaXkn+bXbYeGZdbUvsyK0r93MLZOg98VZ5j1PkwresP5o
 QqlpYTUNw6vS/zkec248hR111wBGDXsMBkV1SbMDHlnVzcALUG5IQWdSUUHn6NYi
 yT/cJwCgv6h5wg0ZWhs3ogNGd9FAVJN/+xYMARfxEkVkvQCUJEa1HozuRTzaJFN3
 3E7z63ouq9sKPEyc+3bIA3qJGwXpg8XhVFm098lgAeESOLwf9anc/tWU9BCQMOyD
 iTdQMeTWVI/XAldw1oqJKlrKjxyzw9y8tpn0htkmn5xdGbVqpGs=
 =M9bd
 -----END PGP SIGNATURE-----

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
pull/1354/merge
Linus Torvalds 2025-12-09 08:46:10 +09:00
commit b88b2f82fa
4 changed files with 19 additions and 14 deletions

View File

@ -17,7 +17,7 @@ done via a userland daemon like fancontrol.
Note that those entries do not provide ways to setup the specific Note that those entries do not provide ways to setup the specific
hardware characteristics of the system (reference clock, pulses per hardware characteristics of the system (reference clock, pulses per
fan revolution, ...); Those can be modified via devicetree bindings fan revolution, ...); Those can be modified via devicetree bindings
documented in Documentation/devicetree/bindings/hwmon/g762.txt or documented in Documentation/devicetree/bindings/hwmon/gmt,g762.yaml or
using a specific platform_data structure in board initialization using a specific platform_data structure in board initialization
file (see include/linux/platform_data/g762.h). file (see include/linux/platform_data/g762.h).

View File

@ -861,9 +861,9 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types
if (auto_fan) { if (auto_fan) {
/* /*
* The setting affects all fans, so only create a * The setting affects all fans, so only create a
* single attribute. * single attribute for the first fan channel.
*/ */
if (channel != 1) if (channel != 0)
return 0; return 0;
/* /*

View File

@ -593,10 +593,8 @@ static int emc2305_probe_childs_from_dt(struct device *dev)
for_each_child_of_node(dev->of_node, child) { for_each_child_of_node(dev->of_node, child) {
if (of_property_present(child, "reg")) { if (of_property_present(child, "reg")) {
ret = emc2305_of_parse_pwm_child(dev, child, data); ret = emc2305_of_parse_pwm_child(dev, child, data);
if (ret) { if (ret)
of_node_put(child);
continue; continue;
}
count++; count++;
} }
} }
@ -685,8 +683,10 @@ static int emc2305_probe(struct i2c_client *client)
i = 0; i = 0;
for_each_child_of_node(dev->of_node, child) { for_each_child_of_node(dev->of_node, child) {
ret = emc2305_set_single_tz(dev, child, i); ret = emc2305_set_single_tz(dev, child, i);
if (ret != 0) if (ret != 0) {
of_node_put(child);
return ret; return ret;
}
i++; i++;
} }
} else { } else {

View File

@ -218,9 +218,14 @@ static u8 fan_to_reg(long rpm, int div)
return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
} }
#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : \ static int fan_from_reg(int val, int div)
((val) == 255 ? 0 : \ {
1350000 / ((val) * (div)))) if (val == 0)
return -1;
if (val == 255)
return 0;
return 1350000 / (val * div);
}
/* for temp1 which is 8-bit resolution, LSB = 1 degree Celsius */ /* for temp1 which is 8-bit resolution, LSB = 1 degree Celsius */
#define TEMP1_FROM_REG(val) ((val) * 1000) #define TEMP1_FROM_REG(val) ((val) * 1000)
@ -521,7 +526,7 @@ static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
struct w83791d_data *data = w83791d_update_device(dev); \ struct w83791d_data *data = w83791d_update_device(dev); \
int nr = sensor_attr->index; \ int nr = sensor_attr->index; \
return sprintf(buf, "%d\n", \ return sprintf(buf, "%d\n", \
FAN_FROM_REG(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \ fan_from_reg(data->reg[nr], DIV_FROM_REG(data->fan_div[nr]))); \
} }
show_fan_reg(fan); show_fan_reg(fan);
@ -585,10 +590,10 @@ static ssize_t store_fan_div(struct device *dev, struct device_attribute *attr,
if (err) if (err)
return err; return err;
/* Save fan_min */
min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
/* Save fan_min */
min = fan_from_reg(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
data->fan_div[nr] = div_to_reg(nr, val); data->fan_div[nr] = div_to_reg(nr, val);
switch (nr) { switch (nr) {