[BUG] mtd: cfi-flash: comparison of unsigned expression in '>= 0' is always true

Sascha Hauer sha at pengutronix.de
Mon May 17 23:26:45 PDT 2021


Hi Ahmad,

On Mon, May 17, 2021 at 01:29:05PM +0200, Ahmad Fatoum wrote:
> Hi,
> 
> The new warning correctly flags following piece of code in
> drivers/mtd/nor/cfi_flash.c:
> 
> /* loop through the sectors from the highest address
>  * when the passed address is greater or equal to the sector address
>  * we have a match
>  */
> flash_sect_t find_sector(struct flash_info *info, unsigned long addr)
> {
>         flash_sect_t sector;
> 
>         for (sector = info->sector_count - 1; sector >= 0; sector--) {
>                 if (addr >= info->start[sector])
>                         break;
>         }
> 
>         return sector;
> }
> 
> If addr is indeed unmapped by info->start[*], this would be an infinite
> loop. I don't know what the correct fix would be though. Any suggestions?

See
https://lore.barebox.org/20210517185424.32145-7-s.hauer@pengutronix.de

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list