hwmon: (macsmc) Allow enable writing to fan speeds by modifying sysfs
Subsystems (2)
PATCH 1/1 hwmon: (macsmc) Allow enable writing to fan speeds by modifying sysfs
The fan_control module parameter in the driver enables/disables the user's ability to manually modify the fan speeds. In case the user attempts to change the module parameter via sysfs rather than at the time of modprobe, changing fan speeds is still restricted.
The reason behind this is because during probe the fan_control variable is used to restrict the user in the following two ways:
1. if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key == 0)
return -EOPNOTSUPP;
Here, if disabled, the OS will return an error and will not allow changing the speeds.
2. if (fan->attrs & BIT(attr)) {
if (attr == hwmon_fan_target && fan_control && fan->mode.macsmc_key)
return 0644;
return 0444;
}Here, if disabled, the sysfs files are with permissions 0444.
In case a user changes the module parameter via sysfs, due to the second check, the sysfs files remain with permissions 0444, and user isn't able to change the speeds.
Since 2 checks are practically unnecessary, and the second is causing problems this patch removes the second check. Now, if the module parameter is changed via sysfs, the first check will pass and user will be able to modify the fan speeds.
--- drivers/hwmon/macsmc-hwmon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/hwmon/macsmc-hwmon.c +1 -1
@@ -390,7 +390,7 @@ static umode_t macsmc_hwmon_fan_is_visible(const struct macsmc_hwmon_fan *fan, u32 attr) {if (fan->attrs &BIT (attr)) { -if (attr == hwmon_fan_target && fan_control && fan->mode.macsmc_key) +if (attr == hwmon_fan_target && fan->mode.macsmc_key)return 0644 ;return 0444 ;
Signature · 1 line
2.53.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues.
Quoted 14 lines
The
fan_controlmodule parameter in the driver enables/disables the user's ability to manually modify the fan speeds. In case the user attempts to change the module parameter via sysfs rather than at the time of modprobe, changing fan speeds is still restricted.The reason behind this is because during probe the
fan_controlvariable is used to restrict the user in the following two ways:1. if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key == 0)
return -EOPNOTSUPP;Here, if disabled, the OS will return an error and will not allow changing the speeds.
Quoted 7 lines
2. if (
fan->attrs& BIT(attr)) {
[ ... ]
this patch removes the second check. Now, if the module parameter is changed via sysfs, the first check will pass and user will be able to modify the fan speeds.Signed-off-by Aditya Garg <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 27 lines · Aditya Garg
The
fan_controlmodule parameter in the driver enables/disables the user's ability to manually modify the fan speeds. In case the user attempts to change the module parameter via sysfs rather than at the time of modprobe, changing fan speeds is still restricted.The reason behind this is because during probe the
fan_controlvariable is used to restrict the user in the following two ways:1. if (!fan_control || hwmon->fan.fans[channel].mode.macsmc_key == 0)
return -EOPNOTSUPP;Here, if disabled, the OS will return an error and will not allow changing the speeds.
2. if (fan->attrs & BIT(attr)) { if (attr == hwmon_fan_target && fan_control && fan->mode.macsmc_key) return 0644; return 0444; }Here, if disabled, the sysfs files are with permissions 0444.
In case a user changes the module parameter via sysfs, due to the second check, the sysfs files remain with permissions 0444, and user isn't able to change the speeds.
Quoted 6 lines
Since 2 checks are practically unnecessary, and the second is causing problems this patch removes the second check. Now, if the module parameter is changed via sysfs, the first check will pass and user will be able to modify the fan speeds.
Signed-off-by Aditya Garg <[email protected]>
Applied.
Thanks,
Guenter