Skip to contentSkip to conversation

platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula

PATCH In review Barnabás Pőcze 1 participant 1 message Feb 3, 2021 x86 platform drivers

lore
Share & tools
lore
#0 lore raw

PATCH v3 10/29 platform/x86: ideapad-laptop: use msecs_to_jiffies() helper instead of hand-crafted formula

The current code used a hand-crafted formula to convert milliseconds to jiffies, replace it with the msecs_to_jiffies() function. Furthermore, use a while loop instead of for loop for shorter lines and simplicity.

drivers/platform/x86/ideapad-laptop.c +7 -4
index 5978770bac2a..bb7eb9c1f0ec 100644
@@ -19,6 +19,7 @@
 #include <linux/init.h>
 #include <linux/input.h>
 #include <linux/input/sparse-keymap.h>
+#include <linux/jiffies.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -221,8 +222,9 @@ static int read_ec_data(acpi_handle handle, int cmd, unsigned long *data)
 	if (method_vpcw(handle, 1, cmd))
 		return -1;
 
-	for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
-	     time_before(jiffies, end_jiffies);) {
+	end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
+
+	while (time_before(jiffies, end_jiffies)) {
 		schedule();
 		if (method_vpcr(handle, 1, &val))
 			return -1;
@@ -247,8 +249,9 @@ static int write_ec_cmd(acpi_handle handle, int cmd, unsigned long data)
 	if (method_vpcw(handle, 1, cmd))
 		return -1;
 
-	for (end_jiffies = jiffies+(HZ)*IDEAPAD_EC_TIMEOUT/1000+1;
-	     time_before(jiffies, end_jiffies);) {
+	end_jiffies = jiffies + msecs_to_jiffies(IDEAPAD_EC_TIMEOUT) + 1;
+
+	while (time_before(jiffies, end_jiffies)) {
 		schedule();
 		if (method_vpcr(handle, 1, &val))
 			return -1;
Signature · 1 line
2.30.0