mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [BUG] mtd: cfi-flash: comparison of unsigned expression in '>= 0' is always true
@ 2021-05-17 11:29 Ahmad Fatoum
  2021-05-18  6:26 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-05-17 11:29 UTC (permalink / raw)
  To: barebox

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?

Cheers,
Ahmad

-- 
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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] mtd: cfi-flash: comparison of unsigned expression in '>= 0' is always true
  2021-05-17 11:29 [BUG] mtd: cfi-flash: comparison of unsigned expression in '>= 0' is always true Ahmad Fatoum
@ 2021-05-18  6:26 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2021-05-18  6:26 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

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 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-05-18  6:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17 11:29 [BUG] mtd: cfi-flash: comparison of unsigned expression in '>= 0' is always true Ahmad Fatoum
2021-05-18  6:26 ` Sascha Hauer

mail archive of the barebox mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://lore.barebox.org/barebox/0 barebox/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 barebox barebox/ https://lore.barebox.org/barebox \
		barebox@lists.infradead.org barebox@lists.infradead.org
	public-inbox-index barebox

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git