2020-04-20 16:38:25

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH v2 0/2] use read_poll_timeout macro to simplify code

Simplify implementation of regmap_read_poll_timeout() macro and
regmap_field_read_poll_timeout by read_poll_timeout() macro, they have
many similar codes.

v1 -> v2:
- modify the commit comments by Markus's suggestion .

Dejin Zheng (2):
regmap: Simplify implementation of the regmap_read_poll_timeout()
macro
regmap: Simplify implementation of the
regmap_field_read_poll_timeout() macro

include/linux/regmap.h | 48 ++++++++----------------------------------
1 file changed, 9 insertions(+), 39 deletions(-)

--
2.25.0


2020-04-20 16:40:13

by Dejin Zheng

[permalink] [raw]
Subject: [PATCH v2 2/2] regmap: Simplify implementation of the regmap_field_read_poll_timeout() macro

Simplify the implementation of the macro regmap_field_read_poll_timeout()
by using the macro read_poll_timeout().

Signed-off-by: Dejin Zheng <[email protected]>
---
v1 -> v2:
- modify the commit comments by Markus's suggestion .

include/linux/regmap.h | 23 ++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 299c1f6a03b4..78ddf224f988 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -194,25 +194,10 @@ struct reg_sequence {
*/
#define regmap_field_read_poll_timeout(field, val, cond, sleep_us, timeout_us) \
({ \
- u64 __timeout_us = (timeout_us); \
- unsigned long __sleep_us = (sleep_us); \
- ktime_t timeout = ktime_add_us(ktime_get(), __timeout_us); \
- int pollret; \
- might_sleep_if(__sleep_us); \
- for (;;) { \
- pollret = regmap_field_read((field), &(val)); \
- if (pollret) \
- break; \
- if (cond) \
- break; \
- if (__timeout_us && ktime_compare(ktime_get(), timeout) > 0) { \
- pollret = regmap_field_read((field), &(val)); \
- break; \
- } \
- if (__sleep_us) \
- usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
- } \
- pollret ?: ((cond) ? 0 : -ETIMEDOUT); \
+ int __ret, __tmp; \
+ __tmp = read_poll_timeout(regmap_field_read, __ret, __ret || (cond), \
+ sleep_us, timeout_us, false, (field), &(val)); \
+ __ret ?: __tmp; \
})

#ifdef CONFIG_REGMAP
--
2.25.0