Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1373936
| From | Boris Brezillon <boris.brezillon@free-electrons.com> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() |
| Date | 2016-04-08 04:20 +0200 |
| Message-ID | <rlubD-5av-3@gated-at.bofh.it> (permalink) |
| References | <rllrJ-6RI-29@gated-at.bofh.it> <rlsjx-3zZ-17@gated-at.bofh.it> <rltSh-4D1-1@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
On Fri, 8 Apr 2016 09:51:04 +0800 Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> wrote: > > > 在 2016年04月08日 08:18, Boris Brezillon 写道: > > Hi Zeng, > > > > On Fri, 8 Apr 2016 00:48:17 +0800 > > zengzhaoxiu@163.com wrote: > > > >> 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. > > Missing Signed-off-by here. > > > >> --- > >> 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) > > Or just > > > > if (hweight_long((unsigned long)diff0) == 1) > > > > which is doing exactly what the comment says. > > > > BTW, I don't understand why the current code is wrong? To me, it seems > > it's correctly detecting the case where only a single bit is different. > > What are you trying to fix exactly? > > > > Best Regards, > > > > Boris > > > > For example, assuming diff0 is 1, then fls(diff0) is equal to 1, then "~(1 << fls(diff0))" is equal to 0xfffffffd, > then the result of "(diff0 & ~(1 << fls(diff0)))" is 1 , not we expected 0. > > __fls(diff0) and "(fls(diff0) - 1)" are all right, but fls(diff0) is wrong. > Indeed, I forgot that fls() was returning (position + 1). Anyway, I still think using hweight clarifies what you really want to test. -- Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() zengzhaoxiu@163.com - 2016-04-07 19:00 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-08 02:20 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-08 04:00 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-08 04:20 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com> - 2016-04-08 07:40 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-11 09:50 +0200
[PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() zengzhaoxiu@163.com - 2016-04-12 09:40 +0200
Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data() Boris Brezillon <boris.brezillon@free-electrons.com> - 2016-04-12 13:40 +0200
csiph-web