Skip to contentSkip to conversation

serdev: Replace poll loop by readx_poll_timeout() macro

PATCH Superseded Andy Shevchenko 2 participants 3 messages Sep 23, 2022 – Sep 26, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serdev: Replace poll loop by readx_poll_timeout() macro

The readx_poll_timeout() consolidates the necessary code under macro. Replace current code with it.

---
v2: dropped TODO: in the Subject line

 include/linux/serdev.h | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
include/linux/serdev.h +4 -10
index 66f624fc618c..69d9c3188065 100644
@@ -7,9 +7,11 @@
 
 #include <linux/types.h>
 #include <linux/device.h>
+#include <linux/iopoll.h>
 #include <linux/uaccess.h>
 #include <linux/termios.h>
 #include <linux/delay.h>
+#include <vdso/time64.h>
 
 struct serdev_controller;
 struct serdev_device;
@@ -279,18 +281,10 @@ static inline bool serdev_device_get_cts(struct serdev_device *serdev)
 
 static inline int serdev_device_wait_for_cts(struct serdev_device *serdev, bool state, int timeout_ms)
 {
-	unsigned long timeout;
 	bool signal;
 
-	timeout = jiffies + msecs_to_jiffies(timeout_ms);
-	while (time_is_after_jiffies(timeout)) {
-		signal = serdev_device_get_cts(serdev);
-		if (signal == state)
-			return 0;
-		usleep_range(1000, 2000);
-	}
-
-	return -ETIMEDOUT;
+	return readx_poll_timeout(serdev_device_get_cts, serdev, signal, signal == state,
+				  2000, timeout_ms * USEC_PER_MSEC);
 }
 
 static inline int serdev_device_set_rts(struct serdev_device *serdev, bool enable)
Signature · 1 line
2.35.1
#1 lore raw
Quoted 14 lines · Andy Shevchenko

The readx_poll_timeout() consolidates the necessary code under macro. Replace current code with it.

---
v2: dropped TODO: in the Subject line

 include/linux/serdev.h | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
include/linux/serdev.h +0 -0
index 66f624fc618c..69d9c3188065 100644

include/linux/serdev.h line 14

Quoted 8 lines
include/linux/serdev.h +2 -0
@@ -7,9 +7,11 @@
 
 #include <linux/types.h>
 #include <linux/device.h>
+#include <linux/iopoll.h>
 #include <linux/uaccess.h>
 #include <linux/termios.h>
 #include <linux/delay.h>
+#include <vdso/time64.h>

Ick, just for USEC_PER_MSEC? That should be in units.h, not burried in a vdso-only .h file. This feels wrong, sorry.

greg k-h

#2 lore raw
Quoted 3 lines · Greg Kroah-Hartman
Quoted 2 lines · Andy Shevchenko

The readx_poll_timeout() consolidates the necessary code under macro. Replace current code with it.

...

Quoted 4 lines
Quoted 1 line

+#include <vdso/time64.h>

Ick, just for USEC_PER_MSEC? That should be in units.h, not burried in a vdso-only .h file. This feels wrong, sorry.

Why are you asking me about this? It was not my choice and it was made a couple of years ago (see [1]).

As a solution I can just drop using that constant in v3.

[1]: b72a9c5e023b ("linux/time64.h: Extract common header for vDSO")

Signature · 2 lines
With Best Regards,
Andy Shevchenko