Skip to contentSkip to conversation

platform/x86/drivers/acerhdf: Use module_param_cb to set/get polling interval

PATCH Applied Daniel Lezcano 4 participants 9 messages Dec 3, 2020 – Dec 11, 2020

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

PATCH v2 1/2 platform/x86/drivers/acerhdf: Use module_param_cb to set/get polling interval

The module parameter can be set by using ops to get and set the values. The change will allow to check the correctness of the interval value everytime it is changed instead of checking in the get_temp function.

---
 drivers/platform/x86/acerhdf.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/acerhdf.c +8 -2
index 44b6bfbd32df..19fc8ff2225c 100644
@@ -84,8 +84,6 @@ static struct platform_device *acerhdf_dev;
 
 module_param(kernelmode, uint, 0);
 MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off");
-module_param(interval, uint, 0600);
-MODULE_PARM_DESC(interval, "Polling interval of temperature check");
 module_param(fanon, uint, 0600);
 MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature");
 module_param(fanoff, uint, 0600);
@@ -824,3 +822,11 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
+
+static const struct kernel_param_ops interval_ops = {
+	.set = param_set_uint,
+	.get = param_get_uint,
+};
+
+module_param_cb(interval, &interval_ops, &interval, 0600);
+MODULE_PARM_DESC(interval, "Polling interval of temperature check");
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 platform/x86/drivers/acerhdf: Check the interval value when it is set

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

I don't have any hardware to test the changes.

---
V2:
- Fixed static function annotation

---
 drivers/platform/x86/acerhdf.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/platform/x86/acerhdf.c +18 -4
index 19fc8ff2225c..b6aa6e5514f4 100644
@@ -334,7 +334,10 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
 		}
 		if (verbose)
 			pr_notice("interval changed to: %d\n", interval);
-		thermal->polling_delay = interval*1000;
+
+		if (thermal)
+			thermal->polling_delay = interval*1000;
+
 		prev_interval = interval;
 	}
 }
@@ -349,8 +352,6 @@ static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
 {
 	int temp, err = 0;
 
-	acerhdf_check_param(thermal);
-
 	err = acerhdf_get_temp(&temp);
 	if (err)
 		return err;
@@ -823,8 +824,21 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
 
+static int interval_set_uint(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+
+	ret = param_set_uint(val, kp);
+	if (ret)
+		return ret;
+
+	acerhdf_check_param(thz_dev);
+
+	return 0;
+}
+
 static const struct kernel_param_ops interval_ops = {
-	.set = param_set_uint,
+	.set = interval_set_uint,
 	.get = param_get_uint,
 };
 
Signature · 1 line
2.25.1
maintainer Acked-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] platform/x86/drivers/acerhdf: Check the interval value when it is set

Quoted 6 lines · Daniel Lezcano

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

Quoted 8 lines

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

Thanks for your effort. This improves the code, good finding.

Quoted 1 line

I don't have any hardware to test the changes.

Tests successfully executed on my good old AOA110.

Quoted 1 line
Quoted 57 lines

---
V2:
- Fixed static function annotation
---
drivers/platform/x86/acerhdf.c | 22 ++++++++++++++++++----

1 file changed, 18 insertions(+), 4 deletions(-)
drivers/platform/x86/acerhdf.c +18 -4
index 19fc8ff2225c..b6aa6e5514f4 100644
@@ -334,7 +334,10 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
 }
 if (verbose)
 pr_notice("interval changed to: %d\n", interval);
- thermal->polling_delay = interval*1000;
+
+ if (thermal)
+ thermal->polling_delay = interval*1000;
+
 prev_interval = interval;
 }
 }
@@ -349,8 +352,6 @@ static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
 {
 int temp, err = 0;
 
- acerhdf_check_param(thermal);
-
 err = acerhdf_get_temp(&temp);
 if (err)
 return err;
@@ -823,8 +824,21 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
 
+static int interval_set_uint(const char *val, const struct kernel_param *kp)
+{
+ int ret;
+
+ ret = param_set_uint(val, kp);
+ if (ret)
+ return ret;
+
+ acerhdf_check_param(thz_dev);
+
+ return 0;
+}
+
 static const struct kernel_param_ops interval_ops = {
- .set = param_set_uint,
+ .set = interval_set_uint,
 .get = param_get_uint,
 };
 
Signature · 1 line
2.25.1
#3 lore raw

Re: [PATCH v2 2/2] platform/x86/drivers/acerhdf: Check the interval value when it is set

Quoted 20 lines · Peter Kästle
Quoted 6 lines · Daniel Lezcano

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

Quoted 8 lines

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

Thanks for your effort. This improves the code, good finding.

Quoted 8 lines
Quoted 1 line

I don't have any hardware to test the changes.

Tests successfully executed on my good old AOA110.

Quoted 1 line

Thanks for testing the changes.

Shall pick the patches through the thermal tree ?

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
Acked-by
#4 lore raw

Re: [PATCH v2 2/2] platform/x86/drivers/acerhdf: Check the interval value when it is set

Hi,

Quoted 26 lines · Daniel Lezcano
Quoted 25 lines · Peter Kästle
Quoted 6 lines · Daniel Lezcano

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

Quoted 8 lines

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

Thanks for your effort. This improves the code, good finding.

Quoted 1 line

I don't have any hardware to test the changes.

Tests successfully executed on my good old AOA110.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks for testing the changes.

Shall pick the patches through the thermal tree ?

I can take them through the drivers/platform/x86 (pdx86) tree, but if you prefer to take them upstream through the thermal tree, then that is fine too...

Here is my ack (as pdx86 maintainer) for taking them through the thermal tree:

Regards,

Hans

#5 lore raw

Re: [PATCH v2 2/2] platform/x86/drivers/acerhdf: Check the interval value when it is set

Quoted 37 lines · Hans de Goede

Hi,

Quoted 26 lines · Daniel Lezcano
Quoted 25 lines · Peter Kästle
Quoted 6 lines · Daniel Lezcano

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

Quoted 8 lines

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

Thanks for your effort. This improves the code, good finding.

Quoted 1 line

I don't have any hardware to test the changes.

Tests successfully executed on my good old AOA110.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks for testing the changes.

Shall pick the patches through the thermal tree ?

Quoted 8 lines

I can take them through the drivers/platform/x86 (pdx86) tree, but if you prefer to take them upstream through the thermal tree, then that is fine too...

Here is my ack (as pdx86 maintainer) for taking them through the thermal tree:

Thanks. I'll take them through the thermal tree.

-- Daniel

Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
#6 lore raw

[thermal: thermal/next] platform/x86/drivers/acerhdf: Check the interval value when it is set

In reply to Daniel Lezcano
The following commit has been merged into the thermal/next branch of thermal:

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     f34a32fae7fde6655ada6b33dc6739c9d1b6a82c
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//f34a32fae7fde6655ada6b33dc6739c9d1b6a82c
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Thu, 03 Dec 2020 08:17:38 +01:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Mon, 07 Dec 2020 17:04:50 +01:00

platform/x86/drivers/acerhdf: Check the interval value when it is set

Currently the code checks the interval value when the temperature is read which is bad for two reasons:

- checking and setting the interval in the get_temp callback is inaccurate and awful, that can be done when changing the value.

- Changing the thermal zone structure internals is an abuse of the exported structure, moreover no lock is taken here.

The goal of this patch is to solve the first item by using the 'set' function called when changing the interval. The check is done there and removed from the get_temp function. If the thermal zone was not initialized yet, the interval is not updated in this case as that will happen in the init function when registering the thermal zone device.

I don't have any hardware to test the changes.

---
 drivers/platform/x86/acerhdf.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
drivers/platform/x86/acerhdf.c +18 -4
index 19fc8ff..b6aa6e5 100644
@@ -334,7 +334,10 @@ static void acerhdf_check_param(struct thermal_zone_device *thermal)
 		}
 		if (verbose)
 			pr_notice("interval changed to: %d\n", interval);
-		thermal->polling_delay = interval*1000;
+
+		if (thermal)
+			thermal->polling_delay = interval*1000;
+
 		prev_interval = interval;
 	}
 }
@@ -349,8 +352,6 @@ static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
 {
 	int temp, err = 0;
 
-	acerhdf_check_param(thermal);
-
 	err = acerhdf_get_temp(&temp);
 	if (err)
 		return err;
@@ -823,8 +824,21 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
 
+static int interval_set_uint(const char *val, const struct kernel_param *kp)
+{
+	int ret;
+
+	ret = param_set_uint(val, kp);
+	if (ret)
+		return ret;
+
+	acerhdf_check_param(thz_dev);
+
+	return 0;
+}
+
 static const struct kernel_param_ops interval_ops = {
-	.set = param_set_uint,
+	.set = interval_set_uint,
 	.get = param_get_uint,
 };
 
maintainer Acked-by on v2 1/2
#7 lore raw
In reply to Daniel Lezcano
Quoted 6 lines · Daniel Lezcano

The module parameter can be set by using ops to get and set the values. The change will allow to check the correctness of the interval value everytime it is changed instead of checking in the get_temp function.

Quoted 31 lines

---
drivers/platform/x86/acerhdf.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/acerhdf.c +8 -2
index 44b6bfbd32df..19fc8ff2225c 100644
@@ -84,8 +84,6 @@ static struct platform_device *acerhdf_dev;
 
 module_param(kernelmode, uint, 0);
 MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off");
-module_param(interval, uint, 0600);
-MODULE_PARM_DESC(interval, "Polling interval of temperature check");
 module_param(fanon, uint, 0600);
 MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature");
 module_param(fanoff, uint, 0600);
@@ -824,3 +822,11 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
+
+static const struct kernel_param_ops interval_ops = {
+ .set = param_set_uint,
+ .get = param_get_uint,
+};
+
+module_param_cb(interval, &interval_ops, &interval, 0600);
+MODULE_PARM_DESC(interval, "Polling interval of temperature check");
Signature · 1 line
2.25.1
#8 lore raw
In reply to Daniel Lezcano
The following commit has been merged into the thermal/next branch of thermal:

The following commit has been merged into the thermal/next branch of thermal:

Commit-ID:     a65181c41e57709053892832d261956afe281deb
Gitweb:        https://git.kernel.org/pub/scm/linux/kernel/git/thermal/linux.git//a65181c41e57709053892832d261956afe281deb
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Thu, 03 Dec 2020 08:17:37 +01:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Mon, 07 Dec 2020 17:03:58 +01:00

platform/x86/drivers/acerhdf: Use module_param_cb to set/get polling interval

The module parameter can be set by using ops to get and set the values. The change will allow to check the correctness of the interval value everytime it is changed instead of checking in the get_temp function.

---
 drivers/platform/x86/acerhdf.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/platform/x86/acerhdf.c +8 -2
index 44b6bfb..19fc8ff 100644
@@ -84,8 +84,6 @@ static struct platform_device *acerhdf_dev;
 
 module_param(kernelmode, uint, 0);
 MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off");
-module_param(interval, uint, 0600);
-MODULE_PARM_DESC(interval, "Polling interval of temperature check");
 module_param(fanon, uint, 0600);
 MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature");
 module_param(fanoff, uint, 0600);
@@ -824,3 +822,11 @@ MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
 
 module_init(acerhdf_init);
 module_exit(acerhdf_exit);
+
+static const struct kernel_param_ops interval_ops = {
+	.set = param_set_uint,
+	.get = param_get_uint,
+};
+
+module_param_cb(interval, &interval_ops, &interval, 0600);
+MODULE_PARM_DESC(interval, "Polling interval of temperature check");