[PATCH 08/10] mtd-utils: nandwrite: prevent 32-bit overflow

Mike Frysinger vapier.adi at gmail.com
Tue Nov 9 04:48:53 EST 2010


On Wed, Nov 3, 2010 at 04:27, Brian Norris wrote:
> For large block- and page-sizes, the multiplication of ebsize_aligned
> and pagelen can overflow a 32-bit integer.  This overflow can be
> prevented by a simple change in order of operations (i.e., do division
> first).
>
> -       filebuf_max = pagelen * ebsize_aligned / mtd.min_io_size;
> +       filebuf_max = ebsize_aligned / mtd.min_io_size * pagelen;

i'd insert a comment noting that order of operations matters to avoid
32bit overflow so someone doesnt switch it back by accident in the
future
-mike



More information about the linux-mtd mailing list