linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/15] i2c: use 'time_left' with wait_for_*
@ 2024-04-27 20:35 Wolfram Sang
  2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Wolfram Sang @ 2024-04-27 20:35 UTC (permalink / raw)
  To: linux-i2c
  Cc: Wolfram Sang, imx, linux-arm-kernel, linux-arm-msm, linux-kernel,
	linux-mips, linux-omap, linux-rockchip, linux-samsung-soc,
	linux-stm32

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_*() causing patterns like:

        timeout = wait_for_completion_timeout(...)
        if (!timeout) return -ETIMEDOUT;

with all kinds of permutations. Use 'time_left' as a variable to make the code
self explaining.

This is the I2C part of a tree-wide series. The rest of the patches can
be found here (slightly WIP):

git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/time_left

Because these patches are generated, they need manual audit. So, I will
send them step by step. This is part 1 and also a call for opinions if
this is a desirable change. But at least in the I2C realm, I really want
to have it proper.

Build bot is happy with these patches and I also compile tested them
(except two). No functional changes intended.

Wolfram Sang (15):
  i2c: amd-mp2-plat: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: digicolor: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: exynos5: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: hix5hd2: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: imx-lpi2c: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: omap: use 'time_left' variable with wait_for_completion_timeout()
  i2c: st: use 'time_left' variable with wait_for_completion_timeout()
  i2c: stm32f4: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: stm32f7: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: synquacer: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: jz4780: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: qcom-geni: use 'time_left' variable with
    wait_for_completion_timeout()
  i2c: rk3x: use 'time_left' variable with wait_event_timeout()
  i2c: s3c2410: use 'time_left' variable with wait_event_timeout()
  i2c: pxa: use 'time_left' variable with wait_event_timeout()

-- 
2.43.0


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

* [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-27 20:35 [PATCH 00/15] i2c: use 'time_left' with wait_for_* Wolfram Sang
@ 2024-04-27 20:36 ` Wolfram Sang
  2024-04-30 12:43   ` Philippe Mathieu-Daudé
  2024-04-30 12:49   ` Paul Cercueil
  2024-04-30  0:07 ` [PATCH 00/15] i2c: use 'time_left' with wait_for_* Andi Shyti
  2024-05-02 11:29 ` Andi Shyti
  2 siblings, 2 replies; 6+ messages in thread
From: Wolfram Sang @ 2024-04-27 20:36 UTC (permalink / raw)
  To: linux-i2c
  Cc: Wolfram Sang, Paul Cercueil, Andi Shyti, linux-mips, linux-kernel

There is a confusing pattern in the kernel to use a variable named 'timeout' to
store the result of wait_for_completion_timeout() causing patterns like:

	timeout = wait_for_completion_timeout(...)
	if (!timeout) return -ETIMEDOUT;

with all kinds of permutations. Use 'time_left' as a variable to make the code
self explaining.

Fix to the proper variable type 'unsigned long' while here.

Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
 drivers/i2c/busses/i2c-jz4780.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-jz4780.c b/drivers/i2c/busses/i2c-jz4780.c
index 55035cca0ae5..7951891d6b97 100644
--- a/drivers/i2c/busses/i2c-jz4780.c
+++ b/drivers/i2c/busses/i2c-jz4780.c
@@ -565,7 +565,7 @@ static inline int jz4780_i2c_xfer_read(struct jz4780_i2c *i2c,
 				       int idx)
 {
 	int ret = 0;
-	long timeout;
+	unsigned long time_left;
 	int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
 	unsigned short tmp;
 	unsigned long flags;
@@ -600,10 +600,10 @@ static inline int jz4780_i2c_xfer_read(struct jz4780_i2c *i2c,
 
 	spin_unlock_irqrestore(&i2c->lock, flags);
 
-	timeout = wait_for_completion_timeout(&i2c->trans_waitq,
-					      msecs_to_jiffies(wait_time));
+	time_left = wait_for_completion_timeout(&i2c->trans_waitq,
+						msecs_to_jiffies(wait_time));
 
-	if (!timeout) {
+	if (!time_left) {
 		dev_err(&i2c->adap.dev, "irq read timeout\n");
 		dev_dbg(&i2c->adap.dev, "send cmd count:%d  %d\n",
 			i2c->cmd, i2c->cmd_buf[i2c->cmd]);
@@ -627,7 +627,7 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
 {
 	int ret = 0;
 	int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
-	long timeout;
+	unsigned long time_left;
 	unsigned short tmp;
 	unsigned long flags;
 
@@ -655,14 +655,14 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
 
 	spin_unlock_irqrestore(&i2c->lock, flags);
 
-	timeout = wait_for_completion_timeout(&i2c->trans_waitq,
-					      msecs_to_jiffies(wait_time));
-	if (timeout && !i2c->stop_hold) {
+	time_left = wait_for_completion_timeout(&i2c->trans_waitq,
+						msecs_to_jiffies(wait_time));
+	if (time_left && !i2c->stop_hold) {
 		unsigned short i2c_sta;
 		int write_in_process;
 
-		timeout = JZ4780_I2C_TIMEOUT * 100;
-		for (; timeout > 0; timeout--) {
+		time_left = JZ4780_I2C_TIMEOUT * 100;
+		for (; time_left > 0; time_left--) {
 			i2c_sta = jz4780_i2c_readw(i2c, JZ4780_I2C_STA);
 
 			write_in_process = (i2c_sta & JZ4780_I2C_STA_MSTACT) ||
@@ -673,7 +673,7 @@ static inline int jz4780_i2c_xfer_write(struct jz4780_i2c *i2c,
 		}
 	}
 
-	if (!timeout) {
+	if (!time_left) {
 		dev_err(&i2c->adap.dev, "write wait timeout\n");
 		ret = -EIO;
 	}
-- 
2.43.0


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

* Re: [PATCH 00/15] i2c: use 'time_left' with wait_for_*
  2024-04-27 20:35 [PATCH 00/15] i2c: use 'time_left' with wait_for_* Wolfram Sang
  2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 2024-04-30  0:07 ` Andi Shyti
  2024-05-02 11:29 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-04-30  0:07 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, imx, linux-arm-kernel, linux-arm-msm, linux-kernel,
	linux-mips, linux-omap, linux-rockchip, linux-samsung-soc,
	linux-stm32

Hi Wolfram,

On Sat, Apr 27, 2024 at 10:35:52PM +0200, Wolfram Sang wrote:
> There is a confusing pattern in the kernel to use a variable named 'timeout' to
> store the result of wait_for_*() causing patterns like:
> 
>         timeout = wait_for_completion_timeout(...)
>         if (!timeout) return -ETIMEDOUT;
> 
> with all kinds of permutations. Use 'time_left' as a variable to make the code
> self explaining.
> 
> This is the I2C part of a tree-wide series. The rest of the patches can
> be found here (slightly WIP):
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/time_left
> 
> Because these patches are generated, they need manual audit. So, I will
> send them step by step. This is part 1 and also a call for opinions if
> this is a desirable change. But at least in the I2C realm, I really want
> to have it proper.
> 
> Build bot is happy with these patches and I also compile tested them
> (except two). No functional changes intended.

It all looks good, I will give people a few days more for reviews
and comments and then I'll take it in.

Andi

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

* Re: [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
@ 2024-04-30 12:43   ` Philippe Mathieu-Daudé
  2024-04-30 12:49   ` Paul Cercueil
  1 sibling, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-04-30 12:43 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c
  Cc: Paul Cercueil, Andi Shyti, linux-mips, linux-kernel

On 27/4/24 22:36, Wolfram Sang wrote:
> There is a confusing pattern in the kernel to use a variable named 'timeout' to
> store the result of wait_for_completion_timeout() causing patterns like:
> 
> 	timeout = wait_for_completion_timeout(...)
> 	if (!timeout) return -ETIMEDOUT;
> 
> with all kinds of permutations. Use 'time_left' as a variable to make the code
> self explaining.
> 
> Fix to the proper variable type 'unsigned long' while here.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
> ---
>   drivers/i2c/busses/i2c-jz4780.c | 22 +++++++++++-----------
>   1 file changed, 11 insertions(+), 11 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>


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

* Re: [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
  2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
  2024-04-30 12:43   ` Philippe Mathieu-Daudé
@ 2024-04-30 12:49   ` Paul Cercueil
  1 sibling, 0 replies; 6+ messages in thread
From: Paul Cercueil @ 2024-04-30 12:49 UTC (permalink / raw)
  To: Wolfram Sang, linux-i2c; +Cc: Andi Shyti, linux-mips, linux-kernel

Le samedi 27 avril 2024 à 22:36 +0200, Wolfram Sang a écrit :
> There is a confusing pattern in the kernel to use a variable named
> 'timeout' to
> store the result of wait_for_completion_timeout() causing patterns
> like:
> 
> 	timeout = wait_for_completion_timeout(...)
> 	if (!timeout) return -ETIMEDOUT;
> 
> with all kinds of permutations. Use 'time_left' as a variable to make
> the code
> self explaining.
> 
> Fix to the proper variable type 'unsigned long' while here.
> 
> Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>

Acked-by: Paul Cercueil <paul@crapouillou.net>

Cheers,
-Paul

> ---
>  drivers/i2c/busses/i2c-jz4780.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/drivers/i2c/busses/i2c-jz4780.c
> b/drivers/i2c/busses/i2c-jz4780.c
> index 55035cca0ae5..7951891d6b97 100644
> --- a/drivers/i2c/busses/i2c-jz4780.c
> +++ b/drivers/i2c/busses/i2c-jz4780.c
> @@ -565,7 +565,7 @@ static inline int jz4780_i2c_xfer_read(struct
> jz4780_i2c *i2c,
>  				       int idx)
>  {
>  	int ret = 0;
> -	long timeout;
> +	unsigned long time_left;
>  	int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
>  	unsigned short tmp;
>  	unsigned long flags;
> @@ -600,10 +600,10 @@ static inline int jz4780_i2c_xfer_read(struct
> jz4780_i2c *i2c,
>  
>  	spin_unlock_irqrestore(&i2c->lock, flags);
>  
> -	timeout = wait_for_completion_timeout(&i2c->trans_waitq,
> -					     
> msecs_to_jiffies(wait_time));
> +	time_left = wait_for_completion_timeout(&i2c->trans_waitq,
> +						msecs_to_jiffies(wai
> t_time));
>  
> -	if (!timeout) {
> +	if (!time_left) {
>  		dev_err(&i2c->adap.dev, "irq read timeout\n");
>  		dev_dbg(&i2c->adap.dev, "send cmd count:%d  %d\n",
>  			i2c->cmd, i2c->cmd_buf[i2c->cmd]);
> @@ -627,7 +627,7 @@ static inline int jz4780_i2c_xfer_write(struct
> jz4780_i2c *i2c,
>  {
>  	int ret = 0;
>  	int wait_time = JZ4780_I2C_TIMEOUT * (len + 5);
> -	long timeout;
> +	unsigned long time_left;
>  	unsigned short tmp;
>  	unsigned long flags;
>  
> @@ -655,14 +655,14 @@ static inline int jz4780_i2c_xfer_write(struct
> jz4780_i2c *i2c,
>  
>  	spin_unlock_irqrestore(&i2c->lock, flags);
>  
> -	timeout = wait_for_completion_timeout(&i2c->trans_waitq,
> -					     
> msecs_to_jiffies(wait_time));
> -	if (timeout && !i2c->stop_hold) {
> +	time_left = wait_for_completion_timeout(&i2c->trans_waitq,
> +						msecs_to_jiffies(wai
> t_time));
> +	if (time_left && !i2c->stop_hold) {
>  		unsigned short i2c_sta;
>  		int write_in_process;
>  
> -		timeout = JZ4780_I2C_TIMEOUT * 100;
> -		for (; timeout > 0; timeout--) {
> +		time_left = JZ4780_I2C_TIMEOUT * 100;
> +		for (; time_left > 0; time_left--) {
>  			i2c_sta = jz4780_i2c_readw(i2c,
> JZ4780_I2C_STA);
>  
>  			write_in_process = (i2c_sta &
> JZ4780_I2C_STA_MSTACT) ||
> @@ -673,7 +673,7 @@ static inline int jz4780_i2c_xfer_write(struct
> jz4780_i2c *i2c,
>  		}
>  	}
>  
> -	if (!timeout) {
> +	if (!time_left) {
>  		dev_err(&i2c->adap.dev, "write wait timeout\n");
>  		ret = -EIO;
>  	}


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

* Re: [PATCH 00/15] i2c: use 'time_left' with wait_for_*
  2024-04-27 20:35 [PATCH 00/15] i2c: use 'time_left' with wait_for_* Wolfram Sang
  2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
  2024-04-30  0:07 ` [PATCH 00/15] i2c: use 'time_left' with wait_for_* Andi Shyti
@ 2024-05-02 11:29 ` Andi Shyti
  2 siblings, 0 replies; 6+ messages in thread
From: Andi Shyti @ 2024-05-02 11:29 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: linux-i2c, imx, linux-arm-kernel, linux-arm-msm, linux-kernel,
	linux-mips, linux-omap, linux-rockchip, linux-samsung-soc,
	linux-stm32

Hi Wolfram,

On Sat, Apr 27, 2024 at 10:35:52PM +0200, Wolfram Sang wrote:
> There is a confusing pattern in the kernel to use a variable named 'timeout' to

there was a little checkpatch warning here for the line being
over 75 characters, but I went ahead anyway and pushed the whole
series to i2c/i2c-host.

Thanks,
Andi

> store the result of wait_for_*() causing patterns like:
> 
>         timeout = wait_for_completion_timeout(...)
>         if (!timeout) return -ETIMEDOUT;
> 
> with all kinds of permutations. Use 'time_left' as a variable to make the code
> self explaining.
> 
> This is the I2C part of a tree-wide series. The rest of the patches can
> be found here (slightly WIP):
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/wsa/linux.git i2c/time_left
> 
> Because these patches are generated, they need manual audit. So, I will
> send them step by step. This is part 1 and also a call for opinions if
> this is a desirable change. But at least in the I2C realm, I really want
> to have it proper.
> 
> Build bot is happy with these patches and I also compile tested them
> (except two). No functional changes intended.
> 
> Wolfram Sang (15):
>   i2c: amd-mp2-plat: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: digicolor: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: exynos5: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: hix5hd2: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: imx-lpi2c: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: omap: use 'time_left' variable with wait_for_completion_timeout()
>   i2c: st: use 'time_left' variable with wait_for_completion_timeout()
>   i2c: stm32f4: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: stm32f7: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: synquacer: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: jz4780: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: qcom-geni: use 'time_left' variable with
>     wait_for_completion_timeout()
>   i2c: rk3x: use 'time_left' variable with wait_event_timeout()
>   i2c: s3c2410: use 'time_left' variable with wait_event_timeout()
>   i2c: pxa: use 'time_left' variable with wait_event_timeout()
> 
> -- 
> 2.43.0
> 

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

end of thread, other threads:[~2024-05-02 11:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-27 20:35 [PATCH 00/15] i2c: use 'time_left' with wait_for_* Wolfram Sang
2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-04-30 12:43   ` Philippe Mathieu-Daudé
2024-04-30 12:49   ` Paul Cercueil
2024-04-30  0:07 ` [PATCH 00/15] i2c: use 'time_left' with wait_for_* Andi Shyti
2024-05-02 11:29 ` Andi Shyti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).