All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	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:23:52 -0300	[thread overview]
Message-ID: <54725068.2010909@vanguardiasur.com.ar> (raw)
In-Reply-To: <54724EBA.3040904@vanguardiasur.com.ar>

On 11/23/2014 06:16 PM, Ezequiel Garcia wrote:
> 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>
> 

On a second look... I find more readable to use a bool type for
booleans, but it's just a silly nitpick.

-- 
Ezequiel Garcia, VanguardiaSur
www.vanguardiasur.com.ar

  reply	other threads:[~2014-11-23 21:25 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
2014-11-23 21:23   ` Ezequiel Garcia [this message]
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=54725068.2010909@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 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.