Re: [PATCH] libfdt: Fix signedness comparison warnings

2020-11-11 Thread Tom Rini
On Fri, Oct 16, 2020 at 03:42:50PM +0100, Andre Przywara wrote:
> This is a combination of upstream libfdt commits to fix warnings about

> comparing signed and unsigned integers:
> ==
> scripts/dtc/libfdt/fdt.c: In function ‘fdt_offset_ptr’:
> scripts/dtc/libfdt/fdt.c:137:18: warning: comparison between signed and 
> unsigned integer expressions [-Wsign-compare]
>if ((absoffset < offset)
> ...
> ==
> 
> For a detailed description of the fixes, see the dtc repo:
> https://git.kernel.org/pub/scm/utils/dtc/dtc.git/log/?id=73e0f143b73d808
> 
> For this patch the commits between 73e0f143b73d8088 and ca19c3db2bf62000
> have been combined and adjusted for the slight differences in U-Boot's
> libfdt code base.
> 
> Signed-off-by: Andre Przywara 

So, I've applied this to u-boot/master now.  These warnings do show up
with gcc-10 and it's worthwhile to silence them.  I'm working with
upstream dtc now so that when we resync next we'll be able to avoid the
size and performance penalties of making all fdt loads unaligned safe.
A further resync will also require us to fixup a number of dts warnings
again.  These are the main reasons that I'm setting aside my suggestion
of a full resync for now.  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] libfdt: Fix signedness comparison warnings

2020-10-16 Thread Tom Rini
On Fri, Oct 16, 2020 at 10:57:19AM -0400, Tom Rini wrote:
> On Fri, Oct 16, 2020 at 03:42:50PM +0100, Andre Przywara wrote:
> 
> > This is a combination of upstream libfdt commits to fix warnings about
> > comparing signed and unsigned integers:
> > ==
> > scripts/dtc/libfdt/fdt.c: In function ‘fdt_offset_ptr’:
> > scripts/dtc/libfdt/fdt.c:137:18: warning: comparison between signed and 
> > unsigned integer expressions [-Wsign-compare]
> >if ((absoffset < offset)
> > ...
> > ==
> > 
> > For a detailed description of the fixes, see the dtc repo:
> > https://git.kernel.org/pub/scm/utils/dtc/dtc.git/log/?id=73e0f143b73d808
> > 
> > For this patch the commits between 73e0f143b73d8088 and ca19c3db2bf62000
> > have been combined and adjusted for the slight differences in U-Boot's
> > libfdt code base.
> > 
> > Signed-off-by: Andre Przywara 
> 
> So, the scripts that the Linux kernel uses to re-sync with dtc also work
> for U-Boot.  Has the kernel re-synced yet?  If so, can we just re-sync
> with that same commit again?  That's typically how we do this.  Thanks!

I see that it has.  So I'll give a re-sync a try and see what comes up.
Thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PATCH] libfdt: Fix signedness comparison warnings

2020-10-16 Thread Tom Rini
On Fri, Oct 16, 2020 at 03:42:50PM +0100, Andre Przywara wrote:

> This is a combination of upstream libfdt commits to fix warnings about
> comparing signed and unsigned integers:
> ==
> scripts/dtc/libfdt/fdt.c: In function ‘fdt_offset_ptr’:
> scripts/dtc/libfdt/fdt.c:137:18: warning: comparison between signed and 
> unsigned integer expressions [-Wsign-compare]
>if ((absoffset < offset)
> ...
> ==
> 
> For a detailed description of the fixes, see the dtc repo:
> https://git.kernel.org/pub/scm/utils/dtc/dtc.git/log/?id=73e0f143b73d808
> 
> For this patch the commits between 73e0f143b73d8088 and ca19c3db2bf62000
> have been combined and adjusted for the slight differences in U-Boot's
> libfdt code base.
> 
> Signed-off-by: Andre Przywara 

So, the scripts that the Linux kernel uses to re-sync with dtc also work
for U-Boot.  Has the kernel re-synced yet?  If so, can we just re-sync
with that same commit again?  That's typically how we do this.  Thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH] libfdt: Fix signedness comparison warnings

2020-10-16 Thread Andre Przywara
This is a combination of upstream libfdt commits to fix warnings about
comparing signed and unsigned integers:
==
scripts/dtc/libfdt/fdt.c: In function ‘fdt_offset_ptr’:
scripts/dtc/libfdt/fdt.c:137:18: warning: comparison between signed and 
unsigned integer expressions [-Wsign-compare]
   if ((absoffset < offset)
...
==

For a detailed description of the fixes, see the dtc repo:
https://git.kernel.org/pub/scm/utils/dtc/dtc.git/log/?id=73e0f143b73d808

For this patch the commits between 73e0f143b73d8088 and ca19c3db2bf62000
have been combined and adjusted for the slight differences in U-Boot's
libfdt code base.

Signed-off-by: Andre Przywara 
---
 scripts/dtc/libfdt/fdt.c  | 15 +++
 scripts/dtc/libfdt/fdt_overlay.c  |  3 ++-
 scripts/dtc/libfdt/fdt_ro.c   | 20 +++-
 scripts/dtc/libfdt/fdt_strerror.c |  4 ++--
 scripts/dtc/libfdt/fdt_sw.c   | 27 +++
 scripts/dtc/libfdt/fdt_wip.c  |  2 +-
 6 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/scripts/dtc/libfdt/fdt.c b/scripts/dtc/libfdt/fdt.c
index 8e4cce3b9be..28f4e1a5f15 100644
--- a/scripts/dtc/libfdt/fdt.c
+++ b/scripts/dtc/libfdt/fdt.c
@@ -131,16 +131,20 @@ int fdt_check_header(const void *fdt)
 
 const void *fdt_offset_ptr(const void *fdt, int offset, unsigned int len)
 {
-   unsigned absoffset = offset + fdt_off_dt_struct(fdt);
+   unsigned int uoffset = offset;
+   unsigned int absoffset = offset + fdt_off_dt_struct(fdt);
+
+   if (offset < 0)
+   return NULL;
 
if (fdt_chk_basic())
-   if ((absoffset < offset)
+   if ((absoffset < uoffset)
|| ((absoffset + len) < absoffset)
|| (absoffset + len) > fdt_totalsize(fdt))
return NULL;
 
if (!fdt_chk_version() || fdt_version(fdt) >= 0x11)
-   if (((offset + len) < offset)
+   if (((uoffset + len) < uoffset)
|| ((offset + len) > fdt_size_dt_struct(fdt)))
return NULL;
 
@@ -302,9 +306,12 @@ const char *fdt_find_string_(const char *strtab, int 
tabsize, const char *s)
 
 int fdt_move(const void *fdt, void *buf, int bufsize)
 {
+   if (fdt_chk_basic() && bufsize < 0)
+   return -FDT_ERR_NOSPACE;
+
FDT_RO_PROBE(fdt);
 
-   if (fdt_totalsize(fdt) > bufsize)
+   if (fdt_totalsize(fdt) > (unsigned int)bufsize)
return -FDT_ERR_NOSPACE;
 
memmove(buf, fdt, fdt_totalsize(fdt));
diff --git a/scripts/dtc/libfdt/fdt_overlay.c b/scripts/dtc/libfdt/fdt_overlay.c
index bd75e3dd786..7a65c35af6f 100644
--- a/scripts/dtc/libfdt/fdt_overlay.c
+++ b/scripts/dtc/libfdt/fdt_overlay.c
@@ -241,6 +241,7 @@ static int overlay_update_local_node_references(void *fdto,
 
if (fixup_len % sizeof(uint32_t))
return -FDT_ERR_BADOVERLAY;
+   fixup_len /= sizeof(uint32_t);
 
tree_val = fdt_getprop(fdto, tree_node, name, _len);
if (!tree_val) {
@@ -250,7 +251,7 @@ static int overlay_update_local_node_references(void *fdto,
return tree_len;
}
 
-   for (i = 0; i < (fixup_len / sizeof(uint32_t)); i++) {
+   for (i = 0; i < fixup_len; i++) {
fdt32_t adj_val;
uint32_t poffset;
 
diff --git a/scripts/dtc/libfdt/fdt_ro.c b/scripts/dtc/libfdt/fdt_ro.c
index d9d52e0d56e..d984bab036b 100644
--- a/scripts/dtc/libfdt/fdt_ro.c
+++ b/scripts/dtc/libfdt/fdt_ro.c
@@ -53,7 +53,7 @@ const char *fdt_get_string(const void *fdt, int stroffset, 
int *lenp)
 
err = -FDT_ERR_BADOFFSET;
absoffset = stroffset + fdt_off_dt_strings(fdt);
-   if (absoffset >= totalsize)
+   if (absoffset >= (unsigned)totalsize)
goto fail;
len = totalsize - absoffset;
 
@@ -61,17 +61,19 @@ const char *fdt_get_string(const void *fdt, int stroffset, 
int *lenp)
if (stroffset < 0)
goto fail;
if (!fdt_chk_version() || fdt_version(fdt) >= 17) {
-   if (stroffset >= fdt_size_dt_strings(fdt))
+   if ((unsigned)stroffset >= fdt_size_dt_strings(fdt))
goto fail;
if ((fdt_size_dt_strings(fdt) - stroffset) < len)
len = fdt_size_dt_strings(fdt) - stroffset;
}
} else if (fdt_magic(fdt) == FDT_SW_MAGIC) {
-   if ((stroffset >= 0)
-   || (stroffset < -fdt_size_dt_strings(fdt)))
+   unsigned int sw_stroffset = -stroffset;
+
+   if ((stroffset >= 0) ||
+   (sw_stroffset > fdt_size_dt_strings(fdt)))
goto fail;
-   if ((-stroffset) < len)
-   len = -stroffset;
+   if