diff mbox

[U-Boot] boot_fit: Fix warning: overflow in implicit constant conversion in fdt_offset()

Message ID 20170802231025.3563-1-iwamatsu@nigauri.org
State Changes Requested
Delegated to: Tom Rini
Headers show

Commit Message

Nobuhiro Iwamatsu Aug. 2, 2017, 11:10 p.m. UTC
FDT_ERROR is defined as unsigned long. However, since the return value of
fdt_offset() is int, a warning will occur when compiling.
This fixes this problem by cast to int when setting FDT_ERROR as return value.

Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
CC: Franklin S Cooper Jr <fcooper@ti.com>
---
 common/boot_fit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Franklin S Cooper Jr Aug. 2, 2017, 11:56 p.m. UTC | #1
Hi
On 08/02/2017 06:10 PM, Nobuhiro Iwamatsu wrote:
> FDT_ERROR is defined as unsigned long. However, since the return value of
> fdt_offset() is int, a warning will occur when compiling.
> This fixes this problem by cast to int when setting FDT_ERROR as return value.
> 
> Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
> CC: Franklin S Cooper Jr <fcooper@ti.com>
> ---
>  common/boot_fit.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/common/boot_fit.c b/common/boot_fit.c
> index 51440a6e6f..ca130f2308 100644
> --- a/common/boot_fit.c
> +++ b/common/boot_fit.c
> @@ -25,7 +25,7 @@ int fdt_offset(void *fit)
>  	images = fdt_path_offset(fit, FIT_IMAGES_PATH);
>  	if (images < 0) {
>  		debug("%s: Cannot find /images node: %d\n", __func__, images);
> -		return FDT_ERROR;
> +		return (int)FDT_ERROR;

Returning -EINVAL would be better. Doing essentially (int)((ulong)(-1))
doesn't look right and to function properly that function needs to
return any kind of negative value.  Thanks for catching this problem.
>  	}
>  
>  	fdt_name = fdt_getprop(fit, node, FIT_FDT_PROP, &fdt_len);
>
Nobuhiro Iwamatsu Aug. 4, 2017, 8:29 p.m. UTC | #2
Hi,

2017-08-03 8:56 GMT+09:00 Franklin S Cooper Jr <fcooper@ti.com>:
>
> Hi
> On 08/02/2017 06:10 PM, Nobuhiro Iwamatsu wrote:
>> FDT_ERROR is defined as unsigned long. However, since the return value of
>> fdt_offset() is int, a warning will occur when compiling.
>> This fixes this problem by cast to int when setting FDT_ERROR as return value.
>>
>> Signed-off-by: Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
>> CC: Franklin S Cooper Jr <fcooper@ti.com>
>> ---
>>  common/boot_fit.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/common/boot_fit.c b/common/boot_fit.c
>> index 51440a6e6f..ca130f2308 100644
>> --- a/common/boot_fit.c
>> +++ b/common/boot_fit.c
>> @@ -25,7 +25,7 @@ int fdt_offset(void *fit)
>>       images = fdt_path_offset(fit, FIT_IMAGES_PATH);
>>       if (images < 0) {
>>               debug("%s: Cannot find /images node: %d\n", __func__, images);
>> -             return FDT_ERROR;
>> +             return (int)FDT_ERROR;
>
> Returning -EINVAL would be better. Doing essentially (int)((ulong)(-1))
> doesn't look right and to function properly that function needs to
> return any kind of negative value.  Thanks for catching this problem.

I see. I will resend new patch.
Thanks!

Nobuhiro
diff mbox

Patch

diff --git a/common/boot_fit.c b/common/boot_fit.c
index 51440a6e6f..ca130f2308 100644
--- a/common/boot_fit.c
+++ b/common/boot_fit.c
@@ -25,7 +25,7 @@  int fdt_offset(void *fit)
 	images = fdt_path_offset(fit, FIT_IMAGES_PATH);
 	if (images < 0) {
 		debug("%s: Cannot find /images node: %d\n", __func__, images);
-		return FDT_ERROR;
+		return (int)FDT_ERROR;
 	}
 
 	fdt_name = fdt_getprop(fit, node, FIT_FDT_PROP, &fdt_len);