All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/14] libfdt: Fix signed/unsigned comparison warnings
@ 2020-09-21 16:52 Andre Przywara
       [not found] ` <20200921165303.9115-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
  0 siblings, 1 reply; 37+ messages in thread
From: Andre Przywara @ 2020-09-21 16:52 UTC (permalink / raw)
  To: Simon Glass, David Gibson; +Cc: Devicetree Compiler, Varun Wadekar

When libfdt is compiled with -Wsign-compare or -Wextra, GCC emits quite
some warnings about the signedness of the operands not matching:
=================
libfdt/fdt.c:140:18: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare]
   if ((absoffset < offset)
.....
=================

This does not occur under normal conditions in the dtc repo, but might
show up when libfdt is embedded in another project. There have been reports
from U-Boot and Trusted-Firmware-A.

The underlying issue is mostly due to C's promotion behaviour (ANSI C
section 6.1.3.8) when dealing with operands of different signedness
(but same size): Signed values get implictly casted to unsigned, which
is not typically what we want if they could have been negative.

The Internet(TM) suggests that blindly applying casts is probably doing
more harm than it helps, so this series tries to fix the underlying
issues properly.
In libfdt, some types are somewhat suboptimal ("int bufsize" comes to mind);
some signed types are due to them being returned along wih error values in
other functions (node offsets).
So these fixes here have been based on the following assumptions:
- We cannot change the prototype of exported functions.
- It's better to change types (for local variables) than to cast.
- If we have established that a signed value is not negative, we can safely
  cast it to an unsigned type.

I split up the fixes in small chunks, to make them easier to review.
The first four patches change types, the next six ones use casts after
we made sure the values are not negative.

This is only covering libfdt for now (which is what those other projects
care about). There are more issues with dtc, but they can be addressed
later.

Not sure if some of these checks should be gated by can_assume() calls.

Please have a look, happy to discuss the invididual cases.

Cheers,
Andre

Andre Przywara (13):
  libfdt: fdt_offset_ptr(): Fix comparison warnings
  libfdt: fdt_mem_rsv(): Fix comparison warnings
  libfdt: fdt_grab_space_(): Fix comparison warning
  libfdt: fdt_add_string_(): Fix comparison warning
  libfdt: fdt_move(): Fix comparison warnings
  libfdt: fdt_splice_(): Fix comparison warning
  libfdt: fdt_create_with_flags(): Fix comparison warning
  libfdt: fdt_resize(): Fix comparison warning
  libfdt: libfdt_wip: Fix comparison warning
  libfdt: overlay: Fix comparison warning
  libfdt: fdt_get_string(): Fix sequential write comparison warnings
  libfdt: fdt_node_offset_by_phandle(): Fix comparison warning
  libfdt: fdt_strerror(): Fix comparison warning

Simon Glass (1):
  libfdt: fdt_get_string(): Fix comparison warnings

 libfdt/fdt.c          | 15 +++++++++++----
 libfdt/fdt_overlay.c  |  3 ++-
 libfdt/fdt_ro.c       | 14 +++++++-------
 libfdt/fdt_rw.c       |  2 +-
 libfdt/fdt_strerror.c |  2 +-
 libfdt/fdt_sw.c       | 14 +++++++++-----
 libfdt/fdt_wip.c      |  4 ++--
 7 files changed, 33 insertions(+), 21 deletions(-)

-- 
2.17.5


^ permalink raw reply	[flat|nested] 37+ messages in thread

end of thread, other threads:[~2020-10-02 12:25 UTC | newest]

Thread overview: 37+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21 16:52 [PATCH 00/14] libfdt: Fix signed/unsigned comparison warnings Andre Przywara
     [not found] ` <20200921165303.9115-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-21 16:52   ` [PATCH 01/14] libfdt: fdt_offset_ptr(): Fix " Andre Przywara
     [not found]     ` <20200921165303.9115-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-23 11:47       ` David Gibson
2020-09-21 16:52   ` [PATCH 02/14] libfdt: fdt_mem_rsv(): " Andre Przywara
     [not found]     ` <20200921165303.9115-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-23 11:50       ` David Gibson
2020-09-21 16:52   ` [PATCH 03/14] libfdt: fdt_grab_space_(): Fix comparison warning Andre Przywara
     [not found]     ` <20200921165303.9115-4-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-23 11:50       ` David Gibson
2020-09-21 16:52   ` [PATCH 04/14] libfdt: fdt_add_string_(): " Andre Przywara
     [not found]     ` <20200921165303.9115-5-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  1:01       ` David Gibson
     [not found]         ` <20200924010145.GJ2298-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-01 15:33           ` André Przywara
     [not found]             ` <74c57a12-db86-ec9f-5c91-f0419c24de4b-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:01               ` David Gibson
     [not found]                 ` <20201002000140.GA1844-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-02  9:31                   ` André Przywara
     [not found]                     ` <3d6281e8-bd95-b2db-2b80-446f9a98ea66-5wv7dgnIgG8@public.gmane.org>
2020-10-02 12:25                       ` David Gibson
2020-09-21 16:52   ` [PATCH 05/14] libfdt: fdt_move(): Fix comparison warnings Andre Przywara
     [not found]     ` <20200921165303.9115-6-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  1:03       ` David Gibson
2020-09-21 16:52   ` [PATCH 06/14] libfdt: fdt_get_string(): " Andre Przywara
     [not found]     ` <20200921165303.9115-7-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  1:06       ` David Gibson
2020-09-21 16:52   ` [PATCH 07/14] libfdt: fdt_splice_(): Fix comparison warning Andre Przywara
     [not found]     ` <20200921165303.9115-8-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  1:07       ` David Gibson
2020-09-21 16:52   ` [PATCH 08/14] libfdt: fdt_create_with_flags(): " Andre Przywara
     [not found]     ` <20200921165303.9115-9-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  4:34       ` David Gibson
2020-09-21 16:52   ` [PATCH 09/14] libfdt: fdt_resize(): " Andre Przywara
     [not found]     ` <20200921165303.9115-10-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  4:43       ` David Gibson
2020-09-21 16:52   ` [PATCH 10/14] libfdt: libfdt_wip: " Andre Przywara
     [not found]     ` <20200921165303.9115-11-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-24  4:49       ` David Gibson
2020-09-21 16:53   ` [PATCH 11/14] libfdt: overlay: " Andre Przywara
     [not found]     ` <20200921165303.9115-12-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-25  4:05       ` David Gibson
2020-09-21 16:53   ` [PATCH 12/14] libfdt: fdt_get_string(): Fix sequential write comparison warnings Andre Przywara
     [not found]     ` <20200921165303.9115-13-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-25  4:09       ` David Gibson
     [not found]         ` <20200925040903.GX2298-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-01 15:33           ` André Przywara
2020-09-21 16:53   ` [PATCH 13/14] libfdt: fdt_node_offset_by_phandle(): Fix comparison warning Andre Przywara
     [not found]     ` <20200921165303.9115-14-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-25  4:09       ` David Gibson
2020-09-21 16:53   ` [PATCH 14/14] libfdt: fdt_strerror(): " Andre Przywara
     [not found]     ` <20200921165303.9115-15-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-09-25  4:12       ` David Gibson
     [not found]         ` <20200925041208.GZ2298-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-01 15:34           ` André Przywara
2020-09-25  4:12   ` [PATCH 00/14] libfdt: Fix signed/unsigned comparison warnings David Gibson
     [not found]     ` <20200925041243.GA2298-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-09-25  8:44       ` André Przywara

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.