From: Huang Shijie <shijie.huang@intel.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: Marek Vasut <marex@denx.de>, Huang Shijie <shijie8@gmail.com>,
linux-mtd@lists.infradead.org
Subject: Re: [PATCH] mtd: spi-nor: improve wait-till-ready timeout loop
Date: Thu, 6 Nov 2014 11:44:11 +0800 [thread overview]
Message-ID: <20141106034411.GA26529@shldeISGChi005.sh.intel.com> (raw)
In-Reply-To: <1415183523-16265-1-git-send-email-computersforpeace@gmail.com>
On Wed, Nov 05, 2014 at 02:32:03AM -0800, 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;
> }
look good.
Acked-by: Huang Shijie <shijie.huang@intel.com>
next prev parent reply other threads:[~2014-11-06 3:44 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 [this message]
2014-11-23 21:16 ` Ezequiel Garcia
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=20141106034411.GA26529@shldeISGChi005.sh.intel.com \
--to=shijie.huang@intel.com \
--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