devicetree-compiler.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "André Przywara" <andre.przywara-5wv7dgnIgG8@public.gmane.org>
To: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
Cc: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Devicetree Compiler
	<devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	Varun Wadekar <vwadekar-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH v2 0/6] libfdt: Fix signed/unsigned comparison warnings
Date: Fri, 2 Oct 2020 15:43:11 +0100	[thread overview]
Message-ID: <c4739c17-5160-3fe2-0ec5-b667811e0ac1@arm.com> (raw)
In-Reply-To: <20201002123209.GA442245-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>

On 02/10/2020 13:32, David Gibson wrote:
> On Fri, Oct 02, 2020 at 10:25:09AM +0100, André Przywara wrote:
>> On 02/10/2020 02:03, David Gibson wrote:
>>
>> Hi David,
>>
>>> On Thu, Oct 01, 2020 at 05:46:24PM +0100, Andre Przywara wrote:
>>>> Those are the six remaining patches of the initial post to fix the
>>>> C comparison warnings.
>>>> I reworked the fixes according to David's comments, and took quite a
>>>> different approach for some of them.
>>>> Changelog below.
>>>>
>>>> The series is against https://github.com/dgibson/dtc/commits/main
>>>> ------------------------------------
>>>>
>>>> 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.
>>>>
>>>> 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.
>>>>
>>>> Please have a look, happy to discuss the invididual cases.
>>>
>>> Thanks again for this work.  I've applied all the remaining patches,
>>> although I have some comments for some followups I think would be
>>> good.
>>
>> Thanks, that's much appreciated! Happy to discuss any further comments.
>>
>>> At this point can we turn on -Wsign-compare by default?  That sounds
>>> like a good idea to stop these problems creeping back in.
>>
>> Not quite yet: the patches were only covering "make libfdt". I see more
>> reports for dtc and the tests. I should probably address those as long
>> as this is still in my "L1 cache" ...
>> Unless you want to turn on -Wsign-compare just for libfdt.
> 
> If you think you can get us there for the whole project reasonably
> soon, then wait for that.  If it looks like you might need to shelve
> this for a while, then it would be good to get it enabled for just
> libfdt.

So I have "make tests" covered now, that looks mostly reasonable.
The rest is more nasty, I needed to paper over a few of them to make
some progress. But "make all check" comes out clean now.

I will try to make reasonable patches out this mess next week.

Cheers,
Andre

      parent reply	other threads:[~2020-10-02 14:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 16:46 [PATCH v2 0/6] libfdt: Fix signed/unsigned comparison warnings Andre Przywara
     [not found] ` <20201001164630.4980-1-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-01 16:46   ` [PATCH v2 1/6] libfdt: fdt_add_string_(): Fix comparison warning Andre Przywara
     [not found]     ` <20201001164630.4980-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:27       ` David Gibson
2020-10-01 16:46   ` [PATCH v2 2/6] libfdt: fdt_move(): Fix comparison warnings Andre Przywara
     [not found]     ` <20201001164630.4980-3-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:28       ` David Gibson
2020-10-01 16:46   ` [PATCH v2 3/6] libfdt: fdt_create_with_flags(): Fix comparison warning Andre Przywara
     [not found]     ` <20201001164630.4980-4-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:29       ` David Gibson
2020-10-01 16:46   ` [PATCH v2 4/6] libfdt: libfdt_wip: " Andre Przywara
     [not found]     ` <20201001164630.4980-5-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:30       ` David Gibson
2020-10-01 16:46   ` [PATCH v2 5/6] libfdt: fdt_get_string(): Fix sequential write comparison warnings Andre Przywara
     [not found]     ` <20201001164630.4980-6-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:33       ` David Gibson
2020-10-01 16:46   ` [PATCH v2 6/6] libfdt: fdt_strerror(): Fix comparison warning Andre Przywara
     [not found]     ` <20201001164630.4980-7-andre.przywara-5wv7dgnIgG8@public.gmane.org>
2020-10-02  0:34       ` David Gibson
2020-10-02  1:03   ` [PATCH v2 0/6] libfdt: Fix signed/unsigned comparison warnings David Gibson
     [not found]     ` <20201002010324.GH1844-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-02  9:25       ` André Przywara
     [not found]         ` <316e6e0f-e15e-89ee-3008-d2ed038ffd79-5wv7dgnIgG8@public.gmane.org>
2020-10-02 12:32           ` David Gibson
     [not found]             ` <20201002123209.GA442245-l+x2Y8Cxqc4e6aEkudXLsA@public.gmane.org>
2020-10-02 14:43               ` André Przywara [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c4739c17-5160-3fe2-0ec5-b667811e0ac1@arm.com \
    --to=andre.przywara-5wv7dgnigg8@public.gmane.org \
    --cc=david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org \
    --cc=devicetree-compiler-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=vwadekar-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).