From: David Gibson <david-xT8FGy+AXnRB3Ne2BGzF6laj5H9X9Tb+@public.gmane.org>
To: Andre Przywara <andre.przywara-5wv7dgnIgG8@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 01/14] libfdt: fdt_offset_ptr(): Fix comparison warnings
Date: Wed, 23 Sep 2020 21:47:51 +1000 [thread overview]
Message-ID: <20200923114751.GG2298@yekko.fritz.box> (raw)
In-Reply-To: <20200921165303.9115-2-andre.przywara-5wv7dgnIgG8@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 1746 bytes --]
On Mon, Sep 21, 2020 at 05:52:50PM +0100, Andre Przywara wrote:
> With -Wsign-compare, compilers warn about mismatching signedness in
> comparisons in fdt_offset_ptr().
>
> This mostly stems from "offset" being passed in as a signed integer,
> even though the function would not really tolerate negative values.
>
> Short of changing the prototype, check that offset is not negative, and
> use an unsigned type internally.
>
> Signed-off-by: Andre Przywara <andre.przywara-5wv7dgnIgG8@public.gmane.org>
Applied, thanks.
> ---
> libfdt/fdt.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/libfdt/fdt.c b/libfdt/fdt.c
> index 37b7b93..04e1e06 100644
> --- a/libfdt/fdt.c
> +++ b/libfdt/fdt.c
> @@ -134,16 +134,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 (!can_assume(VALID_INPUT))
> - if ((absoffset < offset)
> + if ((absoffset < uoffset)
> || ((absoffset + len) < absoffset)
> || (absoffset + len) > fdt_totalsize(fdt))
> return NULL;
>
> if (can_assume(LATEST) || fdt_version(fdt) >= 0x11)
> - if (((offset + len) < offset)
> + if (((uoffset + len) < uoffset)
> || ((offset + len) > fdt_size_dt_struct(fdt)))
> return NULL;
>
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-09-23 11:47 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20200923114751.GG2298@yekko.fritz.box \
--to=david-xt8fgy+axnrb3ne2bgzf6laj5h9x9tb+@public.gmane.org \
--cc=andre.przywara-5wv7dgnIgG8@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).