Skip to contentSkip to conversation

smatch stuff: mtd/cafe_nand: cafe_device_ready() always returns true

PATCH In review Dan Carpenter 4 participants 6 messages Jan 3, 2011 – Aug 17, 2012

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

Hi David,

cafe_device_ready() always returns 1. It looks like something else was intended but I don't know the code enough to say what should go there.

drivers/mtd/nand/cafe_nand.c +107 cafe_device_ready(3)
warn: condition is always true

104 static int cafe_device_ready(struct mtd_info *mtd)
105 {
106 struct cafe_priv *cafe = mtd->priv;
107 int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
^^^^^^^^^^^^^
This bit is always non-zero because we take the result of cafe_readl() and do a bitwize or with 0x40000000. Then the double negate means that result is always 1.

   108          uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
   109

regards,
dan carpenter

#1 lore raw
Quoted 5 lines · Dan Carpenter

Hi David,

cafe_device_ready() always returns 1. It looks like something else was intended but I don't know the code enough to say what should go there.

Probably we should just change the | to an &. I'll send a patch for that.

regards,
dan carpenter

Quoted 19 lines

drivers/mtd/nand/cafe_nand.c +107 cafe_device_ready(3)
warn: condition is always true

   104  static int cafe_device_ready(struct mtd_info *mtd)
   105  {
   106          struct cafe_priv *cafe = mtd->priv;
   107          int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
                                                             ^^^^^^^^^^^^^
	This bit is always non-zero because we take the result of
	cafe_readl() and do a bitwize or with 0x40000000.  Then the
	double negate means that result is always 1.

   108          uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
   109

regards,
dan carpenter

#2 lore raw

PATCH 1/1 mtd: cafe_nand: fix an & vs | mistake

In reply to Dan Carpenter

The intent here was clearly to set result to true if the 0x40000000 flag was set. But instead there was a | vs & typo and we always set result to true.

---
I do not have the hardware to test this. The original code is clearly buggy, but what about if 0x40000000 is the wrong flag?

drivers/mtd/nand/cafe_nand.c +1 -1
index f3594a6..ac0d967 100644
@@ -102,7 +102,7 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
 static int cafe_device_ready(struct mtd_info *mtd)
 {
 	struct cafe_priv *cafe = mtd->priv;
-	int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
+	int result = !!(cafe_readl(cafe, NAND_STATUS) & 0x40000000);
 	uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
 
 	cafe_writel(cafe, irqs, NAND_IRQ);
#3 lore raw

Re: [patch] mtd: cafe_nand: fix an & vs | mistake

Quoted 8 lines · Dan Carpenter

The intent here was clearly to set result to true if the 0x40000000 flag was set. But instead there was a | vs & typo and we always set result to true.

---
I do not have the hardware to test this. The original code is clearly buggy, but what about if 0x40000000 is the wrong flag?

Looks like it is the right flag, I've checked

wiki.laptop.org/images/5/5c/88ALP01_Datasheet_July_2007.pdf

and your patch looks correct.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#4 lore raw

Re: [patch] mtd: cafe_nand: fix an & vs | mistake

In reply to Dan Carpenter

Pushed this patch to l2-mtd.git and added CC to -stable. The patch seems to be a real bug-fix. Daniel, could you please check it - it will be shame if it hits -stable and breaks something.

Thanks!

Quoted 26 lines · Dan Carpenter

The intent here was clearly to set result to true if the 0x40000000 flag was set. But instead there was a | vs & typo and we always set result to true.

---
I do not have the hardware to test this. The original code is clearly buggy, but what about if 0x40000000 is the wrong flag?

drivers/mtd/nand/cafe_nand.c +1 -1
index f3594a6..ac0d967 100644
@@ -102,7 +102,7 @@ static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
 static int cafe_device_ready(struct mtd_info *mtd)
 {
 	struct cafe_priv *cafe = mtd->priv;
-	int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
+	int result = !!(cafe_readl(cafe, NAND_STATUS) & 0x40000000);
 	uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
 
 	cafe_writel(cafe, irqs, NAND_IRQ);

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#5 lore raw

Re: [patch] mtd: cafe_nand: fix an & vs | mistake

Quoted 3 lines · Artem Bityutskiy

Pushed this patch to l2-mtd.git and added CC to -stable. The patch seems to be a real bug-fix. Daniel, could you please check it - it will be shame if it hits -stable and breaks something.

Thanks for catching this, sorry for the delay in looking closely at it. I double-checked the device specifications and indeed, Dan's interpretation is correct.

I also tested the patch. System still remains functional and basic nand performance seems to be the same.

Thanks!
Daniel