diff mbox

[U-Boot] image: Fix loop condition to avoid warning

Message ID 1440063943-23180-1-git-send-email-thierry.reding@gmail.com
State Accepted
Delegated to: Tom Rini
Headers show

Commit Message

Thierry Reding Aug. 20, 2015, 9:45 a.m. UTC
From: Thierry Reding <treding@nvidia.com>

GCC 5.1 starts warning for comparisons such as !a > 0, assuming that the
negation was meant to apply to the whole expression rather than just the
left operand.

Indeed the comparison in the FIT loadable code is confusingly written,
though it does end up doing the right thing. Rewrite the condition to be
more explicit, that is, iterate over strings until they're exhausted.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 common/image.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Tom Rini Aug. 20, 2015, 4:48 p.m. UTC | #1
On Thu, Aug 20, 2015 at 11:45:43AM +0200, Thierry Reding wrote:

> From: Thierry Reding <treding@nvidia.com>
> 
> GCC 5.1 starts warning for comparisons such as !a > 0, assuming that the
> negation was meant to apply to the whole expression rather than just the
> left operand.
> 
> Indeed the comparison in the FIT loadable code is confusingly written,
> though it does end up doing the right thing. Rewrite the condition to be
> more explicit, that is, iterate over strings until they're exhausted.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Reviewed-by: Tom Rini <trini@konsulko.com>
Simon Glass Aug. 21, 2015, 5:53 p.m. UTC | #2
On 20 August 2015 at 03:45, Thierry Reding <thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> GCC 5.1 starts warning for comparisons such as !a > 0, assuming that the
> negation was meant to apply to the whole expression rather than just the
> left operand.
>
> Indeed the comparison in the FIT loadable code is confusingly written,
> though it does end up doing the right thing. Rewrite the condition to be
> more explicit, that is, iterate over strings until they're exhausted.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  common/image.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Aug. 28, 2015, 9:01 p.m. UTC | #3
On Thu, Aug 20, 2015 at 11:45:43AM +0200, Thierry Reding wrote:

> From: Thierry Reding <treding@nvidia.com>
> 
> GCC 5.1 starts warning for comparisons such as !a > 0, assuming that the
> negation was meant to apply to the whole expression rather than just the
> left operand.
> 
> Indeed the comparison in the FIT loadable code is confusingly written,
> though it does end up doing the right thing. Rewrite the condition to be
> more explicit, that is, iterate over strings until they're exhausted.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> Reviewed-by: Tom Rini <trini@konsulko.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

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

Patch

diff --git a/common/image.c b/common/image.c
index 998a4b6fcdfb..5e6f4af5d9cf 100644
--- a/common/image.c
+++ b/common/image.c
@@ -1228,10 +1228,10 @@  int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,
 		conf_noffset = fit_conf_get_node(buf, images->fit_uname_cfg);
 
 		for (loadables_index = 0;
-		     !fdt_get_string_index(buf, conf_noffset,
+		     fdt_get_string_index(buf, conf_noffset,
 				FIT_LOADABLE_PROP,
 				loadables_index,
-				(const char **)&uname) > 0;
+				(const char **)&uname) == 0;
 		     loadables_index++)
 		{
 			fit_img_result = fit_image_load(images,