Skip to contentSkip to conversation

hwmon: (macsmc) Allow enable writing to fan speeds by modifying sysfs

PATCH Applied Aditya Garg 3 participants 3 messages Oct 18 – Oct 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 1500ec2cc..76c485832 100644
@@ -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
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

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.

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Applied
#2 lore raw
In reply to Aditya Garg
Quoted 27 lines · Aditya Garg

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.

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.

Applied.

Thanks,
Guenter