2014-06-18 15:44 GMT+02:00 Richard Genoud <[email protected]>:
> The rounding to next page formula was wrong:
> ex: (len | ~(meminfo->writesize - 1)) + 1;
> len=128K
> writesize=4K
> (len | ~(meminfo->writesize - 1)) + 1 => 4 294 963 201 ?!
>
> correct rounding formula:
> ((len - 1) | (meminfo->writesize - 1)) + 1 => 128K
> len = 130K
> ((len - 1) | (meminfo->writesize - 1)) + 1 => 132K
>
> Signed-off-by: Richard Genoud <[email protected]>

Forgot to give an example how to trigger the bug:

modprobe nandsim parts="20,20" badblocks="22,23"

busybox-1.22.1 nanddump  /dev/mtd1 | wc -c
[...] infinite loop
busybox-1.22.1 nanddump -b /dev/mtd1 | wc -c
294912

with the patch:
busybox nanddump /dev/mtd1 | wc -c
327680
busybox nanddump -b /dev/mtd1 | wc -c
294912

upstream (1.5.0) nanddump:
nanddump /dev/mtd1 --bb=skipbad  | wc -c
ECC failed: 0
ECC corrected: 0
Number of bad blocks: 2
Number of bbt blocks: 0
Block size 16384, page size 512, OOB size 16
Dumping data starting at 0x00000000 and ending at 0x00050000...
294912


> ---
>  miscutils/nandwrite.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
> index e3f9b565dae4..8c4da802f6b3 100644
> --- a/miscutils/nandwrite.c
> +++ b/miscutils/nandwrite.c
> @@ -64,8 +64,8 @@ static void dump_bad(struct mtd_info_user *meminfo, 
> unsigned len, int oob)
>         unsigned char buf[meminfo->writesize];
>         unsigned count;
>
> -       /* round len to the next page */
> -       len = (len | ~(meminfo->writesize - 1)) + 1;
> +       /* round len to the next page only if len is not already on a page */
> +       len = ((len - 1) | (meminfo->writesize - 1)) + 1;
>
>         memset(buf, 0xff, sizeof(buf));
>         for (count = 0; count < len; count += meminfo->writesize) {
> --
> 1.8.5.5
>



-- 
for me, ck means con kolivas and not calvin klein... does it mean I'm a geek ?
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to