Re: [PATCH] mtd: partitions: redboot: Added conversion of operands to a larger type

From: Andy Shevchenko
Date: Mon Mar 25 2024 - 10:10:20 EST


On Fri, Mar 15, 2024 at 12:37:58PM +0300, Denis Arefev wrote:
> The value of an arithmetic expression directory * master->erasesize is
> subject to overflow due to a failure to cast operands to a larger data
> type before perfroming arithmetic

..

> - offset = directory * master->erasesize;
> + offset = (unsigned long) directory * master->erasesize;

Usage of explicit casting can be avoided by using size_mul() from overflow.h.
Usually explicit castings are prone to subtle errors.

--
With Best Regards,
Andy Shevchenko