Skip to contentSkip to conversation

mtd: fix the wrong timeo for panic_nand_wait()

PATCH In review Huang Shijie 5 participants 8 messages Jan 21, 2013 – Feb 4, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: fix the wrong timeo for panic_nand_wait()

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.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +2 -6
index 8323ac9..acdd508 100644
@@ -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))
Signature · 1 line
1.7.4.4
#1 lore raw

Could you explain why the old code was wrong ?

With HZ=100

timeo = jiffies + 2 and it should be working.

Quoted 39 lines · Huang Shijie

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.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +2 -6
index 8323ac9..acdd508 100644
@@ -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))
#2 lore raw
Quoted 1 line · Matthieu CASTET

Could you explain why the old code was wrong ?

sorry. this patch has a compiler error.

Quoted 5 lines

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

Quoted 41 lines
Quoted 39 lines · Huang Shijie

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.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +2 -6
index 8323ac9..acdd508 100644
@@ -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))
#3 lore raw

PATCH v2 1/1 mtd: fix the wrong timeo for panic_nand_wait()

In nand_wait(), the timeo for panic_nand_wait() is assigned with wrong value(jiffies + some delay). The timeo should be set like the panic_nand_write() does.

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

---
fix the compiler error in version 1, and add some commits.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +2 -6
index 8323ac9..a8c1fb4 100644
@@ -825,13 +825,8 @@ 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;
 	int status, state = chip->state;
-
-	if (state == FL_ERASING)
-		timeo += (HZ * 400) / 1000;
-	else
-		timeo += (HZ * 20) / 1000;
+	unsigned long timeo = (state == FL_ERASING ? 400 : 20);
 
 	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))
Signature · 1 line
1.7.0.4
#4 lore raw

Hello Huang,

Quoted 6 lines · Huang Shijie

In nand_wait(), the timeo for panic_nand_wait() is assigned with wrong value(jiffies + some delay). The timeo should be set like the panic_nand_write() does.

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

You are not exactly explaining what is the issue with the current code, and how you are fixing it. If someone needs to backport this patch for whatever reason, it must be clear as to what it fixes.

Quoted 36 lines

---
fix the compiler error in version 1, and add some commits.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 8323ac9..a8c1fb4 100644
@@ -825,13 +825,8 @@ 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) {

drivers/mtd/nand/nand_base.c +2 -6
-	unsigned long timeo = jiffies;
 	int status, state = chip->state;
-
-	if (state == FL_ERASING)
-		timeo += (HZ * 400) / 1000;
-	else
-		timeo += (HZ * 20) / 1000;
+	unsigned long timeo = (state == FL_ERASING ? 400 : 20);
 
 	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))
Signature · 1 line
Florian
#5 lore raw
Quoted 7 lines · Florian Fainelli

Hello Huang,

Quoted 4 lines · Huang Shijie

In nand_wait(), the timeo for panic_nand_wait() is assigned with wrong value(jiffies + some delay). The timeo should be set like the panic_nand_write() does.

Quoted 5 lines
Quoted 2 lines

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

You are not exactly explaining what is the issue with the current code, and how you are fixing it. If someone needs to backport this patch for whatever reason, it must be clear as to what it fixes.

ok, i can add more comments.
thanks for your review.

Best Regards
Huang Shijie

Quoted 35 lines
Quoted 35 lines

---
fix the compiler error in version 1, and add some commits.

---
  drivers/mtd/nand/nand_base.c |    8 ++------
  1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +0 -0
index 8323ac9..a8c1fb4 100644
@@ -825,13 +825,8 @@ 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) {

drivers/mtd/nand/nand_base.c +2 -6
-	unsigned long timeo = jiffies;
  	int status, state = chip->state;
-
-	if (state == FL_ERASING)
-		timeo += (HZ * 400) / 1000;
-	else
-		timeo += (HZ * 20) / 1000;
+	unsigned long timeo = (state == FL_ERASING ? 400 : 20);
 
  	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))
#6 lore raw

PATCH v3 1/1 mtd: fix the wrong timeo for panic_nand_wait()

In reply to Florian Fainelli

The panic_nand_wait() expects the timeo in ms and not in jiffies. But in nand_wait(), the timeo for panic_nand_wait() is assigned with wrong value(jiffies + some delay). The timeo should be set like the panic_nand_write() does.

This patch passes timeo in ms to panic_nand_wait().
And this patch also passes timeo in jiffies(converted by msecs_to_jiffies) to time_before() which makes the code more readable.

---
v1 --> v2:
fixed a compiler error.

v2 --> v3:
add more comments.

---
 drivers/mtd/nand/nand_base.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/mtd/nand/nand_base.c +2 -6
index 8323ac9..a8c1fb4 100644
@@ -825,13 +825,8 @@ 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;
 	int status, state = chip->state;
-
-	if (state == FL_ERASING)
-		timeo += (HZ * 400) / 1000;
-	else
-		timeo += (HZ * 20) / 1000;
+	unsigned long timeo = (state == FL_ERASING ? 400 : 20);
 
 	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))
Signature · 1 line
1.7.0.4
#7 lore raw
Quoted 10 lines · Huang Shijie

The panic_nand_wait() expects the timeo in ms and not in jiffies. But in nand_wait(), the timeo for panic_nand_wait() is assigned with wrong value(jiffies + some delay). The timeo should be set like the panic_nand_write() does.

This patch passes timeo in ms to panic_nand_wait().
And this patch also passes timeo in jiffies(converted by msecs_to_jiffies) to time_before() which makes the code more readable.

Pushed to l2-mtd.git, thanks!

Signature · 2 lines
Best Regards,
Artem Bityutskiy