Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a1a018e2 authored by Armin Wolf's avatar Armin Wolf Committed by Greg Kroah-Hartman
Browse files

hwmon: (dell-smm) Speed up setting of fan speed



commit c0d79987a0d82671bff374c07f2201f9bdf4aaa2 upstream.

When setting the fan speed, i8k_set_fan() calls i8k_get_fan_status(),
causing an unnecessary SMM call since from the two users of this
function, only i8k_ioctl_unlocked() needs to know the new fan status
while dell_smm_write() ignores the new fan status.
Since SMM calls can be very slow while also making error reporting
difficult for dell_smm_write(), remove the function call from
i8k_set_fan() and call it separately in i8k_ioctl_unlocked().

Tested on a Dell Inspiron 3505.

Signed-off-by: default avatarArmin Wolf <W_Armin@gmx.de>
Reviewed-by: default avatarPali Rohár <pali@kernel.org>
Link: https://lore.kernel.org/r/20211021190531.17379-6-W_Armin@gmx.de


Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 1e30073c
Loading
Loading
Loading
Loading
+8 −4
Original line number Original line Diff line number Diff line
@@ -301,7 +301,7 @@ static int i8k_get_fan_nominal_speed(int fan, int speed)
}
}


/*
/*
 * Set the fan speed (off, low, high). Returns the new fan status.
 * Set the fan speed (off, low, high, ...).
 */
 */
static int i8k_set_fan(int fan, int speed)
static int i8k_set_fan(int fan, int speed)
{
{
@@ -313,7 +313,7 @@ static int i8k_set_fan(int fan, int speed)
	speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
	speed = (speed < 0) ? 0 : ((speed > i8k_fan_max) ? i8k_fan_max : speed);
	regs.ebx = (fan & 0xff) | (speed << 8);
	regs.ebx = (fan & 0xff) | (speed << 8);


	return i8k_smm(&regs) ? : i8k_get_fan_status(fan);
	return i8k_smm(&regs);
}
}


static int i8k_get_temp_type(int sensor)
static int i8k_get_temp_type(int sensor)
@@ -427,7 +427,7 @@ static int
i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
{
{
	int val = 0;
	int val = 0;
	int speed;
	int speed, err;
	unsigned char buff[16];
	unsigned char buff[16];
	int __user *argp = (int __user *)arg;
	int __user *argp = (int __user *)arg;


@@ -488,7 +488,11 @@ i8k_ioctl_unlocked(struct file *fp, unsigned int cmd, unsigned long arg)
		if (copy_from_user(&speed, argp + 1, sizeof(int)))
		if (copy_from_user(&speed, argp + 1, sizeof(int)))
			return -EFAULT;
			return -EFAULT;


		val = i8k_set_fan(val, speed);
		err = i8k_set_fan(val, speed);
		if (err < 0)
			return err;

		val = i8k_get_fan_status(val);
		break;
		break;


	default:
	default: