diff mbox

mtd: fix the wrong timeo for panic_nand_wait()

Message ID 1358824265-3425-1-git-send-email-shijie8@gmail.com
State New, archived
Headers show

Commit Message

Huang Shijie Jan. 22, 2013, 3:11 a.m. UTC
In nand_wait(), the timeo for panic_nand_wait() is assigned with
wrong value(jiffies + some delay).

This patch fixes it, and also uses the msecs_to_jiffies() to make the
code more readable.

Signed-off-by: Huang Shijie <shijie8@gmail.com>
---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)

Comments

Matthieu CASTET Jan. 21, 2013, 2:27 p.m. UTC | #1
Could you explain why the old code was wrong ?

With HZ=100

timeo = jiffies + 2 and it should be working.


Huang Shijie a écrit :
> In nand_wait(), the timeo for panic_nand_wait() is assigned with
> wrong value(jiffies + some delay).
> 
> This patch fixes it, and also uses the msecs_to_jiffies() to make the
> code more readable.
> 
> Signed-off-by: Huang Shijie <shijie8@gmail.com>
> ---
>  drivers/mtd/nand/nand_base.c |    8 ++------
>  1 files changed, 2 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
> index 8323ac9..acdd508 100644
> --- a/drivers/mtd/nand/nand_base.c
> +++ b/drivers/mtd/nand/nand_base.c
> @@ -825,14 +825,9 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,
>  static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
>  {
>  
> -	unsigned long timeo = jiffies;
> +	unsigned long timeo = (state == FL_ERASING) ? 400 : 20;
>  	int status, state = chip->state;
>  
> -	if (state == FL_ERASING)
> -		timeo += (HZ * 400) / 1000;
> -	else
> -		timeo += (HZ * 20) / 1000;
> -
>  	led_trigger_event(nand_led_trigger, LED_FULL);
>  
>  	/*
> @@ -849,6 +844,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
>  	if (in_interrupt() || oops_in_progress)
>  		panic_nand_wait(mtd, chip, timeo);
>  	else {
> +		timeo = jiffies + msecs_to_jiffies(timeo);
>  		while (time_before(jiffies, timeo)) {
>  			if (chip->dev_ready) {
>  				if (chip->dev_ready(mtd))
Huang Shijie Jan. 21, 2013, 2:54 p.m. UTC | #2
On Mon, Jan 21, 2013 at 10:27 PM, Matthieu CASTET
<matthieu.castet@parrot.com> wrote:
> Could you explain why the old code was wrong ?


sorry. this patch has a compiler error.


>
> With HZ=100
>
> timeo = jiffies + 2 and it should be working.
>

In logic, timeo should only be 2, just like it does in panic_nand_write().



thanks
Huang Shijie

>
> Huang Shijie a écrit :
>> In nand_wait(), the timeo for panic_nand_wait() is assigned with
>> wrong value(jiffies + some delay).
>>
>> This patch fixes it, and also uses the msecs_to_jiffies() to make the
>> code more readable.
>>
>> Signed-off-by: Huang Shijie <shijie8@gmail.com>
>> ---
>>  drivers/mtd/nand/nand_base.c |    8 ++------
>>  1 files changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
>> index 8323ac9..acdd508 100644
>> --- a/drivers/mtd/nand/nand_base.c
>> +++ b/drivers/mtd/nand/nand_base.c
>> @@ -825,14 +825,9 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,
>>  static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
>>  {
>>
>> -     unsigned long timeo = jiffies;
>> +     unsigned long timeo = (state == FL_ERASING) ? 400 : 20;
>>       int status, state = chip->state;
>>
>> -     if (state == FL_ERASING)
>> -             timeo += (HZ * 400) / 1000;
>> -     else
>> -             timeo += (HZ * 20) / 1000;
>> -
>>       led_trigger_event(nand_led_trigger, LED_FULL);
>>
>>       /*
>> @@ -849,6 +844,7 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
>>       if (in_interrupt() || oops_in_progress)
>>               panic_nand_wait(mtd, chip, timeo);
>>       else {
>> +             timeo = jiffies + msecs_to_jiffies(timeo);
>>               while (time_before(jiffies, timeo)) {
>>                       if (chip->dev_ready) {
>>                               if (chip->dev_ready(mtd))
diff mbox

Patch

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 8323ac9..acdd508 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -825,14 +825,9 @@  static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,
 static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 {
 
-	unsigned long timeo = jiffies;
+	unsigned long timeo = (state == FL_ERASING) ? 400 : 20;
 	int status, state = chip->state;
 
-	if (state == FL_ERASING)
-		timeo += (HZ * 400) / 1000;
-	else
-		timeo += (HZ * 20) / 1000;
-
 	led_trigger_event(nand_led_trigger, LED_FULL);
 
 	/*
@@ -849,6 +844,7 @@  static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
 	if (in_interrupt() || oops_in_progress)
 		panic_nand_wait(mtd, chip, timeo);
 	else {
+		timeo = jiffies + msecs_to_jiffies(timeo);
 		while (time_before(jiffies, timeo)) {
 			if (chip->dev_ready) {
 				if (chip->dev_ready(mtd))