public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
To: Brian Norris <computersforpeace@gmail.com>,
	linux-mtd@lists.infradead.org
Cc: Marek Vasut <marex@denx.de>, Huang Shijie <shijie8@gmail.com>
Subject: Re: [PATCH] mtd: spi-nor: improve wait-till-ready timeout loop
Date: Sun, 23 Nov 2014 18:16:42 -0300	[thread overview]
Message-ID: <54724EBA.3040904@vanguardiasur.com.ar> (raw)
In-Reply-To: <1415183523-16265-1-git-send-email-computersforpeace@gmail.com>

On 11/05/2014 07:32 AM, Brian Norris wrote:
> There are a few small issues with the timeout loop in
> spi_nor_wait_till_ready():
> 
>  * The first operation should not be a reschedule; we should check the
>    status register at least once to see if we're complete!
> 
>  * We should check the status register one last time after declaring the
>    deadline has passed, to prevent a premature timeout erro (this is
>    theoretically possible if we sleep for a long time after the previous
>    status register check).
> 
>  * Add an error message, so it's obvious if we ever hit a timeout.
> 
> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
> ---
>  drivers/mtd/spi-nor/spi-nor.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
> index 5e3a1d363895..d0dcaa1372ec 100644
> --- a/drivers/mtd/spi-nor/spi-nor.c
> +++ b/drivers/mtd/spi-nor/spi-nor.c
> @@ -202,19 +202,24 @@ static int spi_nor_ready(struct spi_nor *nor)
>  static int spi_nor_wait_till_ready(struct spi_nor *nor)
>  {
>  	unsigned long deadline;
> -	int ret;
> +	int timeout = 0, ret;
>  
>  	deadline = jiffies + MAX_READY_WAIT_JIFFIES;
>  
> -	do {
> -		cond_resched();
> +	while (!timeout) {
> +		if (time_after_eq(jiffies, deadline))
> +			timeout = 1;
>  
>  		ret = spi_nor_ready(nor);
>  		if (ret < 0)
>  			return ret;
>  		if (ret)
>  			return 0;
> -	} while (!time_after_eq(jiffies, deadline));
> +
> +		cond_resched();
> +	}
> +
> +	dev_err(nor->dev, "flash operation timed out\n");
>  
>  	return -ETIMEDOUT;
>  }
> 

Looks good to me.

Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
-- 
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

  parent reply	other threads:[~2014-11-23 21:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-05 10:32 [PATCH] mtd: spi-nor: improve wait-till-ready timeout loop Brian Norris
2014-11-06  3:44 ` Huang Shijie
2014-11-23 21:16 ` Ezequiel Garcia [this message]
2014-11-23 21:23   ` Ezequiel Garcia
2014-11-26  6:54 ` Brian Norris

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=54724EBA.3040904@vanguardiasur.com.ar \
    --to=ezequiel@vanguardiasur.com.ar \
    --cc=computersforpeace@gmail.com \
    --cc=linux-mtd@lists.infradead.org \
    --cc=marex@denx.de \
    --cc=shijie8@gmail.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