linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data()
@ 2016-04-07 16:48 zengzhaoxiu at 163.com
  2016-04-08  0:18 ` Boris Brezillon
  0 siblings, 1 reply; 8+ messages in thread
From: zengzhaoxiu at 163.com @ 2016-04-07 16:48 UTC (permalink / raw)
  To: linux-arm-kernel

From: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>

If there is only one bit difference in the ECC, the function should return 1.
The result of "diff0 & ~(1<<fls(diff0))" is equal to diff0, so the function
actually returns -1.

Here, we can use the simple expression "(diff0 & (diff0 - 1)) == 0" to determine
whether the diff0 has only one 1-bit.
---
 drivers/mtd/nand/s3c2410.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 9c9397b..c9698cf 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -542,7 +542,7 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
 	diff0 |= (diff1 << 8);
 	diff0 |= (diff2 << 16);
 
-	if ((diff0 & ~(1<<fls(diff0))) == 0)
+	if ((diff0 & (diff0 - 1)) == 0)
 		return 1;
 
 	return -1;
-- 
2.5.5

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-04-12 11:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-07 16:48 [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() zengzhaoxiu at 163.com
2016-04-08  0:18 ` Boris Brezillon
2016-04-08  1:51   ` Zeng Zhaoxiu
2016-04-08  2:18     ` Boris Brezillon
2016-04-08  5:37       ` Zeng Zhaoxiu
2016-04-11  7:49         ` Boris Brezillon
2016-04-12  7:30           ` zengzhaoxiu at 163.com
2016-04-12 11:34             ` Boris Brezillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).