]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: fix signed vs unsigned compare in read check in _spl_load()
authorFranco Venturi <fventuri@comcast.net>
Wed, 31 Jul 2024 13:09:00 +0000 (09:09 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 28 Aug 2024 00:04:05 +0000 (18:04 -0600)
Fix signed vs unsigned compare in read check in _spl_load()

Issue: when info->read() returns a negative value because of an error,
       the comparison of 'read' (signed) with 'sizeof(*header)'
       (unsigned silently converts the negative value into a very
       large unsigned value and the check on the error condition
       always return false, i.e. the error is not detected
Symptoms: if spl_load_image_fat() is unable to find the file 'uImage',
          the SPL phase of the boot process just hangs after displaying
          the following line:
          Trying to boot from MMC1
Fix: cast 'sizeof(*header)' to int so the compare is now between
     signed types
Reference: https://stackoverflow.com/questions/17293749/sizeof-operator-in-if-statement

Signed-off-by: Franco Venturi <fventuri@comcast.net>
Reviewed-by: Sean Anderson <seanga2@gmail.com>
Reviewed-by: Peng Fan <peng.fan@nxp.com>
include/spl_load.h

index 1c2b296c0a2c54940bdaf932b183079f87babf63..83db3812029831d516e4e26292347cc1a1e7179c 100644 (file)
@@ -22,7 +22,7 @@ static inline int _spl_load(struct spl_image_info *spl_image,
 
        read = info->read(info, offset, ALIGN(sizeof(*header),
                                              spl_get_bl_len(info)), header);
-       if (read < sizeof(*header))
+       if (read < (int)sizeof(*header))
                return -EIO;
 
        if (image_get_magic(header) == FDT_MAGIC) {