mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Cercueil <paul@crapouillou.net>
To: Wolfram Sang <wsa+renesas@sang-engineering.com>,
	 linux-i2c@vger.kernel.org
Cc: Andi Shyti <andi.shyti@kernel.org>,
	linux-mips@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 11/15] i2c: jz4780: use 'time_left' variable with wait_for_completion_timeout()
Date: Tue, 30 Apr 2024 14:49:50 +0200	[thread overview]
Message-ID: <1a72ad2d6f72805de2c99db8ba8ea984711da81b.camel@crapouillou.net> (raw)
In-Reply-To: <20240427203611.3750-12-wsa+renesas@sang-engineering.com>

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;
>  	}


  parent reply	other threads:[~2024-04-30 12:55 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-27 20:35 [PATCH 00/15] i2c: use 'time_left' with wait_for_* Wolfram Sang
2024-04-27 20:35 ` [PATCH 01/15] i2c: amd-mp2-plat: use 'time_left' variable with wait_for_completion_timeout() Wolfram Sang
2024-04-27 20:35 ` [PATCH 02/15] i2c: digicolor: " Wolfram Sang
2024-04-28  4:38   ` Baruch Siach
2024-04-27 20:35 ` [PATCH 03/15] i2c: exynos5: " Wolfram Sang
2024-04-27 20:35 ` [PATCH 04/15] i2c: hix5hd2: " Wolfram Sang
2024-04-27 20:35 ` [PATCH 05/15] i2c: imx-lpi2c: " Wolfram Sang
2024-04-28  1:45   ` Peng Fan
2024-04-27 20:35 ` [PATCH 06/15] i2c: omap: " Wolfram Sang
2024-04-27 20:35 ` [PATCH 07/15] i2c: st: " Wolfram Sang
2024-04-28 12:15   ` Uwe Kleine-König
2024-04-27 20:36 ` [PATCH 08/15] i2c: stm32f4: " Wolfram Sang
2024-04-27 20:36 ` [PATCH 09/15] i2c: stm32f7: " Wolfram Sang
2024-04-27 20:36 ` [PATCH 10/15] i2c: synquacer: " Wolfram Sang
2024-04-29  6:56   ` Ard Biesheuvel
2024-04-27 20:36 ` [PATCH 11/15] i2c: jz4780: " Wolfram Sang
2024-04-30 12:43   ` Philippe Mathieu-Daudé
2024-04-30 12:49   ` Paul Cercueil [this message]
2024-04-27 20:36 ` [PATCH 12/15] i2c: qcom-geni: " Wolfram Sang
2024-04-29 10:52   ` Bryan O'Donoghue
2024-04-30  2:10   ` Bjorn Andersson
2024-04-27 20:36 ` [PATCH 13/15] i2c: rk3x: use 'time_left' variable with wait_event_timeout() Wolfram Sang
2024-04-27 20:36 ` [PATCH 14/15] i2c: s3c2410: " Wolfram Sang
2024-04-27 20:36 ` [PATCH 15/15] i2c: pxa: " 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1a72ad2d6f72805de2c99db8ba8ea984711da81b.camel@crapouillou.net \
    --to=paul@crapouillou.net \
    --cc=andi.shyti@kernel.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=wsa+renesas@sang-engineering.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®