diff mbox series

[1/1] fit: check return value of fit_image_get_data_size()

Message ID 20200311205108.52443-1-xypron.glpk@gmx.de
State Accepted
Commit 183780491f9b45da6bec9627304b2c26169e8801
Headers show
Series [1/1] fit: check return value of fit_image_get_data_size() | expand

Commit Message

Heinrich Schuchardt March 11, 2020, 8:51 p.m. UTC
GCC-10 reports:

In file included from tools/common/image-fit.c:1:
include/image.h: In function ?fit_image_get_data_and_size?:
./tools/../common/image-fit.c:1015:9: warning: ?len? may be used
uninitialized in this function [-Wmaybe-uninitialized]
 1015 |   *size = len;
      |   ~~~~~~^~~~~
./tools/../common/image-fit.c:996:6: note: ?len? was declared here
  996 |  int len;
      |      ^~~

Add the missing check of the return value of fit_image_get_data_size().

Fixes: c3c863880479 ("add FIT data-position & data-offset property support")
Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 common/image-fit.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

--
2.25.1

Comments

Simon Goldschmidt March 11, 2020, 8:57 p.m. UTC | #1
On Wed, Mar 11, 2020 at 9:51 PM Heinrich Schuchardt <xypron.glpk at gmx.de> wrote:
>
> GCC-10 reports:
>
> In file included from tools/common/image-fit.c:1:
> include/image.h: In function ?fit_image_get_data_and_size?:
> ./tools/../common/image-fit.c:1015:9: warning: ?len? may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>  1015 |   *size = len;
>       |   ~~~~~~^~~~~
> ./tools/../common/image-fit.c:996:6: note: ?len? was declared here
>   996 |  int len;
>       |      ^~~
>
> Add the missing check of the return value of fit_image_get_data_size().
>
> Fixes: c3c863880479 ("add FIT data-position & data-offset property support")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>

Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>

> ---
>  common/image-fit.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/common/image-fit.c b/common/image-fit.c
> index f3bb00c98a..4435bc4f1d 100644
> --- a/common/image-fit.c
> +++ b/common/image-fit.c
> @@ -1011,8 +1011,10 @@ int fit_image_get_data_and_size(const void *fit, int noffset,
>         if (external_data) {
>                 debug("External Data\n");
>                 ret = fit_image_get_data_size(fit, noffset, &len);
> -               *data = fit + offset;
> -               *size = len;
> +               if (!ret) {
> +                       *data = fit + offset;
> +                       *size = len;
> +               }
>         } else {
>                 ret = fit_image_get_data(fit, noffset, data, size);
>         }
> --
> 2.25.1
>
Tom Rini March 13, 2020, 5:25 p.m. UTC | #2
On Wed, Mar 11, 2020 at 09:51:08PM +0100, Heinrich Schuchardt wrote:

> GCC-10 reports:
> 
> In file included from tools/common/image-fit.c:1:
> include/image.h: In function ?fit_image_get_data_and_size?:
> ./tools/../common/image-fit.c:1015:9: warning: ?len? may be used
> uninitialized in this function [-Wmaybe-uninitialized]
>  1015 |   *size = len;
>       |   ~~~~~~^~~~~
> ./tools/../common/image-fit.c:996:6: note: ?len? was declared here
>   996 |  int len;
>       |      ^~~
> 
> Add the missing check of the return value of fit_image_get_data_size().
> 
> Fixes: c3c863880479 ("add FIT data-position & data-offset property support")
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
> Reviewed-by: Simon Goldschmidt <simon.k.r.goldschmidt at gmail.com>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/image-fit.c b/common/image-fit.c
index f3bb00c98a..4435bc4f1d 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1011,8 +1011,10 @@  int fit_image_get_data_and_size(const void *fit, int noffset,
 	if (external_data) {
 		debug("External Data\n");
 		ret = fit_image_get_data_size(fit, noffset, &len);
-		*data = fit + offset;
-		*size = len;
+		if (!ret) {
+			*data = fit + offset;
+			*size = len;
+		}
 	} else {
 		ret = fit_image_get_data(fit, noffset, data, size);
 	}