Re: [PATCH] mtd: nand: s3c2410: fix bug in s3c2410_nand_correct_data()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Zeng,

On Fri,  8 Apr 2016 00:48:17 +0800
zengzhaoxiu@xxxxxxx wrote:

> From: Zeng Zhaoxiu <zhaoxiu.zeng@xxxxxxxxx>
> 
> 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

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-samsung-soc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux SoC Development]     [Linux Rockchip Development]     [Linux USB Development]     [Video for Linux]     [Linux Audio Users]     [Linux SCSI]     [Yosemite News]

  Powered by Linux