diff mbox series

[1/1] tools: value checks in rkcommon_check_params()

Message ID 20200509193103.150434-1-xypron.glpk@gmx.de
State Accepted
Commit 69cd0c463d4bd8b9c3c20c96640c612333947d7e
Headers show
Series [1/1] tools: value checks in rkcommon_check_params() | expand

Commit Message

Heinrich Schuchardt May 9, 2020, 7:31 p.m. UTC
Building with -Wtype-limits yields

tools/rkcommon.c: In function ?rkcommon_check_params?:
tools/rkcommon.c:158:27: warning: comparison of
unsigned expression < 0 is always false [-Wtype-limits]
  158 |  if (spl_params.init_size < 0)
      |                           ^
tools/rkcommon.c:165:28: warning: comparison of
unsigned expression < 0 is always false [-Wtype-limits]
  165 |   if (spl_params.boot_size < 0)
      |

Fix the value checks.

Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>
---
 tools/rkcommon.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

--
2.26.2

Comments

Kever Yang May 15, 2020, 2:59 a.m. UTC | #1
Hi Heinrich,

On 2020/5/10 ??3:31, Heinrich Schuchardt wrote:
> Building with -Wtype-limits yields
>
> tools/rkcommon.c: In function ?rkcommon_check_params?:
> tools/rkcommon.c:158:27: warning: comparison of
> unsigned expression < 0 is always false [-Wtype-limits]
>    158 |  if (spl_params.init_size < 0)
>        |                           ^
> tools/rkcommon.c:165:28: warning: comparison of
> unsigned expression < 0 is always false [-Wtype-limits]
>    165 |   if (spl_params.boot_size < 0)
>        |
>
> Fix the value checks.
>
> Signed-off-by: Heinrich Schuchardt <xypron.glpk at gmx.de>

Good catch!


Reviewed-by: Kever Yang <kever.yang at rock-chips.com>

Thanks,
- Kever
> ---
>   tools/rkcommon.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/rkcommon.c b/tools/rkcommon.c
> index 8f281f5901..61c392e27d 100644
> --- a/tools/rkcommon.c
> +++ b/tools/rkcommon.c
> @@ -133,7 +133,7 @@ static int rkcommon_get_aligned_size(struct image_tool_params *params,
>
>   int rkcommon_check_params(struct image_tool_params *params)
>   {
> -	int i;
> +	int i, size;
>
>   	/*
>   	 * If this is a operation (list or extract), the don't require
> @@ -153,17 +153,17 @@ int rkcommon_check_params(struct image_tool_params *params)
>   		spl_params.boot_file += 1;
>   	}
>
> -	spl_params.init_size =
> -		rkcommon_get_aligned_size(params, spl_params.init_file);
> -	if (spl_params.init_size < 0)
> +	size = rkcommon_get_aligned_size(params, spl_params.init_file);
> +	if (size < 0)
>   		return EXIT_FAILURE;
> +	spl_params.init_size = size;
>
>   	/* Boot file is optional, and only for back-to-bootrom functionality. */
>   	if (spl_params.boot_file) {
> -		spl_params.boot_size =
> -			rkcommon_get_aligned_size(params, spl_params.boot_file);
> -		if (spl_params.boot_size < 0)
> +		size = rkcommon_get_aligned_size(params, spl_params.boot_file);
> +		if (size < 0)
>   			return EXIT_FAILURE;
> +		spl_params.boot_size = size;
>   	}
>
>   	if (spl_params.init_size > rkcommon_get_spl_size(params)) {
> --
> 2.26.2
>
>
>
diff mbox series

Patch

diff --git a/tools/rkcommon.c b/tools/rkcommon.c
index 8f281f5901..61c392e27d 100644
--- a/tools/rkcommon.c
+++ b/tools/rkcommon.c
@@ -133,7 +133,7 @@  static int rkcommon_get_aligned_size(struct image_tool_params *params,

 int rkcommon_check_params(struct image_tool_params *params)
 {
-	int i;
+	int i, size;

 	/*
 	 * If this is a operation (list or extract), the don't require
@@ -153,17 +153,17 @@  int rkcommon_check_params(struct image_tool_params *params)
 		spl_params.boot_file += 1;
 	}

-	spl_params.init_size =
-		rkcommon_get_aligned_size(params, spl_params.init_file);
-	if (spl_params.init_size < 0)
+	size = rkcommon_get_aligned_size(params, spl_params.init_file);
+	if (size < 0)
 		return EXIT_FAILURE;
+	spl_params.init_size = size;

 	/* Boot file is optional, and only for back-to-bootrom functionality. */
 	if (spl_params.boot_file) {
-		spl_params.boot_size =
-			rkcommon_get_aligned_size(params, spl_params.boot_file);
-		if (spl_params.boot_size < 0)
+		size = rkcommon_get_aligned_size(params, spl_params.boot_file);
+		if (size < 0)
 			return EXIT_FAILURE;
+		spl_params.boot_size = size;
 	}

 	if (spl_params.init_size > rkcommon_get_spl_size(params)) {