All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
@ 2020-04-19 17:09 ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-04-19 17:09 UTC (permalink / raw)
  To: Dejin Zheng, Mark Brown; +Cc: linux-kernel, kernel-janitors

> use read_poll_timeout macro to redefined regmap_read_poll_timeout
> and also remove the duplicate code.

How do you think about a wording variant like the following?

   Subject:
   [PATCH 1/2] regmap: Simplify implementation of the regmap_read_poll_timeout() macro

   Change description:
   Simplify the implementation of the macro “regmap_read_poll_timeout”
   by using the macro “read_poll_timeout”.


…
> +++ b/include/linux/regmap.h
> @@ -122,26 +123,10 @@ struct reg_sequence {
>   */
>  #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
>  ({ \
> +	int __ret, __tmp; \
> +	__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
> +			sleep_us, timeout_us, false, (map), (addr), &(val)); \
> +	__ret ?: __tmp; \
>  })

* Can this macro work also with variable names which do not contain
  double underscores?

* Can the tag “Fixes” be relevant for such an adjustment?

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
@ 2020-04-19 17:09 ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-04-19 17:09 UTC (permalink / raw)
  To: Dejin Zheng, Mark Brown; +Cc: linux-kernel, kernel-janitors

> use read_poll_timeout macro to redefined regmap_read_poll_timeout
> and also remove the duplicate code.

How do you think about a wording variant like the following?

   Subject:
   [PATCH 1/2] regmap: Simplify implementation of the regmap_read_poll_timeout() macro

   Change description:
   Simplify the implementation of the macro “regmap_read_poll_timeout”
   by using the macro “read_poll_timeout”.


…
> +++ b/include/linux/regmap.h
> @@ -122,26 +123,10 @@ struct reg_sequence {
>   */
>  #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
>  ({ \
> +	int __ret, __tmp; \
> +	__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
> +			sleep_us, timeout_us, false, (map), (addr), &(val)); \
> +	__ret ?: __tmp; \
>  })

* Can this macro work also with variable names which do not contain
  double underscores?

* Can the tag “Fixes” be relevant for such an adjustment?

Regards,
Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
  2020-04-19 17:09 ` Markus Elfring
@ 2020-04-20 13:30   ` Dejin Zheng
  -1 siblings, 0 replies; 5+ messages in thread
From: Dejin Zheng @ 2020-04-20 13:30 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Mark Brown, linux-kernel, kernel-janitors

On Sun, Apr 19, 2020 at 07:09:14PM +0200, Markus Elfring wrote:
> > use read_poll_timeout macro to redefined regmap_read_poll_timeout
> > and also remove the duplicate code.
> 
> How do you think about a wording variant like the following?
> 
>    Subject:
>    [PATCH 1/2] regmap: Simplify implementation of the regmap_read_poll_timeout() macro
> 
>    Change description:
>    Simplify the implementation of the macro “regmap_read_poll_timeout”
>    by using the macro “read_poll_timeout”.
>
Good, I will send the patch v2.
> 
> …
> > +++ b/include/linux/regmap.h
> …
> > @@ -122,26 +123,10 @@ struct reg_sequence {
> >   */
> >  #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
> >  ({ \
> …
> > +	int __ret, __tmp; \
> > +	__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
> > +			sleep_us, timeout_us, false, (map), (addr), &(val)); \
> > +	__ret ?: __tmp; \
> >  })
> 
> * Can this macro work also with variable names which do not contain
>   double underscores?
>
Yes, this is to avoid using the same variable with its caller.

> * Can the tag “Fixes” be relevant for such an adjustment?
>
I think It is not relevant and we don't need add it.

BR,
Dejin

> Regards,
> Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
@ 2020-04-20 13:30   ` Dejin Zheng
  0 siblings, 0 replies; 5+ messages in thread
From: Dejin Zheng @ 2020-04-20 13:30 UTC (permalink / raw)
  To: Markus Elfring; +Cc: Mark Brown, linux-kernel, kernel-janitors

On Sun, Apr 19, 2020 at 07:09:14PM +0200, Markus Elfring wrote:
> > use read_poll_timeout macro to redefined regmap_read_poll_timeout
> > and also remove the duplicate code.
> 
> How do you think about a wording variant like the following?
> 
>    Subject:
>    [PATCH 1/2] regmap: Simplify implementation of the regmap_read_poll_timeout() macro
> 
>    Change description:
>    Simplify the implementation of the macro “regmap_read_poll_timeout”
>    by using the macro “read_poll_timeout”.
>
Good, I will send the patch v2.
> 
> …
> > +++ b/include/linux/regmap.h
> …
> > @@ -122,26 +123,10 @@ struct reg_sequence {
> >   */
> >  #define regmap_read_poll_timeout(map, addr, val, cond, sleep_us, timeout_us) \
> >  ({ \
> …
> > +	int __ret, __tmp; \
> > +	__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
> > +			sleep_us, timeout_us, false, (map), (addr), &(val)); \
> > +	__ret ?: __tmp; \
> >  })
> 
> * Can this macro work also with variable names which do not contain
>   double underscores?
>
Yes, this is to avoid using the same variable with its caller.

> * Can the tag “Fixes” be relevant for such an adjustment?
>
I think It is not relevant and we don't need add it.

BR,
Dejin

> Regards,
> Markus

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code
  2020-04-19 13:51 [PATCH v1 0/2] use read_poll_timeout macro " Dejin Zheng
@ 2020-04-19 13:51 ` Dejin Zheng
  0 siblings, 0 replies; 5+ messages in thread
From: Dejin Zheng @ 2020-04-19 13:51 UTC (permalink / raw)
  To: broonie, linux-kernel; +Cc: Dejin Zheng

use read_poll_timeout macro to redefined regmap_read_poll_timeout
and also remove the duplicate code.

Signed-off-by: Dejin Zheng <zhengdejin5@gmail.com>
---
 include/linux/regmap.h | 25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 40b07168fd8e..299c1f6a03b4 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -17,6 +17,7 @@
 #include <linux/err.h>
 #include <linux/bug.h>
 #include <linux/lockdep.h>
+#include <linux/iopoll.h>
 
 struct module;
 struct clk;
@@ -122,26 +123,10 @@ struct reg_sequence {
  */
 #define regmap_read_poll_timeout(map, addr, 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 __ret; \
-	might_sleep_if(__sleep_us); \
-	for (;;) { \
-		__ret = regmap_read((map), (addr), &(val)); \
-		if (__ret) \
-			break; \
-		if (cond) \
-			break; \
-		if ((__timeout_us) && \
-		    ktime_compare(ktime_get(), __timeout) > 0) { \
-			__ret = regmap_read((map), (addr), &(val)); \
-			break; \
-		} \
-		if (__sleep_us) \
-			usleep_range((__sleep_us >> 2) + 1, __sleep_us); \
-	} \
-	__ret ?: ((cond) ? 0 : -ETIMEDOUT); \
+	int __ret, __tmp; \
+	__tmp = read_poll_timeout(regmap_read, __ret, __ret || (cond), \
+			sleep_us, timeout_us, false, (map), (addr), &(val)); \
+	__ret ?: __tmp; \
 })
 
 /**
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-20 13:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-19 17:09 [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout to simplify code Markus Elfring
2020-04-19 17:09 ` Markus Elfring
2020-04-20 13:30 ` Dejin Zheng
2020-04-20 13:30   ` Dejin Zheng
  -- strict thread matches above, loose matches on Subject: below --
2020-04-19 13:51 [PATCH v1 0/2] use read_poll_timeout macro " Dejin Zheng
2020-04-19 13:51 ` [PATCH v1 1/2] regmap: redefined regmap_read_poll_timeout " Dejin Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.