Skip to contentSkip to conversation

drivers/mtd/devices/doc2000.c - address of 'eccbuf' will always evaluate as 'true' , warnings

PATCH Gabriel C 2 participants 5 messages Jul 22, 2007 Memory technology devices (MTD)

lore
Share & tools
lore

Gabriel C

author
#0 lore raw

Hi,

I noticed this warnings on current git with gcc 4.2.1

....

drivers/mtd/devices/doc2000.c: In function 'doc_read':
drivers/mtd/devices/doc2000.c:635: warning: the address of 'eccbuf' will always evaluate as 'true' drivers/mtd/devices/doc2000.c: In function 'doc_write':
drivers/mtd/devices/doc2000.c:899: warning: the address of 'eccbuf' will always evaluate as 'true'

....

This patch fixes it but maybe there is a better way to do it.

---

drivers/mtd/devices/doc2000.c +2 -2
index c73e96b..ce8fbf5 100644
@@ -632,7 +632,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
 			len = ((from | 0x1ff) + 1) - from;
 
 		/* The ECC will not be calculated correctly if less than 512 is read */
-		if (len != 0x200 && eccbuf)
+		if (len != 0x200 && eccbuf != NULL)
 			printk(KERN_WARNING
 			       "ECC needs a full sector read (adr: %lx size %lx)\n",
 			       (long) from, (long) len);
@@ -896,7 +896,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
+		if (eccbuf != NULL) {
 			unsigned char x[8];
 			size_t dummy;
 			int ret;
#1 lore raw
Quoted 33 lines · Gabriel C

I noticed this warnings on current git with gcc 4.2.1

....

drivers/mtd/devices/doc2000.c: In function 'doc_read':
drivers/mtd/devices/doc2000.c:635: warning: the address of 'eccbuf' will always evaluate as 'true' drivers/mtd/devices/doc2000.c: In function 'doc_write':
drivers/mtd/devices/doc2000.c:899: warning: the address of 'eccbuf' will always evaluate as 'true'

....

This patch fixes it but maybe there is a better way to do it.

---

drivers/mtd/devices/doc2000.c +1 -1
index c73e96b..ce8fbf5 100644
@@ -632,7 +632,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
 			len = ((from | 0x1ff) + 1) - from;
 
 		/* The ECC will not be calculated correctly if less than 512 is read */
-		if (len != 0x200 && eccbuf)
+		if (len != 0x200 && eccbuf != NULL)
 			printk(KERN_WARNING
 			       "ECC needs a full sector read (adr: %lx size %lx)\n",
 			       (long) from, (long) len);

drivers/mtd/devices/doc2000.c static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, · line 902

Quoted 8 lines
drivers/mtd/devices/doc2000.c +1 -1
@@ -896,7 +896,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
+		if (eccbuf != NULL) {
 			unsigned char x[8];
 			size_t dummy;
 			int ret;

The patches doesn't fix anything. If you take a look at git history for the file, you may find this:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7f8a894066b826a4baea49c2a3adbba0a56a192f

And if I read the patch correctly, Thomas merely forgot to remove these two checks on eccbuf. So the correct patch would remove '&& eccbuf' from one conditional and nuke the other completely.

Care to send such a patch?

Jörn

Signature · 4 lines
ticks = jiffies;
while (ticks == jiffies);
ticks = jiffies;
-- /usr/src/linux/init/main.c
author
#2 lore raw
Quoted 46 lines · Jörn Engel
Quoted 32 lines · Gabriel C

I noticed this warnings on current git with gcc 4.2.1

....

drivers/mtd/devices/doc2000.c: In function 'doc_read':
drivers/mtd/devices/doc2000.c:635: warning: the address of 'eccbuf' will always evaluate as 'true' drivers/mtd/devices/doc2000.c: In function 'doc_write':
drivers/mtd/devices/doc2000.c:899: warning: the address of 'eccbuf' will always evaluate as 'true'

....

This patch fixes it but maybe there is a better way to do it.

---

drivers/mtd/devices/doc2000.c +1 -1
index c73e96b..ce8fbf5 100644
@@ -632,7 +632,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
 			len = ((from | 0x1ff) + 1) - from;
 
 		/* The ECC will not be calculated correctly if less than 512 is read */
-		if (len != 0x200 && eccbuf)
+		if (len != 0x200 && eccbuf != NULL)
 			printk(KERN_WARNING
 			       "ECC needs a full sector read (adr: %lx size %lx)\n",
 			       (long) from, (long) len);

drivers/mtd/devices/doc2000.c static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, · line 902

Quoted 8 lines
drivers/mtd/devices/doc2000.c +1 -1
@@ -896,7 +896,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
+		if (eccbuf != NULL) {
 			unsigned char x[8];
 			size_t dummy;
 			int ret;

The patches doesn't fix anything. If you take a look at git history for the file, you may find this:
http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=7f8a894066b826a4baea49c2a3adbba0a56a192f

Quoted 5 lines

And if I read the patch correctly, Thomas merely forgot to remove these two checks on eccbuf. So the correct patch would remove '&& eccbuf' from one conditional and nuke the other completely.

Care to send such a patch?

Yes. I noticed doc2001plus.c has an leftover too.

...

drivers/mtd/devices/doc2001plus.c:751: warning: the address of 'eccbuf' will always evaluate as 'true'

...

Quoted 3 lines

Jörn

Gabriel

drivers/mtd/devices/doc2000.c +1 -20
index c73e96b..d0e6ee8 100644
@@ -632,7 +632,7 @@ static int doc_read(struct mtd_info *mtd, loff_t from, size_t len,
 			len = ((from | 0x1ff) + 1) - from;
 
 		/* The ECC will not be calculated correctly if less than 512 is read */
-		if (len != 0x200 && eccbuf)
+		if (len != 0x200)
 			printk(KERN_WARNING
 			       "ECC needs a full sector read (adr: %lx size %lx)\n",
 			       (long) from, (long) len);
@@ -896,25 +896,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
-			unsigned char x[8];
-			size_t dummy;
-			int ret;
-
-			/* Write the ECC data to flash */
-			for (di=0; di<6; di++)
-				x[di] = eccbuf[di];
-
-			x[6]=0x55;
-			x[7]=0x55;
-
-			ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
-			if (ret) {
-				mutex_unlock(&this->lock);
-				return ret;
-			}
-		}
-
 		to += len;
 		left -= len;
 		buf += len;
drivers/mtd/devices/doc2001plus.c +1 -1
index 2b30b58..83be346 100644
@@ -748,7 +748,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 	WriteDOC(DoC_GetDataOffset(mtd, &fto), docptr, Mplus_FlashCmd);
 
 	/* On interleaved devices the flags for 2nd half 512 are before data */
-	if (eccbuf && before)
+	if (before)
 		fto -= 2;
 
 	/* issue the Serial Data In command to initial the Page Program process */
#3 lore raw
Quoted 17 lines · Gabriel C
drivers/mtd/devices/doc2000.c +0 -12
@@ -896,25 +896,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
-			unsigned char x[8];
-			size_t dummy;
-			int ret;
-
-			/* Write the ECC data to flash */
-			for (di=0; di<6; di++)
-				x[di] = eccbuf[di];
-
-			x[6]=0x55;
-			x[7]=0x55;
-

drivers/mtd/devices/doc2000.c static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, · line 901

Quoted 10 lines
drivers/mtd/devices/doc2000.c +0 -7
-			ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
-			if (ret) {
-				mutex_unlock(&this->lock);
-				return ret;
-			}
-		}
-
 		to += len;
 		left -= len;
 		buf += len;

You should remove the condition, but not the conditional code.

Jörn

Signature · 3 lines
A quarrel is quickly settled when deserted by one party; there is
no battle unless there be two.
-- Seneca
author
#4 lore raw
Quoted 21 lines · Jörn Engel
Quoted 20 lines · Gabriel C
drivers/mtd/devices/doc2000.c +0 -16
@@ -896,25 +896,6 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
 		/* Let the caller know we completed it */
 		*retlen += len;
 
-		if (eccbuf) {
-			unsigned char x[8];
-			size_t dummy;
-			int ret;
-
-			/* Write the ECC data to flash */
-			for (di=0; di<6; di++)
-				x[di] = eccbuf[di];
-
-			x[6]=0x55;
-			x[7]=0x55;
-
-			ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x);
-			if (ret) {
-				mutex_unlock(&this->lock);
-				return ret;
Quoted 8 lines

drivers/mtd/devices/doc2000.c static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, · line 901

Quoted 6 lines
drivers/mtd/devices/doc2000.c +0 -3
-			}
-		}
-
 		to += len;
 		left -= len;
 		buf += len;

You should remove the condition, but not the conditional code.

Sorry , I was away from keyboard.

Then I can't understand what this code is doing :/

So let Thomas or someone know this code fix it.

Quoted 3 lines

Jörn

Regards,

Gabriel